:root {
  --bg: #f7f5ef;
  --surface: #ffffff;
  --ink: #1d2433;
  --muted: #6b7280;
  --line: #e5e1d6;
  --blue: #2f6fdb;
  --green: #1f9d55;
  --green-soft: #d8f3e3;
  --red: #d64545;
  --red-soft: #fbe0e0;
  --amber: #c98a00;
  --amber-soft: #fdf0c9;
  --grey-soft: #eceae4;
  --word-font: "Andika", "Century Gothic", "Avenir Next", "Helvetica Neue", sans-serif;
  --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui-font);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

#app {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
  max-width: 1100px;
  margin: 0 auto;
}
.view { display: none; min-height: 100dvh; flex-direction: column; padding-bottom: 16px; }
.view.active { display: flex; }
.hidden { display: none !important; }

.topbar {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
}
.topbar h1 { margin: 0; font-size: 1.5rem; text-align: center; grid-column: 2; }
.topbar .icon-btn:last-child:not(:first-child) { grid-column: 3; }
.topbar.slim { grid-template-columns: 48px 1fr auto; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 1.3rem; line-height: 1;
}

/* Home */
.home-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 8px 0 20px;
}
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 8px; text-align: center;
}
.stat b { display: block; font-size: 2rem; }
.stat span { color: var(--muted); font-size: .9rem; }
.stat.known b { color: var(--green); }
.stat.learning b { color: var(--amber); }
.stat.untested b { color: var(--muted); }

.home-actions { display: flex; flex-direction: column; gap: 14px; max-width: 520px; width: 100%; margin: 0 auto; }
.big-btn {
  min-height: 72px; border-radius: 18px; border: 1px solid var(--line);
  background: var(--surface); font-size: 1.35rem; font-weight: 600;
}
.big-btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.big-btn:active, .small-btn:active, .answer:active { transform: scale(.98); }
.hint { color: var(--muted); text-align: center; font-size: .95rem; margin: 16px 0; }

/* Card */
.progress-bar { height: 8px; background: var(--grey-soft); border-radius: 4px; overflow: hidden; }
#bar-fill { height: 100%; width: 0; background: var(--blue); transition: width .2s; }
.counter { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .9rem; min-width: 56px; text-align: right; }

.card {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 28px;
  margin: 8px 0 16px; min-height: 40dvh;
  touch-action: pan-y;
  transition: transform .15s ease-out, opacity .15s;
}
.card.swipe-left { transform: translateX(-40px) rotate(-3deg); opacity: .4; }
.card.swipe-right { transform: translateX(40px) rotate(3deg); opacity: .4; }
.word {
  font-family: var(--word-font);
  font-size: clamp(64px, 17vw, 200px);
  line-height: 1.1; padding: 0 16px; text-align: center;
  overflow-wrap: anywhere;
}
.word.long { font-size: clamp(52px, 13vw, 170px); }
.tag {
  position: absolute; top: 14px; right: 18px;
  font-size: .75rem; color: var(--muted); letter-spacing: .05em; text-transform: uppercase;
}

.answer-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.answer {
  min-height: 96px; border-radius: 22px; border: 0;
  font-size: 1.6rem; font-weight: 700; color: #fff;
}
.answer.miss { background: var(--red); }
.answer.got { background: var(--green); }
.hear {
  align-self: flex-end; margin-top: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 8px 14px; font-size: .9rem;
}

/* Coaching overlay */
.coach, .sheet {
  position: fixed; inset: 0; background: rgba(20, 24, 33, .45);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10;
}
.coach-box, .sheet-box {
  background: var(--surface); border-radius: 24px; padding: 24px;
  width: 100%; max-width: 440px; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.coach-word, .sheet-word { font-family: var(--word-font); font-size: 3.2rem; margin-bottom: 8px; }
.coach-steps {
  text-align: left; margin: 0 auto 20px; padding-left: 1.6em; font-size: 1.25rem; line-height: 1.8;
  display: inline-block;
}
.coach-actions, .sheet-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; }
.small-btn {
  min-height: 48px; padding: 0 18px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); font-size: 1rem; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}
.small-btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.small-btn.known { background: var(--green-soft); border-color: var(--green); }
.small-btn.learning { background: var(--amber-soft); border-color: var(--amber); }
.small-btn.untested { background: var(--grey-soft); }

/* Toast + confetti */
.toast {
  position: fixed; left: 50%; top: 18%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 14px 22px; border-radius: 999px;
  font-size: 1.2rem; font-weight: 600; z-index: 20; animation: pop .9s ease-out forwards;
}
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(.9); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 15; }
.confetti i {
  position: absolute; top: 40%; left: 50%; width: 10px; height: 14px; border-radius: 2px;
  animation: burst .9s ease-out forwards;
}
@keyframes burst {
  to { transform: translate(var(--dx), var(--dy)) rotate(var(--r)); opacity: 0; }
}

/* Summary */
.summary {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 20px; margin: 8px auto 20px; max-width: 520px; width: 100%; font-size: 1.15rem;
}
.summary .line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.summary .line:last-of-type { border-bottom: 0; }
.summary .words { font-family: var(--word-font); color: var(--green); margin-top: 8px; }

/* Progress */
.legend { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.legend-note { color: var(--muted); font-size: .85rem; margin-left: auto; }
.chip { padding: 4px 10px; border-radius: 999px; font-size: .85rem; }
.chip.known, .cell.known { background: var(--green-soft); }
.chip.learning, .cell.learning { background: var(--amber-soft); }
.chip.untested, .cell.untested { background: var(--grey-soft); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.cell {
  border: 0; border-radius: 12px; padding: 12px 4px; min-height: 52px;
  font-family: var(--word-font); font-size: 1.15rem;
}
.cell.learning { box-shadow: inset 0 0 0 2px var(--amber); }
.cell .dots { display: block; font-size: .7rem; color: var(--amber); letter-spacing: 2px; font-family: var(--ui-font); }

/* Settings */
.settings { max-width: 620px; width: 100%; margin: 0 auto; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; margin-bottom: 12px;
}
.row select { min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 1.05rem; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; }
.row.danger .small-btn { color: var(--red); border-color: var(--red); }

@media (max-width: 520px) {
  .answer { min-height: 80px; font-size: 1.35rem; }
  .stat b { font-size: 1.6rem; }
  .legend-note { margin-left: 0; width: 100%; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .card { min-height: 0; }
  .answer { min-height: 64px; }
}
