:root {
  --bg: #0e1116;
  --surface: #161b22;
  --border: #232a33;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --yes: #2ea043;
  --yes-hover: #3fb950;
  --no: #da3633;
  --no-hover: #f85149;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

html[data-theme="light"] {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #59636e;
  --accent: #0969da;
  --yes: #1a7f37;
  --yes-hover: #2da44e;
  --no: #cf222e;
  --no-hover: #d1242f;
  --shadow: 0 2px 12px rgba(20, 30, 50, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP",
    "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  /* Disable iOS double-tap zoom / overscroll bounce. */
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body {
  -webkit-tap-highlight-color: transparent;
}

button, .btn {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 10px;
}

.brand {
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: 15px;
  white-space: nowrap;
}

.meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.dot { opacity: 0.5; }

#theme-toggle {
  margin-left: 6px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  min-width: 32px;
  min-height: 32px;
}
#theme-toggle:hover { color: var(--text); border-color: var(--accent); }

#main {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 16px 180px; /* room for fixed action bar */
}

.screen.hidden { display: none; }
.hidden { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px 22px 22px;
  box-shadow: var(--shadow);
}

.card-meta {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.expression {
  font-size: clamp(26px, 6.5vw, 44px);
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  margin: 18px 0 22px;
  word-break: break-word;
  /* Allow user to long-press select if they really want, but no callout. */
  -webkit-touch-callout: none;
}

.reveal {
  border-top: 1px solid var(--border);
  margin-top: 18px;
  padding-top: 18px;
  animation: fadein 120ms ease-out;
}
@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.japanese {
  text-align: center;
  font-size: clamp(20px, 4.5vw, 26px);
  color: var(--accent);
  margin-bottom: 6px;
}

.reading {
  text-align: center;
  font-size: clamp(14px, 3.5vw, 17px);
  color: var(--muted);
  margin: 0 0 14px;
  padding: 6px 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  letter-spacing: 0.02em;
}
.reading::before {
  content: "🔊 ";
  opacity: 0.7;
}

.example-controls {
  display: flex;
  justify-content: flex-end;
  margin: 4px 0 8px;
}

.examples {
  list-style: none;
  padding: 0;
  margin: 0;
}
.examples li {
  padding: 10px 12px;
  margin: 6px 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: clamp(14px, 3.5vw, 15px);
  line-height: 1.5;
}
.examples li .ja {
  display: none;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  color: var(--muted);
  font-size: clamp(13px, 3vw, 14px);
}
.examples.show-ja li .ja { display: block; }

/* ----- Bottom action bar (fixed; primary mobile interaction) ----- */
.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.18);
}

.btn {
  flex: 1;
  min-height: 64px;
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform 0.06s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }

.btn-yes {
  background: var(--yes);
  color: white;
  border-color: var(--yes);
}
.btn-yes:hover { background: var(--yes-hover); border-color: var(--yes-hover); }

.btn-no {
  background: var(--no);
  color: white;
  border-color: var(--no);
}
.btn-no:hover { background: var(--no-hover); border-color: var(--no-hover); }

.btn-secondary {
  flex: 0 0 auto;
  min-height: 40px;
  font-size: 14px;
  padding: 8px 14px;
}

.btn .lbl { font-size: 17px; }

.kbd {
  display: inline-block;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 4px;
  padding: 1px 8px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  line-height: 1.4;
}
/* Hide the keyboard hint on touch-only devices to keep the button label
   clean — it adds clutter when there's no physical keyboard. */
@media (pointer: coarse) {
  .kbd { display: none; }
}

.hint {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 18px 0 0;
}

/* ----- End / error screens ----- */
#screen-end h1 { margin: 4px 0 6px; font-size: clamp(22px, 5vw, 28px); }
#screen-end h2 {
  font-size: 15px;
  color: var(--muted);
  margin-top: 22px;
  margin-bottom: 8px;
}
#end-summary {
  font-size: 17px;
  color: var(--accent);
}
.muted-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}
#end-list-wrong,
#end-list-correct {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 12px 12px 32px;
}
#end-list-wrong:empty::after,
#end-list-correct:empty::after {
  content: "（なし）";
  color: var(--muted);
  font-size: 14px;
  display: block;
  margin-left: -20px;
}
#end-list-wrong li,
#end-list-correct li { padding: 4px 0; }

.end-actions {
  display: flex;
  gap: 12px;
  margin: 18px 0 4px;
}
.end-actions .btn { flex: 1; min-height: 52px; }

.end-instructions {
  margin: 20px 0 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
#end-prompt {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 8px 0;
  font-size: 15px;
  white-space: pre-wrap;
}

#screen-error pre {
  background: var(--surface);
  border: 1px solid var(--no);
  border-radius: 8px;
  padding: 14px;
  color: var(--no);
  overflow-x: auto;
}

/* ----- Swipe affordance (transient color flash) ----- */
.swipe-yes { box-shadow: inset 0 0 0 4px var(--yes); transition: box-shadow 80ms; }
.swipe-no  { box-shadow: inset 0 0 0 4px var(--no);  transition: box-shadow 80ms; }

/* ----- Compact / narrow tweaks ----- */
@media (max-width: 480px) {
  .topbar { padding: 8px 10px; }
  .brand { font-size: 13px; }
  .meta { font-size: 11px; gap: 4px; }
  #main { padding: 16px 12px 180px; }
  .card { padding: 18px 16px; border-radius: 12px; }
  .btn { min-height: 60px; font-size: 16px; }
}

@media (min-width: 720px) {
  /* On desktop, keep the action bar visible but limit its width and center. */
  .action-bar {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(720px, calc(100% - 32px));
    border-radius: 14px 14px 0 0;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
