/* Palette and type borrowed from the Grady test-bed: warm neutrals + iris accent. */
:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --surface-3: #e7e4dd;
  --line: #e2dfd8;
  --text: #1c1b19;
  --text-2: #5d5a53;
  --text-3: #8b877e;
  --accent: #5b4fe0;
  --accent-ink: #ffffff;
  --accent-soft: #ecebfd;
  --danger: #c4372b;
  --danger-soft: #fbeceb;
  --warn: #a45b00;
  --ok: #1f7a4d;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgb(20 18 12 / 0.05), 0 8px 24px rgb(20 18 12 / 0.06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312;
    --surface: #1b1b19;
    --surface-2: #232320;
    --surface-3: #2d2c29;
    --line: #2e2d2a;
    --text: #ecebe7;
    --text-2: #b0ada5;
    --text-3: #7f7c75;
    --accent: #8f86ff;
    --accent-ink: #120f2a;
    --accent-soft: #24223d;
    --danger: #ff7b6e;
    --danger-soft: #3a1d1a;
    --warn: #f0b056;
    --ok: #5fd39a;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.25);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.shell { display: grid; grid-template-columns: 270px minmax(0, 1fr); height: 100dvh; }

/* sidebar */
.sidebar { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--surface-2); border-right: 1px solid var(--line); min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 2px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; }
/* Grady's whorl G (ported from grady-android Whorl.kt; timings from its approved prototype) */
.brandmark { display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; }
.brandmark .whorl { width: 100%; height: 100%; color: var(--accent); }
.whorl { display: block; flex: none; overflow: visible; color: var(--text-2); }
.whorl .off { stroke: var(--surface-3); }
.w-think { color: var(--accent); }
.w-wait { color: var(--text-2); }
.w-fail { color: var(--warn); }
.w-think .next { animation: whorl-breathe 1.6s ease-in-out infinite; }
.w-wait .next { animation: whorl-breathe-grey 3.2s ease-in-out infinite; }
/* done: each ridge draws in from its mouth (inner first, 90 ms apart), the crossbar last, with a small press,
   then the colour settles from accent to text-2. draw: the same without the colour (the brand mark). */
.w-done, .w-draw { animation: whorl-press 0.7s cubic-bezier(0.3, 0.7, 0.2, 1) both; }
.w-done { animation: whorl-press 0.7s cubic-bezier(0.3, 0.7, 0.2, 1) both, whorl-settle 0.8s ease 0.8s both; }
.w-done .wr, .w-done .wb, .w-draw .wr, .w-draw .wb { stroke-dasharray: var(--len) calc(var(--len) * 2); animation: whorl-draw 0.55s cubic-bezier(0.3, 0.7, 0.2, 1) both; }
.whorl .wr[data-order="1"] { animation-delay: 90ms; }
.whorl .wr[data-order="2"] { animation-delay: 180ms; }
.whorl .wr[data-order="3"] { animation-delay: 270ms; }
.whorl .wb { animation-delay: 360ms; }
@keyframes whorl-draw { from { stroke-dashoffset: var(--len); } to { stroke-dashoffset: 0; } }
@keyframes whorl-press { 0% { transform: scale(0.8); } 55% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes whorl-settle { from { color: var(--accent); } to { color: var(--text-2); } }
@keyframes whorl-breathe { 0%, 100% { stroke: color-mix(in srgb, var(--accent) 15%, var(--surface-3)); } 45% { stroke: var(--accent); } }
@keyframes whorl-breathe-grey { 0%, 100% { stroke: color-mix(in srgb, var(--text-3) 15%, var(--surface-3)); } 45% { stroke: var(--text-3); } }
@media (prefers-reduced-motion: reduce) {
  .whorl, .whorl * { animation: none !important; }
  .w-think .next { stroke: color-mix(in srgb, var(--accent) 50%, var(--surface-3)); }
  .w-wait .next { stroke: color-mix(in srgb, var(--text-3) 50%, var(--surface-3)); }
}
.new-chat { width: 100%; justify-content: center; }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.chat-item { display: flex; align-items: center; gap: 4px; border-radius: var(--radius-sm); }
.chat-item > button.open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: var(--radius-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
.chat-item:hover, .chat-item.active { background: var(--surface-3); }
.chat-item.active > button.open { color: var(--text); font-weight: 550; }
.chat-item .del { opacity: 0; background: none; border: 0; color: var(--text-2); width: 30px; height: 30px; border-radius: 8px; }
.chat-item:hover .del, .chat-item.active .del, .chat-item .del:focus-visible { opacity: 1; }
.chat-item .del:hover { color: var(--danger); background: var(--danger-soft); }
.side-foot { margin: 0; font-size: 12px; color: var(--text-2); line-height: 1.45; padding: 0 4px; }
/* Interface language: Indonesia | English (default Indonesian) */
.lang-switch { display: flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface-2); margin: 0 4px; }
.lang-switch button { flex: 1; min-height: 30px; border: 0; border-radius: 99px; background: none; color: var(--text-2); font: inherit; font-size: 12.5px; cursor: pointer; }
.lang-switch button:hover { color: var(--text); }
.lang-switch button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }
.lang-switch button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* main */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.title { flex: 1; margin: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); padding: 4px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.status.online i { background: var(--ok); }
.status.busy i { background: var(--warn); }
.status.offline i { background: var(--danger); }

.messages { flex: 1; overflow-y: auto; padding: 20px 16px 8px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.messages > * { width: 100%; max-width: 760px; margin-inline: auto; }
.msg { display: flex; flex-direction: column; gap: 4px; }
.msg .bubble { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: var(--accent-soft); padding: 9px 14px; border-radius: var(--radius) var(--radius) 4px var(--radius); max-width: 85%; }
.msg.assistant .who { font-size: 12px; font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.msg.assistant .who .whorl { width: 20px; height: 20px; }
.option .who { display: flex; align-items: center; gap: 6px; }
.option .who .whorl { width: 18px; height: 18px; }
.msg.assistant .bubble { padding: 2px 0; }
.msg .note { font-size: 12.5px; color: var(--text-2); }
.msg .note.err { color: var(--danger); }
.msg .note.retries { align-self: flex-start; font-size: 12px; font-variant-numeric: tabular-nums; padding: 1px 8px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface-2); }
.msg .actions { display: flex; gap: 6px; }
.msg .actions button { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 2px 9px; font-size: 12.5px; color: var(--text-2); }
.msg .actions button:hover { background: var(--surface-2); }
.msg .actions { align-items: center; }
.msg .actions button.rate { display: inline-grid; place-items: center; width: 30px; height: 28px; padding: 0; color: var(--text-2); }
.msg .actions button.rate.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* pick the best of three */
.compare { display: flex; flex-direction: column; gap: 10px; }
.compare-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.compare-head span { font-size: 13px; color: var(--text-2); }
.compare-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.option { display: flex; flex-direction: column; gap: 6px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); min-width: 0; }
.option .who { font-size: 12px; font-weight: 600; color: var(--text-2); }
.option .bubble { flex: 1; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; }
.option .note { font-size: 12.5px; color: var(--text-2); }
.option .note:empty { display: none; }
.btn.pick { justify-content: center; padding: 7px 12px; font-size: 13.5px; }
.btn.pick:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn.pick:disabled { opacity: 0.45; cursor: default; }
.empty .notice { margin: 18px auto 0; max-width: 380px; font-size: 12.5px; color: var(--text-2); }
.composer textarea:disabled { background: var(--surface-2); cursor: not-allowed; }
.compare-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.compare-foot .btn { padding: 7px 14px; font-size: 13.5px; }
.compare-foot .btn:disabled { opacity: 0.45; cursor: default; }
.allbad { display: flex; flex-direction: column; gap: 8px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.allbad label { font-size: 13.5px; font-weight: 600; }
.allbad .opt { font-weight: 400; color: var(--text-2); }
.allbad textarea { width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg); font-size: 14px; line-height: 1.45; resize: vertical; min-height: 70px; }
.allbad textarea:focus { outline: none; border-color: var(--accent); }

/* detailed feedback */
.msg .actions button.fb-btn { display: inline-flex; align-items: center; gap: 5px; height: 28px; }
.msg .actions button.fb-btn.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.fb-panel { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); max-width: 560px; }
.fb-panel fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.fb-panel legend, .fb-panel .ideal-label { font-size: 13.5px; font-weight: 600; margin-bottom: 8px; padding: 0; }
.fb-panel .opt { font-weight: 400; color: var(--text-2); }
.scores { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.score { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 4px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; text-align: center; }
.score b { font-size: 16px; }
.score span { font-size: 11.5px; color: var(--text-2); line-height: 1.2; }
.score:hover { border-color: var(--accent); }
.score.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.score.on span { color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; padding: 5px 11px; border: 1px solid var(--line); border-radius: 99px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.score input, .chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.score:has(input:focus-visible), .chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.fb-panel .other, .fb-panel textarea { width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg); font-size: 14px; line-height: 1.45; }
.fb-panel .other { margin-top: 8px; }
.fb-panel textarea { resize: vertical; min-height: 70px; }
.fb-panel .other:focus, .fb-panel textarea:focus { outline: none; border-color: var(--accent); }
.fb-row { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.fb-err { flex: 1; font-size: 12.5px; color: var(--danger); }
.btn.ghost { background: none; }
.btn.ghost:hover { background: var(--surface-2); }

.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.empty { margin: auto; text-align: center; padding: 24px 8px; color: var(--text-2); }
.empty .brandmark { display: grid; width: 52px; height: 52px; margin: 0 auto 12px; }
.empty h2 { margin: 0 0 4px; font-size: 22px; color: var(--text); }
.empty p { margin: 0 0 18px; font-size: 14px; }
.starters { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.starters button { background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 7px 14px; font-size: 13.5px; color: var(--text-2); box-shadow: var(--shadow); }
.starters button:hover { color: var(--text); border-color: var(--accent); }
.starters-head { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.shuffle { display: inline-flex; align-items: center; gap: 5px; background: none; border: 0; border-radius: 99px; padding: 4px 10px; font-size: 13px; font-weight: 550; color: var(--accent); }
.shuffle:hover { background: var(--accent-soft); }


.composer { display: flex; gap: 8px; align-items: flex-end; width: 100%; max-width: 792px; margin: 0 auto; padding: 10px 16px calc(14px + env(safe-area-inset-bottom, 0px)); }
.field { position: relative; flex: 1; display: flex; min-width: 0; }
.composer textarea { flex: 1; min-width: 0; resize: none; max-height: 180px; padding: 11px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); line-height: 1.45; }
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer textarea { padding-right: 46px; }
.idea { position: absolute; right: 7px; bottom: 7px; display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--text-2); }
.idea:hover { color: var(--accent); background: var(--accent-soft); }
.idea[hidden] { display: none; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 9px 16px; border-radius: var(--radius-sm); font-weight: 550; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:disabled { opacity: 0.5; cursor: default; }
.btn.stop { background: var(--text); color: var(--bg); }
.send { min-height: 44px; }
.icon-btn { background: none; border: 0; width: 36px; height: 36px; border-radius: 9px; font-size: 18px; color: var(--text-2); }
.icon-btn:hover { background: var(--surface-3); }
.only-mobile { display: none; }
.scrim { display: none; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; width: min(360px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog p { margin: 0 0 12px; color: var(--text-2); font-size: 14px; }
dialog input { width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg); margin-bottom: 10px; }
dialog .row { display: flex; justify-content: flex-end; }
.code-error { color: var(--danger) !important; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 10px 9px 16px; border-radius: 99px; font-size: 14px; display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow); z-index: 30; }
.toast button { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; padding: 2px 8px; }

/* offline / resting banner above the message box */
.notice-bar { display: flex; align-items: center; gap: 10px; width: calc(100% - 32px); max-width: 760px; margin: 6px auto 0; padding: 10px 8px 10px 14px; border: 1px solid var(--line); border-left: 3px solid var(--danger); border-radius: var(--radius-sm); background: var(--surface); box-shadow: var(--shadow); }
.notice-bar.paused { border-left-color: var(--warn); }
.notice-bar[hidden] { display: none; }
.notice-bar p { flex: 1; margin: 0; font-size: 13.5px; line-height: 1.45; color: var(--text); }
.notice-bar .btn { flex: none; padding: 6px 12px; font-size: 13.5px; }
.notice-bar .btn:disabled { opacity: 0.6; cursor: default; }
.notice-close { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 8px; background: none; color: var(--text-2); }
.notice-close:hover { background: var(--surface-2); }

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(290px, 84vw); z-index: 20; transform: translateX(-100%); visibility: hidden; transition: transform 0.2s ease, visibility 0s 0.2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; visibility: visible; transition: transform 0.2s ease; }
  @media (prefers-reduced-motion: reduce) { .sidebar, .sidebar.open { transition: none; } }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgb(0 0 0 / 0.3); z-index: 10; }
  .only-mobile { display: inline-grid; place-items: center; }
  .topbar { padding: calc(6px + env(safe-area-inset-top, 0px)) calc(8px + env(safe-area-inset-right, 0px)) 6px calc(8px + env(safe-area-inset-left, 0px)); gap: 6px; }
  .chat-item .del { opacity: 1; }

  /* Android / phones: thumb-sized targets, comfier typing, no accidental pull-to-refresh mid-chat. */
  button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
  .icon-btn { width: 44px; height: 44px; font-size: 20px; flex: none; }
  .icon-btn:active { background: var(--surface-3); }
  .title { font-size: 16px; }
  .status { padding: 4px 9px; }
  .sidebar { padding-top: calc(12px + env(safe-area-inset-top, 0px)); padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .new-chat { min-height: 48px; font-size: 15.5px; }
  .lang-switch button { min-height: 40px; font-size: 14px; }
  .chat-item > button.open { padding: 12px 10px; }
  .chat-item .del { width: 44px; height: 44px; }

  .messages { padding: 16px 14px 8px; overscroll-behavior-y: contain; }
  .msg .actions { gap: 8px; flex-wrap: wrap; }
  .msg .actions button { min-height: 40px; padding: 4px 12px; font-size: 13.5px; }
  .msg .actions button.rate { width: 44px; height: 40px; }
  .msg .actions button.fb-btn { height: 40px; }
  .btn.pick, .compare-foot .btn { min-height: 44px; }
  .score { min-height: 56px; }
  .chip { min-height: 40px; padding: 8px 14px; font-size: 14px; }
  .fb-row .btn { min-height: 44px; }

  .empty { padding: 16px 4px; }
  .starters { flex-direction: column; align-items: stretch; gap: 8px; }
  .starters button { min-height: 46px; padding: 10px 16px; font-size: 15px; text-align: left; border-radius: var(--radius); }
  .shuffle { min-height: 40px; padding: 6px 12px; font-size: 14px; }

  .composer { gap: 8px; padding: 8px calc(10px + env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) calc(10px + env(safe-area-inset-left, 0px)); }
  .composer textarea { font-size: 16px; line-height: 1.4; min-height: 50px; padding: 13px 52px 13px 16px; border-radius: 25px; }
  .idea { right: 5px; bottom: 5px; width: 40px; height: 40px; }
  .idea svg { width: 20px; height: 20px; }
  .idea:active { background: var(--accent-soft); }
  .send { min-height: 50px; min-width: 68px; justify-content: center; border-radius: 25px; font-size: 15.5px; }
  .toast { bottom: calc(90px + env(safe-area-inset-bottom, 0px)); max-width: calc(100vw - 24px); }
  .notice-bar { width: calc(100% - 20px); flex-wrap: wrap; padding: 10px 6px 10px 12px; }
  .notice-bar p { flex-basis: calc(100% - 56px); font-size: 14px; }
  .notice-bar .btn { min-height: 40px; }
  .notice-close { width: 40px; height: 40px; order: 1; }
  .notice-bar .btn { order: 2; }
}

@media (prefers-reduced-motion: reduce) { .cursor::after { animation: none; } }
