:root {
  --paper: #f4eddf;
  --paper-deep: #e8dfd1;
  --paper-light: #fbf6ec;
  --aubergine: #3f2838;
  --aubergine-soft: #5d4254;
  --brick: #a24f43;
  --brick-dark: #7d3935;
  --lavender: #8d8194;
  --lavender-wash: #d9d1db;
  --sage: #89947c;
  --sage-wash: #d5dccd;
  --ink: var(--aubergine);
  --muted: #6d606a;
  --line: rgba(63, 40, 56, .18);
  --line-strong: rgba(63, 40, 56, .3);
  --shadow: 0 14px 34px rgba(63, 40, 56, .12);
  --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
.tap-spark { width: 9px; height: 9px; position: fixed; z-index: 120; pointer-events: none; background: var(--brick); clip-path: polygon(50% 0, 60% 37%, 100% 50%, 60% 63%, 50% 100%, 40% 63%, 0 50%, 40% 37%); filter: drop-shadow(0 1px 2px rgba(63,40,56,.24)); animation: tap-spark .34s ease-out forwards; }
html {
  min-height: 100%;
  min-height: 100dvh;
  background-color: var(--paper);
  color-scheme: light;
  overscroll-behavior: none;
}
body { height: 100%; min-height: 100dvh; }
body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper) url("/assets/workroom-paper-v2.jpg") center / min(100vw, 1254px) auto repeat-y fixed;
  font-family: ui-serif, "Songti SC", "STSong", "Noto Serif CJK SC", Georgia, serif;
}
body::before { content: ""; position: fixed; inset: 0; z-index: -1; background: rgba(244, 237, 223, .72); pointer-events: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:active { transform: translateY(1px) scale(.985); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid rgba(162, 79, 67, .27); outline-offset: 2px; }
.hidden { display: none !important; }
.grain { position: fixed; inset: 0; z-index: 99; opacity: .13; pointer-events: none; mix-blend-mode: multiply; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.72' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E"); }

.eyebrow { margin: 0 0 7px; color: var(--brick-dark); font: 700 10px/1.2 ui-monospace, SFMono-Regular, monospace; letter-spacing: .16em; }
.login-screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 22px; background: rgba(244, 237, 223, .48); }
.login-card { width: min(420px, 100%); padding: 46px 42px 42px; position: relative; border: 1px solid var(--line-strong); border-radius: var(--radius); background: rgba(251, 246, 236, .94); box-shadow: var(--shadow); transform: rotate(-.35deg); }
.login-card::before { content: ""; position: absolute; width: 72px; height: 27px; top: -13px; left: calc(50% - 36px); opacity: .76; background: #c8becb; transform: rotate(2deg); box-shadow: inset 0 0 12px rgba(251, 246, 236, .55); }
.seal { width: 61px; height: 61px; display: grid; place-items: center; margin-bottom: 24px; border: 1px solid rgba(251, 246, 236, .58); border-radius: 47% 53% 43% 57%; color: #f9eee0; background: var(--aubergine); box-shadow: 5px 6px 0 rgba(162, 79, 67, .28); font-size: 28px; }
.login-card h1 { margin: 0; font-size: 32px; letter-spacing: .04em; }
.login-copy { color: var(--muted); line-height: 1.7; }
.login-card label, .dialog-card label { display: grid; gap: 8px; margin: 22px 0 8px; color: var(--aubergine-soft); font-size: 13px; }
input, textarea, select { width: 100%; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius); outline: 0; color: var(--aubergine); background: rgba(251, 246, 236, .82); }
input::placeholder, textarea::placeholder { color: #776b74; opacity: 1; }
input:focus, textarea:focus, select:focus { border-color: var(--brick); background: var(--paper-light); }
.primary { width: 100%; margin-top: 18px; padding: 13px 18px; border: 0; border-radius: var(--radius); color: #fff4e8; background: var(--aubergine); box-shadow: 4px 5px 0 rgba(162, 79, 67, .3); transition: transform .16s ease, background .16s ease; }
.primary:hover { background: var(--brick-dark); }
.primary.compact { width: auto; margin: 0; padding: 10px 18px; }
.form-error { min-height: 20px; color: #8c302f; font-size: 12px; }
.login-separator { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; margin: 4px 0 13px; color: var(--muted); font-size: 11px; }
.login-separator::before, .login-separator::after { content: ""; height: 1px; background: var(--line); }
.pair-button { width: 100%; min-height: 46px; padding: 11px 15px; border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--aubergine); background: rgba(217,209,219,.35); box-shadow: 3px 3px 0 rgba(141,129,148,.16); }
.pair-button:disabled { opacity: .58; cursor: wait; }
.pair-status { min-height: 34px; margin: 9px 2px 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.shell { height: 100%; display: grid; grid-template-columns: 264px minmax(0, 1fr); background: rgba(244, 237, 223, .58); }
.rail { display: flex; flex-direction: column; padding: 24px 18px 19px; z-index: 2; border-right: 1px solid var(--line); background: rgba(232, 223, 209, .9); box-shadow: 8px 0 28px rgba(63, 40, 56, .07); }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px 23px; border-bottom: 1px solid var(--line); }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 47% 53% 46% 54%; color: #fff4e8; background: var(--aubergine); box-shadow: 3px 3px 0 rgba(162, 79, 67, .26); }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 17px; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.nav { display: grid; gap: 6px; margin: 18px 0 26px; }
.nav-item { min-height: 44px; padding: 11px 13px; border: 1px solid transparent; border-radius: var(--radius); color: var(--muted); background: transparent; text-align: left; transition: transform .16s ease, color .16s ease, background .16s ease; }
.nav-item span { display: inline-block; width: 25px; color: var(--brick); }
.nav-item.active { color: var(--aubergine); border-color: rgba(162, 79, 67, .16); background: rgba(251, 246, 236, .7); box-shadow: 3px 3px 0 rgba(141, 129, 148, .18); }
.section-label { margin: 0 10px 11px; color: var(--muted); font: 700 10px/1.2 ui-monospace, monospace; letter-spacing: .12em; }
.crew-card { display: grid; grid-template-columns: 35px 1fr auto; gap: 10px; align-items: center; padding: 8px 9px; margin-bottom: 3px; }
.avatar { width: 35px; height: 35px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 46% 54% 48% 52%; color: #fff4e8; font: 700 13px/1 ui-monospace, monospace; box-shadow: 2px 2px 0 rgba(63, 40, 56, .13); }
.avatar.owner { background: var(--brick); }
.avatar.xiaojin { background: var(--aubergine-soft); }
.avatar.codex { background: var(--lavender); }
.avatar.claude { background: var(--sage); color: #182316; }
.crew-name { font-size: 13px; }
.crew-note { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.status-dot { width: 8px; height: 8px; border: 1px solid rgba(63,40,56,.22); border-radius: 50%; background: #9c929a; }
.status-dot.online { background: var(--sage); box-shadow: 0 0 0 3px rgba(137,148,124,.18); }
.safe-note { display: flex; gap: 10px; align-items: flex-start; padding: 13px; margin-top: auto; border: 1px solid rgba(137, 148, 124, .44); border-radius: var(--radius); background: rgba(213, 220, 205, .55); transform: rotate(.4deg); }
.safe-note strong { font-size: 12px; }
.safe-note p { margin: 3px 0 0; color: var(--muted); font-size: 10px; line-height: 1.4; }
.safe-dot { width: 9px; height: 9px; margin-top: 3px; border-radius: 50%; background: var(--sage); }
.text-button { min-height: 42px; margin-top: 7px; border: 0; background: none; color: var(--muted); font-size: 12px; }

.main { min-width: 0; height: 100%; }
.view { display: none; height: 100%; position: relative; }
.active-view { display: flex; flex-direction: column; }
.topbar { min-height: 78px; padding: 16px 30px 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(251, 246, 236, .77); backdrop-filter: blur(10px); }
.topbar h2 { margin: 0; font-weight: 600; font-size: 23px; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.connection { display: flex; gap: 7px; align-items: center; color: var(--muted); font-size: 11px; }
.connection i { width: 8px; height: 8px; border-radius: 50%; background: var(--lavender); }
.connection.online i { background: var(--sage); }
.soft-button { min-height: 40px; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--aubergine); background: rgba(251, 246, 236, .78); font-size: 11px; }
.soft-button[aria-pressed="true"] { color: #fff4e8; border-color: var(--aubergine); background: var(--aubergine); }
.account-button { display: grid; min-width: 154px; grid-template-columns: auto auto 1fr; gap: 5px; align-items: center; text-align: left; }
.account-button span { color: var(--brick); }
.account-button b { font-size: 11px; }
.account-button small { overflow: hidden; color: var(--muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.messages { flex: 1; overflow: auto; padding: 26px max(28px, calc((100vw - 1120px) / 2)); scroll-behavior: smooth; }
.empty-chat { max-width: 580px; margin: 9vh auto; padding: 0 12px; color: var(--muted); text-align: left; }
.empty-chat .seal { margin: 0 0 24px 7%; }
.empty-chat h3 { max-width: 470px; margin: 0 0 12px; color: var(--aubergine); font-size: clamp(26px, 4vw, 39px); line-height: 1.15; }
.empty-chat p { max-width: 520px; margin-left: 10%; line-height: 1.8; }
.message { display: flex; gap: 12px; max-width: 780px; margin: 0 auto 22px; }
.message.owner { flex-direction: row-reverse; }
.bubble-wrap { min-width: 0; max-width: min(82%, 680px); }
.message.owner .bubble-wrap { display: flex; flex-direction: column; align-items: flex-end; }
.meta { display: flex; gap: 8px; align-items: center; margin: 0 3px 5px; color: var(--muted); font-size: 10px; }
.bubble { padding: 13px 15px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.65; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(251, 246, 236, .88); box-shadow: 3px 4px 0 rgba(141, 129, 148, .16); }
.owner .bubble { border-color: rgba(162,79,67,.22); background: #e7c8b8; box-shadow: 3px 4px 0 rgba(162,79,67,.17); }
.message.error .bubble { border-color: rgba(140,48,47,.56); }
.task-tag { display: inline-block; margin-top: 7px; padding: 4px 8px; border-radius: 8px; color: var(--muted); background: rgba(217,209,219,.55); font: 10px/1.4 ui-monospace, monospace; }
.composer-wrap { padding: 0 max(28px, calc((100vw - 1120px) / 2)) max(18px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(244,237,223,.94) 22%); }
.mention-row { display: flex; gap: 7px; padding: 12px 4px 8px; overflow-x: auto; }
.mention-row button { min-height: 36px; padding: 6px 10px; white-space: nowrap; border: 1px solid rgba(141,129,148,.36); border-radius: 10px; color: var(--aubergine-soft); background: rgba(217,209,219,.42); font-size: 11px; }
.mention-row button:nth-child(2), .mention-row button:nth-child(4) { background: rgba(213,220,205,.48); border-color: rgba(137,148,124,.45); }
.composer { padding: 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: rgba(251, 246, 236, .95); box-shadow: var(--shadow); }
.composer textarea { min-height: 52px; max-height: 180px; resize: none; padding: 4px; border: 0; border-radius: 0; background: transparent; box-shadow: none; line-height: 1.5; }
.composer-actions { display: flex; align-items: center; justify-content: space-between; padding-top: 9px; border-top: 1px solid var(--line); }
.emergency { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 11px; }
.emergency input { width: auto; accent-color: var(--brick); }
.send-button { min-width: 72px; min-height: 40px; padding: 8px 19px; border: 0; border-radius: var(--radius); color: #fff4e8; background: var(--brick-dark); box-shadow: 3px 3px 0 rgba(63,40,56,.18); }
.send-button:disabled { opacity: .55; cursor: wait; }
.jump { position: absolute; right: 30px; bottom: 170px; padding: 8px 13px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--paper-light); box-shadow: var(--shadow); }

.order-board { padding: 28px; overflow: auto; display: grid; grid-template-columns: repeat(3, minmax(230px, 1fr)); gap: 18px; align-items: start; }
.order-column { min-height: 160px; padding: 15px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(251,246,236,.52); }
.order-column:nth-child(2) { background: rgba(217,209,219,.34); }
.order-column:nth-child(3) { background: rgba(213,220,205,.38); }
.order-column h3 { margin: 0 0 14px; color: var(--aubergine-soft); font-size: 12px; letter-spacing: .07em; }
.order-card { padding: 14px; margin-bottom: 10px; border: 1px solid var(--line); border-left: 4px solid var(--sage); border-radius: var(--radius); background: var(--paper-light); box-shadow: 3px 4px 0 rgba(63,40,56,.09); }
.order-card.critical { border-left-color: var(--brick-dark); }
.order-card.high { border-left-color: var(--lavender); }
.order-card strong { display: block; }
.order-card p { margin: 8px 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.order-meta { color: var(--muted); font: 10px/1.5 ui-monospace, monospace; }
.approval-empty { max-width: 650px; margin: auto; padding: 52px; text-align: left; border: 1px solid var(--line-strong); border-radius: var(--radius); background: rgba(251,246,236,.82); box-shadow: 7px 8px 0 rgba(141,129,148,.2); transform: rotate(-.25deg); }
.big-lock { display: block; margin-left: 8%; color: var(--brick); font-size: 48px; }
.approval-empty h3 { margin: 20px 0 12px; font-size: 26px; }
.approval-empty p { color: var(--muted); line-height: 1.8; }
.gate-list { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 25px; }
.gate-list span { padding: 10px; border-radius: 9px; color: var(--aubergine-soft); background: rgba(217,209,219,.38); font-size: 11px; }
.gate-list span:nth-child(2n) { background: rgba(213,220,205,.48); }

dialog { max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); overflow-x: hidden; padding: 0; border: 0; border-radius: var(--radius); background: transparent; }
dialog::backdrop { background: rgba(63,40,56,.45); backdrop-filter: blur(3px); }
.dialog-card { width: min(540px, calc(100vw - 32px)); max-width: 100%; padding: 30px; position: relative; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--paper-light); box-shadow: var(--shadow); }
.dialog-card::before { content: ""; position: absolute; width: 70px; height: 24px; top: -11px; left: calc(50% - 35px); opacity: .72; background: var(--sage-wash); transform: rotate(-2deg); }
.dialog-card h2 { margin: 0; }
.dialog-close { width: 44px; height: 44px; position: absolute; top: 8px; right: 9px; border: 0; background: none; font-size: 22px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.account-card { width: min(620px, calc(100vw - 28px)); max-height: min(760px, calc(100dvh - 24px)); overflow-y: auto; }
.account-intro { margin: 8px 0 22px; color: var(--muted); font-size: 12px; line-height: 1.65; }
.account-fieldset { margin: 0 0 14px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(244,237,223,.55); }
.account-fieldset legend { display: flex; gap: 10px; align-items: center; padding: 0 7px; }
.account-fieldset legend strong, .account-fieldset legend small { display: block; }
.account-fieldset legend small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.account-choices { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; margin-top: 8px; }
.account-choices label { min-width: 0; margin: 0; cursor: pointer; }
.account-choices input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.account-choices label > span { display: block; min-height: 70px; padding: 11px; border: 1px solid var(--line); border-radius: 10px; background: rgba(251,246,236,.72); }
.account-choices label:nth-child(2) > span { background: rgba(217,209,219,.36); }
.account-choices label:nth-child(3) > span { background: rgba(213,220,205,.44); }
.account-choices strong, .account-choices small { display: block; }
.account-choices small { margin-top: 5px; color: var(--muted); font-size: 9px; line-height: 1.4; }
.account-choices input:checked + span { border-color: var(--brick); box-shadow: inset 0 0 0 1px rgba(162,79,67,.22), 3px 3px 0 rgba(162,79,67,.13); transform: translateY(-1px); }
.account-choices input:focus-visible + span { outline: 3px solid rgba(162,79,67,.27); outline-offset: 2px; }

@media (prefers-reduced-motion: no-preference) {
  .message { animation: rise .22s ease-out; }
  .login-card { animation: settle .35s ease-out; }
}
@keyframes rise { from { opacity: 0; transform: translateY(5px); } }
@keyframes settle { from { opacity: 0; transform: translateY(8px) rotate(-.35deg); } }
@keyframes tap-spark { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.25) rotate(-20deg); } 38% { opacity: .82; transform: translate(-50%, -50%) scale(1) rotate(4deg); } 100% { opacity: 0; transform: translate(-50%, -65%) scale(.55) rotate(18deg); } }

@media (max-width: 780px) {
  body { background-attachment: scroll; background-position: center top; background-size: 480px 480px; }
  body::before { background: rgba(244, 237, 223, .38); }
  .shell { height: 100dvh; grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 56px; background: rgba(244, 237, 223, .34); }
  .rail { grid-row: 2; min-height: 0; padding: 4px 8px 5px; border: 0; border-top: 1px solid var(--line); background: rgba(232,223,209,.96); }
  .brand, .crew-block, .safe-note, .text-button { display: none; }
  .nav { margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
  .nav-item { min-height: 46px; padding: 2px 4px; display: flex; align-items: center; justify-content: center; gap: 3px; text-align: center; font-size: 11px; touch-action: manipulation; }
  .nav-item span { display: inline-block; width: auto; margin: 0; }
  .nav-item.active { box-shadow: 2px 3px 0 rgba(141,129,148,.18); }
  .shell[data-active-view="orders"], .shell[data-active-view="approvals"] { grid-template-rows: minmax(0, 1fr) 56px; }
  .shell[data-active-view="orders"] .rail, .shell[data-active-view="approvals"] .rail { padding-top: 4px; padding-bottom: 5px; }
  .shell[data-active-view="orders"] .nav-item, .shell[data-active-view="approvals"] .nav-item { min-height: 46px; }
  .main { grid-row: 1; min-height: 0; }
  .topbar { min-height: 72px; padding: max(14px, env(safe-area-inset-top)) 16px 14px; }
  .topbar h2 { font-size: 19px; }
  .header-actions { gap: 7px; }
  .account-button { min-width: 44px; width: 44px; grid-template-columns: 1fr; justify-items: center; }
  .account-button b, .account-button small { display: none; }
  .connection { display: none; }
  .messages { padding: 20px 14px; }
  .empty-chat { margin: 7vh auto; padding: 0 4px; }
  .empty-chat .seal { margin-left: 12%; }
  .empty-chat h3 { font-size: 28px; }
  .empty-chat p { margin-left: 8%; }
  .composer-wrap { padding: 0 12px 10px; }
  .bubble-wrap { max-width: 86%; }
  .order-board { grid-template-columns: 1fr; padding: 16px; }
  .approval-empty { margin: 20px; padding: 34px 24px; }
  .gate-list { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .account-choices { grid-template-columns: 1fr; }
  .account-choices label > span { min-height: 0; }
  .login-card { padding: 38px 27px 32px; }
  .dialog-card { padding: 27px 22px; }
  input, textarea, select { font-size: 16px; }
  .mention-row button, .soft-button, .send-button, .primary.compact { min-height: 44px; touch-action: manipulation; }
  .composer textarea { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; transition: none !important; }
}

@media (prefers-contrast: more) {
  :root { --line: rgba(63,40,56,.36); --line-strong: rgba(63,40,56,.58); }
  body::before { background: rgba(244,237,223,.87); }
}
