/* ============ TOKENS (taste-skill app-screen rules: neutral chrome, colour only on the Korean) ============ */
:root {
  --ground: #f5f5f2;
  --surface: #ffffff;
  --raised: #f0f0ec;
  --border: #e6e6e1;
  --rule: #efefea;
  --control: #d4d4cf;
  --text: #111111;
  --muted: #5f6368;
  --primary: #111111;        /* near-black fill, white label */
  --accent: #0b4fa8;         /* the one hue: Korean text and the saved star */
  --notice-bg: #fffbeb;
  --notice-border: #fde68a;
  --notice-ink: #92400e;
  --negative: #c4242a;
  --radius-card: 16px;
  --font: "IBM Plex Sans KR", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --pad: 16px;
}

/* ============ BASE ============ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.45; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.topbar, .screen, .credit { max-width: 640px; margin: 0 auto; }

/* ============ TOP BAR ============ */
.topbar {
  position: sticky; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between;
  min-height: 56px; padding: env(safe-area-inset-top) var(--pad) 0; background: var(--ground);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 700; font-size: 18px; }
.mark { width: 30px; height: 30px; }
.mark path { fill: var(--accent); }
.mark text { fill: #fff; font: 700 11px var(--font); }
.toggle {
  min-height: 44px; padding: 0 16px; border: 1px solid var(--control); border-radius: 999px;
  background: var(--surface); font-size: 14px; font-weight: 600;
}
.toggle[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.top-btns { display: flex; gap: 6px; }
.top-btns a.btn { display: inline-flex; align-items: center; text-decoration: none; }

/* ============ TITLE ROW ============ */
.screen { padding: 4px var(--pad) 0; }
.title-row { padding: 8px 0 12px; }
h1 { margin: 0; font-size: 24px; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
.finding { margin-top: 2px; color: var(--muted); font-size: 14px; }
.notice { margin: 0 0 12px; padding: 10px 12px; border: 1px solid var(--notice-border); border-radius: 10px; background: var(--notice-bg); color: var(--notice-ink); font-size: 13px; }

/* ============ FIND FIELD ============ */
.find { position: relative; }
.find input {
  width: 100%; min-height: 48px; padding: 0 48px 0 18px; border: 1px solid var(--control); border-radius: 999px;
  background: var(--surface); font-size: 16px; /* 16px stops iPhone zooming in */
}
.find input::placeholder { color: var(--muted); }
.find input::-webkit-search-cancel-button { display: none; }
.clear { position: absolute; right: 2px; top: 2px; width: 44px; height: 44px; border: 0; background: none; color: var(--muted); font-size: 22px; }

/* ============ TOPIC CHIPS: one row that scrolls inside itself ============ */
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 12px calc(-1 * var(--pad)) 12px; padding: 0 var(--pad); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none; min-height: 40px; padding: 0 14px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); font-size: 14px; font-weight: 500;
}
.chips button .n { margin-left: 6px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chips button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.chips button[aria-pressed="true"] .n { color: #c9c9c9; }

/* ============ THE LIST: one card, rows split by rules ============ */
.list { list-style: none; margin: 0 0 24px; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); overflow: hidden; }
.list:empty { display: none; }
.row { display: flex; align-items: stretch; border-top: 1px solid var(--rule); }
.row:first-child { border-top: 0; }
.say { flex: 1; min-width: 0; padding: 14px 4px 14px 16px; border: 0; background: none; text-align: left; }
.say .en { display: block; font-size: 16px; font-weight: 600; line-height: 1.3; }
.say .ko { display: block; margin-top: 4px; color: var(--accent); font-size: 21px; font-weight: 600; line-height: 1.3; word-break: keep-all; overflow-wrap: anywhere; }
.say .rom { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; }
.row.is-playing { background: var(--raised); }
.acts { display: flex; align-items: center; padding-right: 6px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.icon-btn[aria-pressed="true"] svg { fill: currentColor; }
.text-btn { min-height: 44px; padding: 0 10px; border: 0; background: none; color: var(--text); font-size: 14px; font-weight: 600; }

/* The "translate your own" row and its states */
.row--own .say .en { font-weight: 500; }
.row--own .say .en strong { font-weight: 700; }
.row--own .label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 2px; }
.bar { display: block; width: 62%; height: 21px; margin-top: 6px; border-radius: 4px; background: var(--raised); }
.err { display: block; margin-top: 4px; color: var(--text); font-size: 14px; }
.err::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: var(--negative); }
.empty { padding: 16px; color: var(--muted); font-size: 14px; }

/* ============ NOW PLAYING: floats, so it may carry a shadow ============ */
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; display: flex; flex-direction: column; gap: 10px;
  max-width: 640px; margin: 0 auto; padding: 12px var(--pad) max(12px, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
}
.player[hidden] { display: none; }
.player-top { display: flex; align-items: center; gap: 12px; }
.player-text { flex: 1; min-width: 0; }
/* Suggested next: four big tiles, English over Korean, one tap plays */
.next { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.next[hidden] { display: none; }
.next-lbl { grid-column: 1 / -1; color: var(--muted); font-size: 13px; font-weight: 600; }

/* A say-it tile, shared by the player and Talk mode */
.tile {
  display: flex; flex-direction: column; justify-content: center; min-height: 64px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--raised); text-align: left;
}
.tile .en { font-size: 14px; font-weight: 600; line-height: 1.25; }
.tile .ko { margin-top: 2px; color: var(--accent); font-size: 15px; font-weight: 600; line-height: 1.25; word-break: keep-all; }
.tile:active, .say:active, .reply:active { background: var(--active, #e4e4df); }
.player-ko { color: var(--accent); font-size: 20px; font-weight: 600; line-height: 1.25; word-break: keep-all; overflow-wrap: anywhere; }
.player-en { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-btns { display: flex; gap: 8px; }
body.has-player .screen { padding-bottom: 260px; }
.btn { min-height: 44px; padding: 0 16px; border: 1px solid var(--control); border-radius: 999px; background: var(--surface); font-size: 15px; font-weight: 600; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ============ SHOW ============ */
.show {
  position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; justify-content: center; gap: 20px;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom)); background: var(--surface);
}
.show[hidden] { display: none; }
.show-close { position: absolute; top: max(16px, env(safe-area-inset-top)); right: 16px; }
.show-ko { color: var(--text); font-size: clamp(40px, 11vw, 96px); font-weight: 700; line-height: 1.2; word-break: keep-all; overflow-wrap: anywhere; }
.show-en { color: var(--muted); font-size: 18px; }
.show-play { align-self: flex-start; min-height: 52px; padding: 0 24px; font-size: 17px; }

/* ============ CREDIT ============ */
.credit { padding: 0 var(--pad) 24px; color: var(--muted); font-size: 12px; }
body.has-player .credit { padding-bottom: 270px; }

/* ============ TALK MODE ============ */
.talk { position: fixed; inset: 0; z-index: 8; display: flex; flex-direction: column; height: 100dvh; background: var(--ground); }
.talk[hidden] { display: none; }
body.in-talk { overflow: hidden; }
.side { flex: 1 1 0; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 14px var(--pad); }
.side--them { background: #eef3fa; } /* one tone step: their half reads apart from mine */
/* My half takes only the room it needs, so all of their replies fit without scrolling */
.side--me { flex: 0 0 auto; max-height: 62%; background: var(--surface); border-top: 1px solid var(--border); }
/* Whose turn: the side that types sits at the bottom, upright; the other faces the person across */
.talk[data-turn="me"] .side--them, .talk[data-turn="them"] .side--me { order: 0; transform: rotate(180deg); }
.talk[data-turn="me"] .side--me, .talk[data-turn="them"] .side--them { order: 1; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
.talk[data-turn="them"] .side--me { border-top: 0; border-bottom: 1px solid var(--border); }
.side-label { color: var(--muted); font-size: 13px; font-weight: 600; }

/* Their half: what I said, big; their one-tap replies */
.said { display: flex; align-items: center; gap: 12px; min-height: 64px; }
.said-ko { flex: 1; font-size: clamp(26px, 7vw, 40px); font-weight: 700; line-height: 1.2; word-break: keep-all; overflow-wrap: anywhere; }
.said-ko.is-hint { color: var(--muted); font-size: 16px; font-weight: 500; }
.replies { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.reply { min-height: 44px; padding: 4px 6px; border: 1px solid #cfdbec; border-radius: 12px; background: var(--surface); font-size: 14px; font-weight: 600; line-height: 1.2; word-break: keep-all; }
.btn--wide { width: 100%; }
.composer { display: flex; gap: 8px; }
.composer input { flex: 1; min-width: 0; min-height: 48px; padding: 0 16px; border: 1px solid var(--control); border-radius: 999px; background: var(--surface); font-size: 16px; }
.composer input::-webkit-search-cancel-button { display: none; }
.talk-note { min-height: 0; color: var(--muted); font-size: 13px; }
.talk-note:empty { display: none; }
/* Only the side whose turn it is can type; while they type, my half shows the button that takes the turn back */
.talk[data-turn="me"] #t-form, .talk[data-turn="them"] #t-type,
.talk[data-turn="them"] #m-form, .talk[data-turn="them"] #m-tiles, .talk[data-turn="them"] .me-head .toggle { display: none; }
.turn-me { display: none; }
.talk[data-turn="them"] .turn-me { display: block; }

/* My half: what they said, big; four tiles; search or type */
.me-head { display: flex; align-items: center; gap: 8px; }
.me-head .side-label { margin-right: auto; }
.heard { min-height: 56px; }
.heard .en { font-size: clamp(22px, 6vw, 32px); font-weight: 700; line-height: 1.2; }
.heard .ko { margin-top: 2px; color: var(--muted); font-size: 14px; }
.heard .hint { color: var(--muted); font-size: 15px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Short phones (iPhone SE and similar): tighter Talk mode so both halves still fit */
@media (max-height: 740px) {
  .side { gap: 6px; padding-top: 10px; padding-bottom: 10px; }
  .me-head .btn, .me-head .toggle { min-height: 40px; }
  .heard { min-height: 0; }
  .heard .en { font-size: 20px; }
  .talk .tile { min-height: 50px; padding: 6px 10px; }
  .talk .tile .en { font-size: 13px; }
  .talk .tile .ko { font-size: 14px; }
  .said { min-height: 0; }
  .said-ko { font-size: 24px; }
  .said-ko.is-hint { font-size: 14px; }
  .reply { min-height: 38px; font-size: 13px; }
  .composer input, .talk .btn--wide { min-height: 44px; }
}

@media (prefers-reduced-motion: no-preference) {
  .row, .chips button, .toggle, .btn { transition: background-color 150ms ease, color 150ms ease; }
}
