/*
 * The phone screen.
 *
 * Dark by default because the app is used in the same moments the glasses are — outdoors,
 * quickly, one-handed — and because the lens preview is white on black and a page that
 * frames it in white makes the preview look like a photograph of a different device.
 *
 * The controls are large. Not for style: the wearer is holding a phone in one hand while
 * talking to a stranger, and every control on this page has a version that is a tap on the
 * glasses precisely because looking down at a phone is the thing being avoided.
 */

:root {
  --bg: #0b0d10;
  --card: #14181d;
  --line: #232a32;
  --text: #e9eef4;
  --dim: #9aa7b4;
  --accent: #4da3ff;
  --accent-ink: #04121f;
  --warn: #ffb454;
  --bad: #ff6b6b;
  --radius: 14px;

  /* The lens, at the pixel size the glasses actually grant. See bridge.js. */
  --lens-w: 864px;
  --lens-h: 432px;
  /*
   * A half-width cell is 864/56 ≈ 15.43px and a card line is 43px (both measured on the
   * device). The font size below is the one that puts a monospace advance on that pitch;
   * it is an approximation of the lens, not the lens. The authority on whether a line fits
   * is `wrap.js`, which counts cells — this preview only has to look like the answer.
   */
  --lens-font: 25.5px;
  --lens-line: 43px;
  --row-font: 17px;
  --row-line: 28.8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-top, 0px));
  background: rgba(11, 13, 16, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.bar h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.04em;
}

.status {
  margin: 0;
  font-size: 12px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.status[data-state='ok'] {
  color: var(--accent);
}

.status[data-state='mock'] {
  color: var(--warn);
}

main {
  padding: 12px 16px 24px;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card,
details.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.card h2,
details.card summary {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--dim);
  letter-spacing: 0.04em;
}

details.card summary {
  cursor: pointer;
  margin: 0;
}

details.card[open] summary {
  margin-bottom: 10px;
}

.hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--dim);
}

/* 言語モード ------------------------------------------------------------- */

.modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.mode {
  padding: 10px 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--dim);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.mode[aria-checked='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

/* 聞くボタン ------------------------------------------------------------- */

.listen {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 18px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.listen-label {
  font-size: 20px;
  font-weight: 700;
}

.listen-note {
  font-size: 12px;
  color: var(--dim);
}

.listen[data-on='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.listen[data-on='true'] .listen-note {
  color: var(--accent-ink);
  opacity: 0.75;
}

.meter {
  height: 6px;
  margin-top: 10px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 80ms linear;
}

.line {
  margin: 8px 0 0;
  min-height: 1.6em;
  font-size: 14px;
  color: var(--dim);
}

/* レンズのプレビュー ------------------------------------------------------ */

/*
 * Drawn at the glasses' own pixel size and then scaled down as a whole, rather than laid
 * out at phone size. Anything else is a picture of a different display: the wrapping, the
 * row heights and the number of lines that fit are the things being previewed, and they
 * only mean something at 864×432.
 */
.lens-frame {
  width: 100%;
  aspect-ratio: 2 / 1;
  overflow: hidden;
  border-radius: 10px;
  background: #000;
  border: 1px solid var(--line);
  container-type: inline-size;
}

.lens {
  position: relative;
  width: var(--lens-w);
  height: var(--lens-h);
  transform-origin: 0 0;
  /* 864px wide, scaled to whatever the card is. Set from main.js on resize. */
  transform: scale(var(--lens-scale, 0.4));
  color: #fff;
  font-family: ui-monospace, 'SF Mono', 'Menlo', 'Consolas', 'Noto Sans Mono CJK JP', monospace;
}

.lens-card {
  position: absolute;
  inset: 0;
  padding: 0;
  white-space: pre;
  font-size: var(--lens-font);
  line-height: var(--lens-line);
}

.lens-rows {
  position: absolute;
  inset: 0;
}

.lens-row {
  position: absolute;
  left: 0;
  width: 100%;
  padding: 4px;
  white-space: pre;
  font-size: var(--row-font);
  line-height: var(--row-line);
  border: 2px solid transparent;
  border-radius: 8px;
}

.lens-row[data-selected='true'] {
  border-color: #fff;
}

.pad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 12px;
}

.pad button,
.secondary,
.row button,
.samples button {
  padding: 12px 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.secondary {
  width: 100%;
  margin-top: 10px;
  color: var(--dim);
}

/* 入力 ------------------------------------------------------------------- */

.row {
  display: flex;
  gap: 8px;
}

.row input {
  flex: 1;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0e1216;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* under 16px, iOS zooms the page on focus and never zooms back */
}

.samples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.samples button {
  padding: 8px 10px;
  font-size: 13px;
  color: var(--dim);
}

/* 会話 ------------------------------------------------------------------- */

.turns {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.turns:empty::after {
  content: 'まだ何も聞いていません。';
  color: var(--dim);
  font-size: 13px;
}

.turn {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0e1216;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: inherit;
  font: inherit;
}

.turn[data-speaker='user'] {
  border-left: 3px solid var(--accent);
}

.turn-meta {
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0.06em;
}

.turn-main {
  font-size: 15px;
}

.turn-sub {
  font-size: 13px;
  color: var(--dim);
}

/* 記録 ------------------------------------------------------------------- */

.records {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.records:empty::after {
  content: 'まだ記録がありません。';
  color: var(--dim);
  font-size: 13px;
}

.record {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0e1216;
  padding: 10px 12px;
}

.record summary {
  cursor: pointer;
  font-size: 14px;
  margin: 0;
  color: var(--text);
}

.record-title {
  display: block;
  color: var(--text);
  font-weight: 600;
}

.record-when {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0.04em;
}

.record-lines {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.record-line {
  display: flex;
  gap: 8px;
  font-size: 14px;
}

.record-line[data-speaker='user'] {
  /* The wearer's own turns, set off so the two voices are tellable apart at a glance. */
  padding-left: 8px;
  border-left: 2px solid var(--accent);
}

.record-clock {
  flex: none;
  width: 3.2em;
  color: var(--dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding-top: 3px;
}

.record-foreign {
  color: var(--dim);
  font-size: 13px;
}

.record-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.record-actions button {
  flex: 1;
  padding: 8px;
  font-size: 13px;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  font-family: inherit;
  cursor: pointer;
}

.export {
  width: 100%;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e1216;
  color: var(--text);
  font-family: ui-monospace, monospace;
  font-size: 12px;
  resize: vertical;
}

/* 設定 ------------------------------------------------------------------- */

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}

.field span {
  font-size: 14px;
}

.field select,
.fields input {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e1216;
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 14px;
}

.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--dim);
}

.phrases {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}

.phrases b {
  font-weight: 600;
}

.phrases span {
  display: block;
  color: var(--dim);
  font-size: 13px;
}

/* 診断 ------------------------------------------------------------------- */

.measures {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.measures dt {
  color: var(--dim);
}

.measures dd {
  margin: 0;
  word-break: break-all;
}

.log {
  margin: 10px 0 0;
  padding: 10px;
  max-height: 240px;
  overflow: auto;
  background: #0e1216;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--dim);
}

.log .error {
  color: var(--bad);
}

.log .warn {
  color: var(--warn);
}

.build {
  margin: 0;
  text-align: center;
  font-size: 11px;
  color: var(--dim);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --line: #dde3ea;
    --text: #12171d;
    --dim: #5d6b7a;
    --accent: #0b62d0;
    --accent-ink: #ffffff;
  }

  .bar {
    background: rgba(244, 246, 248, 0.94);
  }

  .row input,
  .field select,
  .fields input,
  .turn,
  .log {
    background: #f7f9fb;
  }
}
