:root {
  color-scheme: light;
  --bg: #f3f4f7;
  --surface: #ffffff;
  --ink: #17191f;
  --muted: #717681;
  --line: #e2e4e9;
  --accent: #2c57d6;
  --known: #15966d;
  --unknown: #df5f5f;
  --shadow: 0 24px 70px rgba(28, 34, 52, .13), 0 3px 12px rgba(28, 34, 52, .06);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 50% -20%, rgba(44, 87, 214, .11), transparent 42%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { font: inherit; }

.app-shell {
  width: min(100%, 760px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 22px max(58px, calc(env(safe-area-inset-bottom) + 46px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.top-stack { min-width: 0; }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .14em;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 5vw, 38px);
  letter-spacing: 0;
}

.header-actions { display: flex; gap: 4px; }

.text-button {
  border: 0;
  border-radius: 10px;
  padding: 9px 11px;
  background: transparent;
  color: var(--accent);
  font-weight: 650;
  cursor: pointer;
}

.text-button:hover { background: rgba(44, 87, 214, .07); }
.text-button.muted { color: var(--muted); }

.deck-panel {
  margin-top: clamp(12px, 2.2dvh, 22px);
  display: flex;
  align-items: center;
  gap: 14px;
}

.deck-switch {
  flex: 0 0 auto;
  padding: 4px;
  display: inline-flex;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, .7);
  box-shadow: 0 4px 16px rgba(28, 34, 52, .04);
}

.deck-button {
  min-height: 34px;
  padding: 7px 13px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, box-shadow .16s ease;
}

.deck-button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 2px 9px rgba(28, 34, 52, .09);
}

.deck-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.voice-loader {
  margin-top: clamp(10px, 2dvh, 22px);
  padding: 13px 15px 12px;
  overflow: hidden;
  border: 1px solid rgba(44, 87, 214, .14);
  border-radius: 14px;
  background: rgba(255, 255, 255, .76);
  transition: opacity .24s ease, transform .24s ease, margin .24s ease, padding .24s ease, max-height .24s ease;
  max-height: 96px;
}

.voice-loader[hidden] { display: none; }

.voice-loader.is-leaving {
  margin-top: 0;
  padding-top: 0;
  padding-bottom: 0;
  max-height: 0;
  border-color: transparent;
  opacity: 0;
  transform: translateY(-6px);
}

.voice-loader-copy {
  display: flex;
  align-items: center;
  gap: 11px;
}

.voice-loader-icon {
  flex: 0 0 auto;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 9px;
  background: rgba(44, 87, 214, .09);
  color: var(--accent);
}

.voice-loader-icon svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.voice-loader-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.voice-loader-text strong { font-size: 13px; }
.voice-loader-text small { color: var(--muted); font-size: 11px; }

.voice-loader-percent {
  margin-left: auto;
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.voice-loader-track {
  height: 3px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 99px;
  background: #e2e6f1;
}

.voice-loader-fill {
  width: 8%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width .18s ease;
}

.voice-loader:not(.has-progress) .voice-loader-fill {
  width: 34%;
  animation: voice-loading 1.25s ease-in-out infinite;
}

.voice-loader.is-ready { border-color: rgba(21, 150, 109, .2); }
.voice-loader.is-ready .voice-loader-icon { background: rgba(21, 150, 109, .1); color: var(--known); }
.voice-loader.is-ready .voice-loader-percent { color: var(--known); }
.voice-loader.is-ready .voice-loader-fill { width: 100%; background: var(--known); animation: none; }

.voice-loader.is-fallback { border-color: var(--line); }
.voice-loader.is-fallback .voice-loader-icon { background: var(--bg); color: var(--muted); }
.voice-loader.is-fallback .voice-loader-percent { color: var(--muted); }

@keyframes voice-loading {
  from { transform: translateX(-115%); }
  to { transform: translateX(310%); }
}

.progress-panel { margin-top: clamp(12px, 2.5dvh, 28px); }

.progress-copy {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.progress-track {
  height: 5px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 99px;
  background: #dedfe4;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width .28s ease;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, .66);
  backdrop-filter: blur(12px);
}

.stats div {
  padding: 13px 16px;
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.stats div + div { border-left: 1px solid var(--line); }
.stats strong { font-size: 18px; }
.stats span { color: var(--muted); font-size: 12px; }

.study-area {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3dvh, 30px) 0 clamp(10px, 2.2dvh, 24px);
}

.card-wrap {
  position: relative;
  width: min(100%, 610px);
  height: 100%;
  max-height: 440px;
  min-height: 0;
  border-radius: 58px;
}

.card {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  cursor: grab;
  perspective: 1200px;
  touch-action: pan-y;
  user-select: none;
  outline: none;
  will-change: transform;
}

.card:active { cursor: grabbing; }
.card:focus-visible { box-shadow: 0 0 0 4px rgba(44, 87, 214, .2); }

.card-inner {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.2,.72,.2,1);
}

.card.is-flipped .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 38px;
  overflow: hidden;
  border: 1px solid rgba(28, 34, 52, .055);
  border-radius: inherit;
  background: linear-gradient(145deg, #ffffff 0%, #fdfdff 58%, #f8f9fd 100%);
  box-shadow: 0 30px 78px rgba(28, 34, 52, .11), 0 4px 16px rgba(28, 34, 52, .045), inset 0 1px 0 rgba(255, 255, 255, .9);
  backface-visibility: hidden;
}

.card-back { transform: rotateY(180deg); }

.pronounce-button {
  position: absolute;
  z-index: 5;
  top: 20px;
  right: 20px;
  min-height: 42px;
  padding: 8px 11px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(44, 87, 214, .14);
  border-radius: 999px;
  background: rgba(255, 255, 255, .86);
  color: #515867;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 5px 18px rgba(28, 34, 52, .08);
  backdrop-filter: blur(12px);
  transition: transform .16s ease, background .16s ease, color .16s ease;
}

.pronounce-button:hover { transform: translateY(-1px); background: #fff; color: var(--accent); }
.pronounce-button.is-speaking { color: var(--accent); background: #f4f7ff; }
.pronounce-button:disabled { cursor: not-allowed; opacity: .45; }
.pronounce-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; }
.pronounce-button kbd { min-width: 25px; min-height: 22px; padding: 3px 6px; font-size: 10px; }

.card-kicker {
  margin-bottom: 20px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .15em;
}

.card h2 {
  margin: 0;
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(36px, 8vw, 62px);
  font-weight: 500;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.meaning {
  max-width: 520px;
  margin: 0;
  text-align: center;
  font-size: clamp(22px, 4.2vw, 32px);
  font-weight: 650;
  line-height: 1.55;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.meaning-note {
  width: min(100%, 500px);
  margin-top: 22px;
  padding: 15px 18px;
  border: 1px solid rgba(44, 87, 214, .12);
  border-radius: 18px;
  background: rgba(44, 87, 214, .055);
  text-align: left;
}

.meaning-note-title {
  display: block;
  margin-bottom: 7px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 780;
  letter-spacing: .08em;
}

.meaning-note p {
  margin: 0;
  color: #4f5562;
  font-size: clamp(14px, 2.5vw, 17px);
  font-weight: 580;
  line-height: 1.55;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.tap-hint {
  position: absolute;
  bottom: 23px;
  margin: 0;
  color: #a0a4ad;
  font-size: 12px;
}

.swipe-label {
  position: absolute;
  z-index: 3;
  top: 64px;
  padding: 7px 12px;
  border: 2px solid currentColor;
  border-radius: 9px;
  background: rgba(255, 255, 255, .9);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .06em;
  opacity: 0;
  pointer-events: none;
}

.unknown-label { left: 10%; color: var(--unknown); transform: rotate(-8deg); }
.known-label { right: 10%; color: var(--known); transform: rotate(8deg); }

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.choice-button {
  min-height: 66px;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(28, 34, 52, .04);
  transition: transform .16s ease, border-color .16s ease;
}

.choice-button:hover { transform: translateY(-2px); }
.choice-button.unknown:hover { border-color: rgba(223, 95, 95, .45); }
.choice-button.known:hover { border-color: rgba(21, 150, 109, .45); }
.choice-button > span:not(.key) { display: grid; text-align: left; }
.choice-button.known > span:not(.key) { text-align: right; }
.choice-button strong { font-size: 15px; }
.choice-button small { margin-top: 3px; color: var(--muted); font-size: 11px; }

.key {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
}

.help-button {
  position: fixed;
  z-index: 20;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(13px, env(safe-area-inset-bottom));
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid #d5d8df;
  border-radius: 50%;
  background: rgba(255, 255, 255, .9);
  color: var(--muted);
  font-size: 16px;
  font-weight: 760;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(28, 34, 52, .08);
  backdrop-filter: blur(12px);
}

.help-button:hover,
.help-button:focus-visible { color: var(--accent); border-color: rgba(44, 87, 214, .35); }

.help-dialog {
  width: min(calc(100% - 32px), 390px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.help-dialog::backdrop { background: rgba(23, 25, 31, .28); backdrop-filter: blur(3px); }

.help-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.help-dialog h2 { margin: 0; font-size: 19px; }

.dialog-close {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: var(--bg);
  color: var(--muted);
  font-size: 23px;
  line-height: 1;
  cursor: pointer;
}

.shortcut-list { margin-top: 20px; display: grid; gap: 10px; }
.shortcut-list div { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.shortcut-list span { color: var(--muted); font-size: 13px; }

kbd {
  min-width: 31px;
  min-height: 27px;
  padding: 4px 8px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #d8dae0;
  border-bottom-width: 2px;
  border-radius: 8px;
  background: #fff;
  color: #444955;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 2px 5px rgba(28, 34, 52, .05);
}

.complete-panel {
  width: min(100%, 560px);
  padding: 48px 30px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.complete-panel h2 { margin: 16px 0 8px; }
.complete-panel p { margin: 0 0 24px; color: var(--muted); }
.complete-icon {
  display: inline-grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 50%;
  background: rgba(21, 150, 109, .12);
  color: var(--known);
  font-size: 28px;
  font-weight: 800;
}

.primary-button {
  border: 0;
  border-radius: 13px;
  padding: 13px 20px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

@media (max-width: 560px) {
  .app-shell { padding-left: 15px; padding-right: 15px; }
  .header-actions { flex-direction: column; align-items: flex-end; }
  .deck-panel { gap: 9px; }
  .deck-button { padding-left: 10px; padding-right: 10px; }
  .deck-panel p { font-size: 10px; }
  .stats div { padding: 11px 8px; display: grid; gap: 2px; text-align: center; }
  .stats strong { font-size: 17px; }
  .card-wrap { border-radius: 44px; }
  .card-face { padding: 28px 22px; }
  .pronounce-button { top: 15px; right: 15px; }
  .controls { gap: 8px; }
  .choice-button { padding: 11px; }
  .choice-button small { display: none; }
  .meaning-note { margin-top: 17px; padding: 12px 14px; }
}

@media (max-height: 760px) {
  .app-shell { padding-top: max(10px, env(safe-area-inset-top)); }
  .eyebrow { margin-bottom: 2px; font-size: 10px; }
  h1 { font-size: 25px; }
  .text-button { padding: 6px 8px; }
  .deck-panel { margin-top: 7px; }
  .deck-switch { padding: 3px; }
  .deck-button { min-height: 29px; padding-top: 5px; padding-bottom: 5px; }
  .deck-panel p { display: none; }
  .progress-panel { margin-top: 10px; }
  .progress-track { margin-top: 6px; }
  .stats { margin-top: 9px; }
  .stats div { padding-top: 8px; padding-bottom: 8px; }
  .study-area { padding-top: 9px; padding-bottom: 9px; }
  .choice-button { min-height: 56px; padding-top: 8px; padding-bottom: 8px; }
  .card-face { padding-top: 24px; padding-bottom: 24px; }
  .card-kicker { margin-bottom: 12px; }
  .meaning { font-size: clamp(18px, 3.7vw, 26px); line-height: 1.4; }
  .meaning-note { margin-top: 12px; padding: 10px 13px; }
  .meaning-note p { font-size: clamp(12px, 2.2vw, 15px); line-height: 1.45; }
  .tap-hint { bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
