/* Kikiwake's one stylesheet. The base rules (colours, type, buttons, inputs,
   segmented control, bottom sheet) follow septo-caine/Fun's
   common/static/style.css so the apps feel like one family: ink on paper,
   one typeface, outlined panels, hairline rules, small uppercase labels.

   The page is a fixed column the height of the screen: top bar, a scrolling
   transcript, and the controls at the bottom within thumb reach. */

@font-face {
  font-family: "Geist Mono";
  src: url("fonts/geist-mono.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #eeeee9;          /* paper */
  --surface-2: #e1e1db;   /* the few filled things */
  --text: #151515;        /* ink */
  --muted: #6d6d68;
  --border: #c9c9c2;      /* hairline rules between rows */
  --line: #151515;        /* panel outlines */
  --accent: #151515;
  --accent-soft: #15151512;
  --accent-text: #eeeee9;
  --radius: 26px;
  --radius-sm: 14px;
  --tap: 48px;
  /* Geist Mono has no Japanese, so kana and kanji fall through to the
     phone's own Japanese font. */
  --font: "Geist Mono", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP",
    "Noto Sans CJK JP", ui-monospace, "SF Mono", Menlo, Consolas, sans-serif;
  --fs: 17px;             /* transcript text; set by the S/M/L/XL choice */
  color-scheme: light dark;
}

html[data-size="s"] { --fs: 15px; }
html[data-size="l"] { --fs: 20px; }
html[data-size="xl"] { --fs: 24px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f0e;
    --surface-2: #1d1d1b;
    --text: #e9e9e3;
    --muted: #8f8f88;
    --border: #2d2d2a;
    --line: #e9e9e3;
    --accent: #e9e9e3;
    --accent-soft: #e9e9e314;
    --accent-text: #0f0f0e;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 var(--font);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden; /* only the transcript scrolls */
}

[hidden] { display: none !important; }

a { color: inherit; text-underline-offset: 3px; text-decoration-thickness: 1px; }

h3 { margin: 0; line-height: 1.15; }

.label, summary.label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.num { font-variant-numeric: tabular-nums; }

.icon {
  flex: none;
  display: block;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Buttons: ink pills. Secondary is an outline, ghost is just a word. */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 22px;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
}

button:active { transform: scale(0.98); }
button:disabled { opacity: 0.35; cursor: default; }
button.block { display: flex; width: 100%; }
button.secondary { background: transparent; color: var(--text); border-color: var(--line); }
button.ghost { background: transparent; color: var(--text); border-color: transparent; padding: 0 12px; }
button.danger { background: transparent; color: var(--text); border-color: transparent; }
button.small { min-height: 36px; padding: 0 16px; font-size: 12px; }

button.icon-only {
  width: 44px;
  min-height: 44px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--text);
}

button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* Inputs */

label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px+ stops iPhone zooming in on focus */
}

input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 40px; }
select option { background: var(--bg); color: var(--text); }
textarea { min-height: 72px; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: none; box-shadow: 0 0 0 1.5px var(--line); }
input[type="checkbox"] { width: 22px; min-height: 22px; padding: 0; accent-color: var(--text); box-shadow: none; flex: none; }

label.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: inherit;
  text-transform: none;
}

.field { margin-bottom: 24px; }
.field > .label { display: block; margin-bottom: 8px; font-size: 11px; color: var(--muted); }
.help { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

.key-row { display: flex; gap: 4px; }
.key-row input { flex: 1; min-width: 0; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row button { flex: 1; padding: 0 12px; }

details summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--muted); }
details[open] summary { margin-bottom: 8px; }

/* Segmented control: words in a row, the chosen one underlined */

.segmented {
  display: flex;
  gap: 4px;
  border-bottom: 1.5px solid var(--line);
}

.segmented button {
  flex: 1;
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  margin-bottom: -1.5px;
}

.segmented button:active { transform: none; }
.segmented .on { color: var(--text); box-shadow: inset 0 -3px 0 var(--text); }

/* Lists and notices */

.list {
  list-style: none;
  margin: 0;
  padding: 0 4px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
}

.list > li { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 4px 4px 4px 14px; }
.list > li + li { border-top: 1px solid var(--border); }
.list > li span { flex: 1; min-width: 0; }

.flash {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 4px 16px 8px;
  padding: 6px 4px 6px 18px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-sm);
}

.flash p { flex: 1; margin: 10px 0; font-size: 14px; }

.confirm {
  margin-top: 12px;
  padding: 4px 16px 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
}

.confirm p { font-size: 14px; }

/* Bottom sheet (a <dialog>) */

dialog.sheet {
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  margin: auto auto 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1.5px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--bg);
  color: var(--text);
}

dialog.sheet::backdrop { background: #0008; }

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.sheet-head h3 { flex: 1; text-align: center; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.head-spacer { width: 44px; flex: none; }
.sheet-body { padding: 20px 20px calc(24px + env(safe-area-inset-bottom)); }

@media (min-width: 720px) {
  dialog.sheet { margin: auto; border-bottom: 1.5px solid var(--line); border-radius: var(--radius); }
}

/* App frame */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 960px;
  margin: 0 auto;
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: env(safe-area-inset-top) 16px 0;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand .kanji { color: var(--muted); font-weight: 400; letter-spacing: 0.1em; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.status .dot { width: 8px; height: 8px; border: 1.5px solid currentColor; border-radius: 50%; }
.status[data-state="listening"] .dot { background: currentColor; animation: blink 1.6s ease-in-out infinite; }
.status[data-state="reconnecting"], .status[data-state="error"] { border-style: dashed; }
.status .timer:empty { display: none; }

@keyframes blink { 50% { opacity: 0.25; } }

/* The transcript. The board is as wide as the screen, or wider when there are
   many lanes, in which case it scrolls sideways inside the scroller. */

.scroller {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.board {
  --lanes: 1;
  min-width: max(100%, calc(var(--lanes) * 108px));
  padding: 0 16px 24px;
}

.lanes-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(var(--lanes), minmax(0, 1fr));
  gap: 4px;
  background: var(--bg);
  border-bottom: 1.5px solid var(--line);
}

.lanes-head:empty { display: none; }
.lanes-head.has-hidden { grid-template-columns: repeat(var(--lanes), minmax(0, 1fr)) auto; }

/* The eye at the end of the lane names: some speakers are hidden. */
.lanes-hidden { position: relative; align-self: center; color: var(--muted); }
.lanes-hidden .count {
  position: absolute;
  top: 4px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 10px;
  line-height: 16px;
  letter-spacing: 0;
}

.lane {
  min-height: 48px;
  padding: 0 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  justify-content: center;
  min-width: 0;
}

.lane .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* The numbered circle that marks a speaker, in the lane head and on each turn. */
.badge {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.badge.wide { width: auto; min-width: 22px; padding: 0 5px; border-radius: 999px; }

/* The bubbles. app.js places each one (left, top, width): in portrait about
   68% of the width, slid across by speaker, one below the other; in
   landscape one column per speaker, side by side when people talk at once.
   A gutter on the left holds the timeline. */

.lanes-head { padding-left: 58px; }
.board.columns .lanes-head { gap: 10px; }

.rows { position: relative; margin-top: 12px; }

.turn {
  position: absolute;
  padding: 8px 12px 10px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
}

.turn.live { border-width: 2.5px; padding: 7px 11px 9px; }
.turn.new { border-style: dashed; }

/* A short reply (うん, はい): only as wide as its words, smaller, beside the
   bubble it answers. Or just a dot. */
.turn.nod { width: max-content; padding: 4px 10px 5px; border-width: 1px; cursor: default; }
.turn.nod.live { border-width: 2px; padding: 3px 9px 4px; }
.turn.nod .say { font-size: calc(var(--fs) * 0.8); }
.turn.nod.dot { width: 8px; height: 8px; min-width: 0; padding: 0; margin: 6px 0 0 12px; border: 0; border-radius: 50%; background: var(--text); }

/* The timeline: a stem, a dot where each turn arrives, its time, and a
   dotted line across to the bubble, faint so it stays behind the words. */
#timeline { position: absolute; inset: 0; pointer-events: none; }
#timeline .stem { position: absolute; width: 0; border-left: 1.5px solid var(--line); transform: translateX(-0.75px); }
#timeline .tie { position: absolute; height: 0; border-top: 1.5px dotted var(--muted); transform: translateY(-0.75px); }
#timeline .tick { position: absolute; width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; border-radius: 50%; background: var(--text); }
#timeline .when {
  position: absolute;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

/* A speaker's name once given: a small outlined tag. Filled while they speak. */
.tag {
  display: inline-block;
  max-width: 100%;
  padding: 2px 8px;
  border: 1.5px solid currentColor;
  border-radius: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: none;
}
.badge.filled, .tag.filled { background: var(--text); border-color: var(--text); color: var(--bg); }

/* Columns already say who is speaking. */
.board.columns .who { display: none; }

.who {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.who .badge { color: var(--text); width: 20px; height: 20px; font-size: 10px; }
.who .tag { color: var(--text); font-size: 10px; padding: 1px 6px; }

.say {
  margin: 0;
  font-size: var(--fs);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.say .more { color: var(--muted); }
/* Both languages: the English under the Japanese, a little smaller. */
.say.en { margin-top: 4px; font-size: calc(var(--fs) * 0.82); }

.cost { margin: 4px 0 0; white-space: pre-line; font-size: 14px; line-height: 1.6; }
.say.waiting { color: var(--muted); font-size: calc(var(--fs) * 0.88); }

.peek {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: calc(var(--fs) * 0.85);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.note {
  margin: 16px 0 8px;
  padding: 12px 16px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.empty {
  padding: 64px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.latest {
  position: fixed;
  left: 50%;
  bottom: calc(108px + env(safe-area-inset-bottom));
  z-index: 5;
  transform: translateX(-50%);
  padding: 0 12px 0 18px;
  gap: 4px;
}

.latest:active { transform: translateX(-50%) scale(0.98); }
.latest .icon { width: 20px; height: 20px; }

/* Bottom controls: language, the big mic button, settings. */

.controls {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

.controls { grid-template-columns: auto auto 1fr; }
.controls .segmented button { padding: 0 8px; white-space: nowrap; }
.controls-end { display: flex; justify-content: flex-end; }

.mic {
  --level: 0;
  width: 72px;
  height: 72px;
  min-height: 72px;
  padding: 0;
  border-radius: 50%;
  /* Loudness shows as a soft ring that grows with the voice. */
  box-shadow: 0 0 0 calc(var(--level) * 14px) var(--accent-soft);
  transition: box-shadow 0.1s linear;
}

.mic .icon { width: 30px; height: 30px; }
.mic .icon-stop { display: none; }
.mic[data-state="listening"] .icon-mic, .mic[data-state="stopping"] .icon-mic { display: none; }
.mic[data-state="listening"] .icon-stop, .mic[data-state="stopping"] .icon-stop { display: block; }
.mic[data-state="starting"], .mic[data-state="stopping"] { opacity: 0.5; }

/* A phone on its side: little height, so slimmer bars and a smaller mic. */
@media (orientation: landscape) and (max-height: 500px) {
  .topbar { min-height: 40px; }
  .controls { padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .mic { width: 48px; height: 48px; min-height: 48px; }
  .mic .icon { width: 22px; height: 22px; }
  .lane { min-height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  .status .dot { animation: none !important; }
  .mic { transition: none; }
}

/* E-ink (the Bigme B7 Pro BW): pure black on white, because greys dither
   and lose contrast; nothing animates, because every change is a visible
   refresh; slightly heavier, bigger type. app.js also batches live text to
   about one update a second and turns off the mic level ring. */

html[data-screen="eink"] {
  --bg: #fff;
  --surface-2: #fff;
  --text: #000;
  --muted: #000;
  --border: #000;
  --line: #000;
  --accent: #000;
  --accent-soft: transparent;
  --accent-text: #fff;
  --fs: 21px;
  color-scheme: light;
}

html[data-screen="eink"][data-size="s"] { --fs: 18px; }
html[data-screen="eink"][data-size="l"] { --fs: 25px; }
html[data-screen="eink"][data-size="xl"] { --fs: 30px; }

html[data-screen="eink"] *,
html[data-screen="eink"] *::before,
html[data-screen="eink"] *::after {
  animation: none !important;
  transition: none !important;
}

html[data-screen="eink"] body { -webkit-font-smoothing: auto; }
html[data-screen="eink"] .say { font-weight: 500; }
html[data-screen="eink"] .who, html[data-screen="eink"] .help { font-weight: 500; }
/* Words that may still change: underlined with dots instead of grey. */
html[data-screen="eink"] .say .more,
html[data-screen="eink"] .say.waiting {
  text-decoration: underline dotted;
  text-underline-offset: 5px;
  text-decoration-thickness: 2px;
}
html[data-screen="eink"] .turn.live { border-width: 3px; }
html[data-screen="eink"] #timeline .tie { border-top-color: #000; }
html[data-screen="eink"] .turn.new { border-color: #000; }
html[data-screen="eink"] .mic { box-shadow: none; }
html[data-screen="eink"] .mic[data-state="starting"],
html[data-screen="eink"] .mic[data-state="stopping"] { opacity: 1; background: #fff; color: #000; }
html[data-screen="eink"] dialog.sheet { border-width: 2.5px; }
html[data-screen="eink"] dialog.sheet::backdrop { background: transparent; }
html[data-screen="eink"] .status .dot { background: none; }
html[data-screen="eink"] .status[data-state="listening"] .dot { background: #000; }
/* The one grey left: placeholder text must not look like something typed. */
html[data-screen="eink"] input::placeholder, html[data-screen="eink"] textarea::placeholder { color: #707070; opacity: 1; }
