:root {
  --canvas: #f8f7f4;
  --surface: #fff;
  --surface-soft: #faf9f7;
  --surface-warm: #eeece7;
  --ink: #292824;
  --ink-soft: #45433d;
  --muted: #757169;
  --muted-light: #959088;
  --border: #e7e4dd;
  --border-strong: #c9c4bb;
  --purple: #645783;
  --purple-deep: #504269;
  --purple-soft: #efecf4;
  --lavender: #e9e3f1;
  --peach: #f4e5da;
  --coral: #b24b45;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}
* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; color: var(--ink); font-family: var(--font-sans); font-size: 15px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
body.modal-open { overflow: hidden; }
button, input, textarea, select { color: inherit; font: inherit; -webkit-tap-highlight-color: transparent; }
button { border: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--purple); outline-offset: 3px; }
button:disabled { cursor: not-allowed; opacity: .45; }
[hidden] { display: none !important; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.6; flex: 0 0 auto; }
.icon-small { width: 16px; height: 16px; }
.app-shell { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; height: 68px; padding: 0 28px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--border); }
.brand-lockup { display: flex; align-items: center; gap: 10px; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; color: white; background: var(--ink); border-radius: 9px; font-size: 17px; font-weight: 600; }
.brand-title { font-size: 16px; font-weight: 600; }
.topbar-actions { position: relative; display: flex; align-items: center; gap: 8px; }
.identity-button { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 8px; border-radius: 8px; background: transparent; font-size: 14px; }
.identity-button:hover, .identity-button[aria-expanded="true"] { background: var(--surface-warm); }
.avatar { display: inline-grid; place-items: center; width: 28px; height: 28px; flex: 0 0 auto; border-radius: 50%; font-size: 12px; font-weight: 600; line-height: 1; }
.avatar-brother { color: #64517e; background: var(--lavender); }
.avatar-baby { color: #91684b; background: var(--peach); }
.identity-menu { position: absolute; top: calc(100% + 8px); right: 0; width: 156px; padding: 6px; background: white; border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 32px #29282414; }
.identity-menu button { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 8px; background: transparent; border-radius: 8px; text-align: left; font-size: 14px; }
.identity-menu button:hover { background: var(--surface-warm); }
.identity-check { color: var(--purple); visibility: hidden; }
.selected .identity-check { visibility: visible; }
.icon-button, .section-action, .row-action { display: inline-grid; place-items: center; width: 36px; height: 36px; flex: 0 0 auto; padding: 0; color: var(--muted); background: transparent; border-radius: 8px; transition: color 140ms ease, background 140ms ease; }
.icon-button:hover, .section-action:hover, .row-action:hover { color: var(--purple-deep); background: var(--purple-soft); }
.mobile-menu-button { display: none; }
.workspace { display: grid; grid-template-columns: 222px minmax(0,1fr); }
.sidebar { position: sticky; top: 68px; height: calc(100dvh - 68px); padding: 30px 14px; background: #f1f0ec; border-right: 1px solid var(--border); }
.nav-item { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 44px; margin-bottom: 5px; padding: 0 12px; color: var(--muted); background: transparent; border-radius: 8px; font-size: 14px; }
.nav-item:hover { color: var(--ink); background: #ffffff80; }
.nav-item.active { color: var(--ink); background: white; font-weight: 600; }
.nav-item-left { display: inline-flex; align-items: center; gap: 10px; }
.nav-dot { width: 7px; height: 7px; border-radius: 50%; }
.dot-all { background: #7e7987; }
.dot-brother { background: #a496ba; }
.dot-baby { background: #c8a086; }
.dot-shared { background: #8fa896; }
.nav-count { color: var(--muted-light); font-size: 12px; font-variant-numeric: tabular-nums; }
.main-content { min-width: 0; }
.main-inner { width: min(1110px,100%); margin: 0 auto; padding: 40px 42px 64px; }
.page-topline { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
h1 { margin: 0; font-size: 30px; font-weight: 600; letter-spacing: -.035em; line-height: 1.3; }
.page-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.search-box { display: flex; align-items: center; gap: 9px; width: 204px; min-width: 0; height: 42px; padding: 0 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.search-box:focus-within { border-color: var(--purple); }
.search-box input { width: 100%; min-width: 0; padding: 0; border: 0; background: transparent; font-size: 14px; }
.search-box input:focus-visible { outline: none; }
input::placeholder, textarea::placeholder { color: var(--muted-light); }
.primary-button, .secondary-button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 0 18px; border-radius: 8px; font-size: 14px; font-weight: 500; }
.primary-button { color: white; background: var(--purple); }
.primary-button:hover { background: var(--purple-deep); }
.secondary-button { background: white; border: 1px solid var(--border-strong); }
.secondary-button:hover { background: var(--surface-warm); }
.add-button { width: 42px; height: 42px; padding: 0; flex: 0 0 auto; }
.content-area { margin-top: 34px; }
.content-section + .content-section { margin-top: 28px; }
.content-section-header, .person-card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.content-section-header h2, .person-title { display: flex; align-items: center; gap: 9px; margin: 0; font-size: 17px; font-weight: 600; line-height: 1.5; }
.section-count { color: var(--muted-light); font-size: 12px; font-weight: 400; }
.rule-card, .person-card, .feature-card { min-width: 0; padding: 6px 22px; background: white; border: 1px solid var(--border); border-radius: 12px; }
.feature-card, .tint-mint { background: #f0f3ef; border-color: #e0e6de; }
.tint-lavender { background: #f7f5fa; }
.tint-peach { background: #fcf7f3; }
.personal-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); align-items: start; gap: 20px; }
.person-card { padding-top: 18px; }
.person-card-header { margin-bottom: 8px; }
.person-title { font-size: 16px; }
.rule-list { padding: 0; margin: 0; list-style: none; }
.rule-row { display: grid; grid-template-columns: 24px minmax(0,1fr) auto; align-items: start; gap: 10px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.feature-card .rule-row { border-color: #dde4db; }
.rule-row:last-child { border-bottom: 0; }
.rule-index { padding-top: 4px; color: var(--muted-light); font-size: 12px; line-height: 26px; font-variant-numeric: tabular-nums; }
.rule-content { min-width: 0; padding-top: 4px; }
.rule-text { margin: 0; color: var(--ink-soft); font-size: 15px; line-height: 1.85; white-space: pre-wrap; overflow-wrap: anywhere; }
.rule-actions { display: flex; align-items: center; gap: 2px; }
.row-action .icon { width: 16px; height: 16px; }
.row-action { color: #858178; }
.delete-action:hover, .undo-action:hover { color: var(--coral); background: #f9eeea; }
.author-avatar { width: 20px; height: 20px; font-size: 9px; }
.is-editing .rule-content { grid-column: 2 / -1; }
.rule-edit { display: block; width: 100%; min-height: 84px; padding: 10px 12px; border: 1px solid var(--purple); border-radius: 8px; background: white; font-size: 15px; line-height: 1.8; resize: vertical; }
.inline-edit-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.inline-edit-actions button { min-height: 36px; padding: 0 14px; border-radius: 7px; font-size: 13px; }
.inline-cancel { background: var(--surface-warm); }
.inline-save { background: var(--purple); color: white; }
.inline-save:hover { background: var(--purple-deep); }
.empty-state { display: grid; place-items: center; min-height: 150px; padding: 24px; text-align: center; color: var(--muted); }
.empty-state p { margin: 0 0 10px; font-size: 14px; }
.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: #29282455; }
.modal { width: min(500px,100%); max-height: calc(100dvh - 40px); overflow-y: auto; padding: 24px; border-radius: 14px; background: white; box-shadow: 0 16px 64px #29282426; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.modal-header h2 { margin: 0; font-size: 23px; font-weight: 600; }
.form-label { display: block; margin-bottom: 8px; font-size: 14px; }
#ruleCategory, #ruleText { display: block; width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface-soft); font-size: 15px; }
#ruleCategory { height: 44px; }
#ruleText { min-height: 116px; resize: vertical; line-height: 1.8; }
.form-field-gap { height: 18px; }
.form-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 22px; }
.form-meta, .form-identity { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; }
.form-meta { color: var(--muted); }
.form-identity { color: var(--ink); }
.form-actions { display: flex; gap: 8px; }
.toast { position: fixed; bottom: 24px; left: 50%; z-index: 80; max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: 8px; color: white; background: var(--ink); font-size: 14px; opacity: 0; pointer-events: none; transform: translate(-50%,8px); transition: opacity 160ms, transform 160ms; }
.toast.visible { opacity: 1; transform: translate(-50%,0); }
@media (max-width: 1100px) {
  .main-inner { padding-right: 28px; padding-left: 28px; }
  .personal-grid { grid-template-columns: 1fr; }
}
@media (max-width: 1020px) {
  .workspace { display: block; }
  .sidebar { position: fixed; inset: 68px auto 0 0; z-index: 15; width: 230px; transform: translateX(-100%); visibility: hidden; transition: transform 160ms ease; }
  .sidebar.open { transform: translateX(0); visibility: visible; box-shadow: 12px 0 32px #29282415; }
  .mobile-menu-button { display: inline-grid; }
}
@media (max-width: 640px) {
  .topbar { height: 64px; padding: 0 16px; }
  .brand-title { font-size: 15px; }
  .sidebar { top: 64px; height: calc(100dvh - 64px); }
  .main-inner { padding: 28px 16px 44px; }
  .page-topline { align-items: stretch; flex-direction: column; gap: 20px; }
  h1 { font-size: 27px; }
  .page-actions { width: 100%; }
  .search-box { flex: 1; width: auto; height: 44px; }
  .add-button { width: 44px; height: 44px; }
  .icon-button, .section-action, .row-action { width: 44px; height: 44px; }
  .content-area { margin-top: 24px; }
  .content-section + .content-section { margin-top: 24px; }
  .content-section-header { margin-bottom: 8px; }
  .rule-card, .person-card, .feature-card { padding-right: 12px; padding-left: 16px; }
  .person-card { padding-top: 14px; }
  .person-card-header { margin-bottom: 4px; }
  .rule-row { grid-template-columns: 20px minmax(0,1fr) 44px; gap: 6px; padding: 12px 0; }
  .rule-content { padding-top: 8px; }
  .rule-index { padding-top: 8px; }
  .rule-actions { flex-direction: column; gap: 0; }
  .author-avatar { margin: 5px 0; order: 1; }
  .inline-edit-actions button { min-height: 44px; }
  .form-footer { align-items: stretch; flex-direction: column; }
  .form-actions { margin-top: 6px; }
  .form-actions button { flex: 1; min-height: 44px; }
}
@media (max-width: 380px) {
  .identity-button > #identityLabel { display: none; }
  .topbar-actions { gap: 0; }
  .person-title { gap: 6px; font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
