/* sävy — stark utilitarian minimalism. hairlines, one indigo, mono micro-labels. */

:root {
  --bg: #0e0f11;
  --panel: #131417;
  --panel2: #17181c;
  --line: #24262c;
  --line-soft: #1c1e23;
  --text: #e8e9eb;
  --dim: #8b909a;
  --faint: #5c616b;
  --accent: #5e6ad2;
  --accent-soft: #7c85dd;
  --err: #e5484d;
  --ok: #3dd68c;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
          "Malgun Gothic", "Hiragino Kaku Gothic ProN", "Yu Gothic UI",
          "Microsoft YaHei UI", "PingFang SC", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, Menlo, monospace;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #fafafa;
    --panel: #ffffff;
    --panel2: #f4f4f6;
    --line: #e2e3e8;
    --line-soft: #ececef;
    --text: #17181b;
    --dim: #666b74;
    --faint: #9BA0A8;
    --accent: #4f5ac9;
    --accent-soft: #3d47ad;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; } /* author display rules must not defeat the hidden attribute */
html { height: 100%; }
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.5 var(--sans);
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

.micro-label {
  font: 500 10.5px/1 var(--mono);
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--faint);
}
.mono-dim { font: 400 11px/1 var(--mono); color: var(--faint); letter-spacing: .02em; }

/* ── header: sticky, translucent, blurred ───────────── */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(1.6);
  backdrop-filter: blur(18px) saturate(1.6);
  border-bottom: 1px solid var(--line-soft);
}
@supports not (backdrop-filter: blur(1px)) { .top { background: var(--bg); } }
.brand { font: 600 17px/1 var(--sans); letter-spacing: -.02em; user-select: none; }
.brand em { font-style: normal; color: var(--accent-soft); }

/* iOS-style segmented mode switch with sliding thumb */
.mode-switch {
  position: relative; display: inline-grid;
  grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--panel2); border-radius: 9px; padding: 2px;
  box-shadow: inset 0 0 0 1px var(--line-soft);
}
.mode-switch button {
  position: relative; z-index: 1;
  font-size: 12.5px; font-weight: 500; color: var(--dim);
  padding: 5px 14px; border-radius: 7px; text-align: center;
  transition: color .18s;
}
.mode-switch button.on { color: var(--text); }
.mode-switch .thumb {
  position: absolute; top: 2px; bottom: 2px; left: 2px;
  width: calc(50% - 2px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 1px 3px rgba(0,0,0,.22);
  transition: transform .28s cubic-bezier(.25, .9, .3, 1);
}
.mode-switch[data-mode="words"] .thumb { transform: translateX(100%); }

.ghost-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--dim);
  padding: 5px 9px; border-radius: 6px;
  transition: color .12s, background .12s;
}
.ghost-btn:hover { color: var(--text); background: var(--panel2); }
.ghost-btn.small { font-size: 11.5px; padding: 4px 7px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px; color: var(--dim);
  transition: color .12s, background .12s;
}
.icon-btn:hover { color: var(--text); background: var(--panel2); }

/* ── controls ───────────────────────────────────────── */
.controls {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}
.lang-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.detect-chip {
  font: 500 11px/1 var(--mono); letter-spacing: .04em;
  color: var(--faint);
  border: 1px dashed var(--line);
  border-radius: 6px; padding: 6px 8px;
  white-space: nowrap;
}
.detect-chip.live { color: var(--accent-soft); border-color: var(--accent); border-style: solid; }

.lang-row { flex: 1; }
.pills {
  display: flex; gap: 2px; min-width: 0; flex: 1;
  overflow-x: auto; scrollbar-width: none;
  touch-action: pan-x; overscroll-behavior-x: contain;
}
.pills::-webkit-scrollbar { display: none; }
.pills button {
  flex: none;
  font-size: 12.5px; color: var(--dim); white-space: nowrap;
  padding: 6px 10px; border-radius: 6px;
  transition: color .12s, background .12s;
}
.pills button:hover { color: var(--text); }
.pills button.on { color: var(--text); background: var(--panel2); box-shadow: inset 0 0 0 1px var(--line); }

.mode-row { display: flex; align-items: center; gap: 14px; }
.seg {
  display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden;
}
.seg button {
  font-size: 11.5px; color: var(--dim); padding: 5px 10px;
  border-right: 1px solid var(--line-soft);
  transition: color .12s, background .12s;
}
.seg button:last-child { border-right: none; }
.seg button.on { color: var(--text); background: var(--panel2); }

/* ── touch & motion niceties ────────────────────────── */
button { transition-property: color, background, border-color, transform; }
.pills button:active, .seg button:active, .chips button:active,
.ghost-btn:active, .icon-btn:active, .mode-switch button:active { transform: scale(.95); }
::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation: none !important; }
}

/* ── panes: full-bleed, hairline dividers ───────────── */
.panes {
  display: grid; grid-template-columns: 1fr 1fr;
  min-height: 0;
}
.pane { display: flex; flex-direction: column; min-width: 0; }
.pane-src { border-right: 1px solid var(--line); }
.pane-out { background: var(--panel); position: relative; }

#src {
  width: 100%; flex: 1;
  min-height: 168px;
  background: none; border: none; outline: none; resize: none;
  color: var(--text);
  font: 400 16.5px/1.75 var(--sans);
  padding: 18px 20px 6px;
  caret-color: var(--accent);
}
#src::placeholder { color: var(--faint); }

.trans {
  flex: 1;
  font: 400 16.5px/1.75 var(--sans);
  padding: 18px 20px 6px;
  white-space: pre-wrap; word-break: break-word;
  min-height: 168px;
}
.trans:empty::before { content: "sävy"; color: var(--line); font-weight: 600; }
.trans.thinking:empty::before {
  content: "···"; color: var(--faint); font-weight: 400;
  animation: blink 1.2s steps(2, start) infinite;
}
.trans.streaming::after {
  content: "▍"; color: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.pane-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 12px 10px;
  min-height: 34px;
}
.pane-foot .mono-dim { margin-left: auto; }
.out-actions { justify-content: flex-end; }

.errbar {
  position: absolute; top: 8px; left: 12px; right: 12px;
  font: 400 11.5px/1.4 var(--mono);
  color: var(--err);
  border: 1px solid color-mix(in srgb, var(--err) 35%, transparent);
  background: color-mix(in srgb, var(--err) 7%, var(--panel));
  border-radius: 6px; padding: 7px 10px;
  z-index: 2;
}

/* ── dictionary panel header ────────────────────────── */
.tabbar { display: flex; align-items: center; gap: 14px; }
/* same treatment as the header mode-switch thumb, minus the track background */
.dict-btns { display: inline-flex; gap: 6px; }
.dict-btns button {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 54px; height: 26px; line-height: 1;
  font-size: 12.5px; font-weight: 500; color: var(--dim);
  padding: 0 12px; border-radius: 7px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(0,0,0,.22);
  transition: color .18s, border-color .18s;
}
.dict-btns button:hover { color: var(--text); }
.dict-btns button.on { color: var(--text); border-color: var(--accent); }
.dict-btns button:active { transform: scale(.95); }
.dict-btns button.loading { animation: pulse 1s ease-in-out infinite; }
.trans ruby { ruby-position: over; ruby-align: center; }
/* readings are an aid, not content: keep them out of manual text selection */
.trans rt {
  font-size: .55em; color: var(--dim);
  user-select: none; -webkit-user-select: none;
}
.tabbar .spacer { flex: 1; }

/* ── words view (thesaurus / word finder) ───────────── */
.words-wrap { max-width: 640px; margin: clamp(24px, 9vh, 96px) auto 0; padding-bottom: 24px; }
.search-field {
  display: flex; align-items: center; gap: 11px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 15px 17px;
  color: var(--faint);
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
  transition: border-color .15s, box-shadow .15s;
  cursor: text;
}
.search-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.search-field input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font: 400 17px/1.4 var(--sans);
  caret-color: var(--accent);
}
.search-field input::placeholder { color: var(--faint); }
.thes-out { margin-top: 18px; }
#mic.rec { color: var(--err); }
#mic.rec svg { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.thes-row { display: flex; gap: 12px; align-items: baseline; margin-top: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  font-size: 13px; color: var(--dim);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px;
  transition: color .12s, border-color .12s;
}
.chips button:hover { color: var(--text); border-color: var(--accent); }

/* ── dictionary guide ───────────────────────────────── */
.guide {
  border-top: 1px solid var(--line);
  padding: 12px 20px 8px;
  animation: rise .18s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(3px); } }
.micro-src { text-transform: none; letter-spacing: .03em; color: var(--faint); opacity: .75; }

.guide-note {
  margin-top: 10px;
  font-size: 12.5px; color: var(--dim);
  border-left: 2px solid var(--accent);
  padding: 2px 0 2px 10px;
}
.guide-rows { margin-top: 4px; }
.grow { border-bottom: 1px solid var(--line-soft); }
.grow:last-child { border-bottom: none; }
.grow-head {
  width: 100%; display: flex; align-items: baseline; gap: 10px;
  padding: 9px 2px; text-align: left;
  transition: background .12s;
  border-radius: 4px;
}
.grow-head:hover { background: var(--panel2); }
.grow-head .w { font-size: 15px; font-weight: 550; }
.grow-head .r { font: 400 11.5px/1 var(--mono); color: var(--accent-soft); }
.grow-head .g { font-size: 13px; color: var(--dim); margin-left: auto; text-align: right; }
.grow-head .chev { color: var(--faint); font-size: 10px; transition: transform .15s; }
.grow.open .chev { transform: rotate(90deg); }

.grow-body { display: none; padding: 2px 2px 12px 12px; }
.grow.open .grow-body { display: block; }
.sense { margin-top: 8px; }
.sense-pos {
  font: 500 10px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent-soft);
}
.sense ol { margin: 5px 0 0 16px; }
.sense li { font-size: 13px; color: var(--dim); margin-top: 3px; }
.sense li .ex { display: block; color: var(--faint); font-size: 12px; font-style: italic; }
.dict-empty, .dict-loading { font: 400 12px/1 var(--mono); color: var(--faint); padding: 8px 0 4px; }
.dict-more { font: 400 11px/1 var(--mono); color: var(--accent-soft); text-decoration: none; display: inline-block; margin-top: 8px; }
.dict-more:hover { text-decoration: underline; }

/* ── footer ─────────────────────────────────────────── */
.foot {
  margin-top: auto;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.foot .spacer { flex: 1; }
.flash { color: var(--ok); opacity: 0; transition: opacity .3s; }
.flash.show { opacity: 1; }

/* ── password gate ──────────────────────────────────── */
.gate {
  position: fixed; inset: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.gate-card {
  display: flex; flex-direction: column; gap: 10px;
  width: min(300px, 84vw);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 18px;
}
.gate-card input {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px;
  font: 400 14px/1 var(--mono); padding: 9px 10px; outline: none;
}
.gate-card input:focus { border-color: var(--accent); }
.gate-card button {
  background: var(--accent); color: #fff; border-radius: 7px;
  font-size: 13px; font-weight: 500; padding: 8px;
}
.gate-err { font: 400 11.5px/1 var(--mono); color: var(--err); }

/* ── mobile ─────────────────────────────────────────── */
@media (max-width: 720px) {
  .top { padding-left: 14px; padding-right: 14px; }
  .mode-switch button { padding: 5px 10px; }
  .controls { padding: 8px 14px; gap: 8px; }
  .mode-row { width: 100%; justify-content: space-between; }
  .panes { grid-template-columns: 1fr; }
  .pane-src { border-right: none; border-bottom: 1px solid var(--line); }
  #src, .trans { min-height: 128px; padding: 14px 16px 4px; }
  .guide { padding: 12px 16px 8px; }
  .words-wrap { margin-top: 18px; }
  .foot { padding-left: 16px; padding-right: 16px; gap: 12px; }
  .hint-key { display: none; }
}
