:root {
  color-scheme: light;
  --ink: #242331;
  --muted: #74727f;
  --top: #4e4a5f;
  --line: #dedce5;
  --paper: #ffffff;
  --mist: #f5f4f0;
  --gold: #f3b31a;
  --gold-2: #ffe37c;
  --teal: #1aa9a5;
  --rose: #e84a68;
  --green: #2eaf72;
  --blue: #5477c9;
  --shadow: 0 10px 26px rgba(36, 35, 49, .14);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(243, 179, 26, .22), transparent 28%),
    radial-gradient(circle at 90% 20%, rgba(26, 169, 165, .2), transparent 26%),
    linear-gradient(135deg, #ededf1, #f7f4ec);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.phone {
  position: relative;
  width: min(100vw, 430px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--mist);
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(36, 35, 49, .08), 0 30px 80px rgba(36, 35, 49, .25);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  color: #fff;
  background: var(--top);
  box-shadow: 0 4px 14px rgba(36, 35, 49, .2);
}

.statusline,
.brandline,
.modebar,
.toolbar,
.auth-actions,
.triple-actions {
  display: flex;
  align-items: center;
}

.statusline {
  justify-content: space-between;
  height: 22px;
  font-weight: 700;
  font-size: 13px;
  opacity: .95;
}

.brandline {
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 10px;
}

.brandline p,
.brandline h1,
.toolbar h2,
.toolbar p,
.summary-card h2,
.summary-card p {
  margin: 0;
}

.brandline p {
  font-size: 12px;
  color: #dad7e7;
}

.brandline h1 {
  font-size: 24px;
  letter-spacing: 0;
}

.profile-btn {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--teal), #6ad4c8);
  color: #fff;
  font-weight: 900;
  box-shadow: inset 0 -3px rgba(0, 0, 0, .14);
}

.modebar {
  gap: 8px;
}

.mode-btn {
  flex: 1;
  min-height: 46px;
  border-radius: 8px;
  color: #2b2a34;
  background: #f7df65;
  font-weight: 900;
  border: 2px solid rgba(255, 255, 255, .5);
  box-shadow: inset 0 -4px rgba(0, 0, 0, .13), 0 1px 0 rgba(255, 255, 255, .45);
}

.mode-btn.active {
  background: var(--gold);
  outline: 2px solid rgba(255, 255, 255, .75);
}

.square-btn {
  width: 48px;
  height: 46px;
  border-radius: 8px;
  background: #61bbb5;
  border: 2px solid rgba(255, 255, 255, .5);
  box-shadow: inset 0 -4px rgba(0, 0, 0, .14);
}

.speaker,
.speaker::before,
.speaker::after {
  display: inline-block;
  position: relative;
}

.speaker {
  width: 13px;
  height: 16px;
  background: #fff;
  clip-path: polygon(0 35%, 35% 35%, 100% 0, 100% 100%, 35% 65%, 0 65%);
}

.speaker::after {
  content: "";
  position: absolute;
  left: 14px;
  top: 1px;
  width: 10px;
  height: 14px;
  border-right: 3px solid #fff;
  border-radius: 50%;
}

.screen {
  display: none;
  min-height: calc(100vh - 170px);
  padding: 14px 12px 96px;
}

.screen.active {
  display: block;
}

.summary-card {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 12px;
  align-items: center;
  padding: 16px;
  border-radius: 12px;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, .92), rgba(255, 255, 255, .76)),
    linear-gradient(135deg, rgba(243, 179, 26, .25), rgba(26, 169, 165, .22));
  border: 1px solid rgba(255, 255, 255, .9);
  box-shadow: var(--shadow);
}

.kicker {
  color: var(--teal);
  font-weight: 900;
  font-size: 12px;
  text-transform: uppercase;
}

.summary-card h2 {
  margin-top: 3px;
  font-size: 21px;
}

.summary-card span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.ring {
  position: relative;
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
}

.ring svg {
  position: absolute;
  inset: 0;
  transform: rotate(-90deg);
}

.ring circle {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
}

.ring circle:first-child {
  stroke: #e4e1dc;
}

#ringBar {
  stroke: var(--green);
  stroke-dasharray: 302;
  stroke-dashoffset: 302;
  transition: stroke-dashoffset .35s ease;
}

.ring strong {
  font-size: 20px;
}

.toolbar {
  justify-content: space-between;
  gap: 12px;
  margin: 18px 2px 10px;
}

.toolbar.sticky {
  position: sticky;
  top: 144px;
  z-index: 5;
  padding: 8px 0;
  background: var(--mist);
}

.toolbar h2 {
  font-size: 21px;
}

.toolbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.pill-btn,
.tiny-btn {
  min-height: 38px;
  padding: 0 13px;
  border-radius: 9px;
  background: var(--gold-2);
  color: #2b2a34;
  font-weight: 800;
  box-shadow: inset 0 -3px rgba(0, 0, 0, .1);
  white-space: nowrap;
}

.filterbar,
.segment {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.segment {
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border-radius: 12px;
  background: #e8e5dd;
}

.filter-btn,
.segment-btn {
  min-height: 36px;
  border-radius: 9px;
  color: var(--muted);
  background: rgba(255, 255, 255, .75);
  font-weight: 800;
}

.filter-btn.active,
.segment-btn.active {
  background: var(--ink);
  color: #fff;
}

.letter-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.letter-card {
  min-height: 86px;
  padding: 8px 8px 9px;
  border-radius: 10px;
  background: linear-gradient(#ffffff 0 49%, #e7e7e7 50% 100%);
  border: 1px solid #d9d7df;
  box-shadow: inset 0 -5px rgba(0, 0, 0, .08), 0 4px 8px rgba(36, 35, 49, .12);
  text-align: center;
  transition: transform .12s ease, box-shadow .12s ease;
}

.letter-card:active,
.letter-card.pop {
  transform: translateY(2px) scale(.99);
  box-shadow: inset 0 -2px rgba(0, 0, 0, .08), 0 2px 5px rgba(36, 35, 49, .1);
}

.letter-card.learned {
  outline: 3px solid rgba(46, 175, 114, .5);
}

.letter-card .hangul {
  display: block;
  color: #9d2430;
  font-size: 34px;
  line-height: 1;
  font-weight: 800;
}

.letter-card .roman {
  display: block;
  margin-top: 4px;
  color: #34323c;
  font-size: 14px;
  font-weight: 900;
}

.letter-card .hint {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content-list {
  display: grid;
  gap: 10px;
}

.content-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 13px;
  border-radius: 11px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 5px 13px rgba(36, 35, 49, .08);
}

.content-card h3 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.content-card p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.content-card small {
  display: inline-block;
  margin-top: 6px;
  color: var(--teal);
  font-weight: 800;
}

.card-actions {
  display: grid;
  gap: 6px;
}

.round-action {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  color: #fff;
  background: var(--teal);
  font-weight: 900;
  box-shadow: inset 0 -3px rgba(0, 0, 0, .13);
}

.round-action.alt {
  background: var(--rose);
}

.write-card,
.quiz-card,
.auth-card,
.settings-card {
  padding: 14px;
  border-radius: 13px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.write-target {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

#writeHangul {
  color: #9d2430;
  font-size: 56px;
  font-weight: 900;
  line-height: 1;
}

#writeCanvas {
  display: block;
  width: 100%;
  height: auto;
  background:
    linear-gradient(90deg, transparent 49.5%, rgba(36, 35, 49, .12) 50%, transparent 50.5%),
    linear-gradient(transparent 49.5%, rgba(36, 35, 49, .12) 50%, transparent 50.5%),
    #fbfaf7;
  border: 1px dashed #beb9c9;
  border-radius: 12px;
  touch-action: none;
}

.triple-actions {
  gap: 8px;
  margin-top: 12px;
}

.triple-actions button,
.auth-actions button {
  flex: 1;
  min-height: 46px;
  border-radius: 10px;
  color: var(--ink);
  background: #e6e1d5;
  font-weight: 900;
}

.primary,
.triple-actions .primary,
.auth-actions .primary {
  color: #fff;
  background: var(--teal);
}

.quiz-card {
  text-align: center;
}

.quiz-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.quiz-audio {
  min-height: 38px;
  margin-top: 10px;
  padding: 0 14px;
  border-radius: 999px;
  color: #fff;
  background: var(--blue);
  font-weight: 900;
}

.quiz-prompt {
  margin-top: 12px;
  min-height: 92px;
  display: grid;
  place-items: center;
  font-size: 46px;
  font-weight: 900;
  color: #9d2430;
  word-break: keep-all;
}

.answer-grid {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.answer-btn {
  min-height: 58px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 4px 10px rgba(36, 35, 49, .08);
  font-weight: 900;
  text-align: left;
}

.answer-btn.correct {
  background: #dff5e9;
  border-color: var(--green);
}

.answer-btn.wrong {
  background: #ffe3e7;
  border-color: var(--rose);
}

.feedback {
  min-height: 30px;
  margin-top: 12px;
  color: var(--muted);
  font-weight: 900;
}

.auth-card {
  display: grid;
  gap: 10px;
}

.auth-card h3 {
  margin: 0;
  font-size: 18px;
}

.auth-card label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.auth-card input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 12px;
  background: #fbfaf8;
  color: var(--ink);
}

.auth-actions {
  gap: 8px;
}

#authMessage {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.stats-grid div {
  min-height: 82px;
  display: grid;
  place-items: center;
  padding: 8px;
  border-radius: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
}

.stats-grid strong {
  font-size: 24px;
}

.stats-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.settings-card {
  display: grid;
  gap: 2px;
  margin-top: 12px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 50px;
  padding: 0 4px;
  color: var(--ink);
  background: transparent;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.setting-row:last-child {
  border-bottom: 0;
}

.setting-row strong {
  color: var(--teal);
}

.setting-row.danger strong {
  color: var(--rose);
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: end;
  justify-content: center;
  background: rgba(36, 35, 49, .42);
}

.drawer.open {
  display: flex;
}

.drawer-card {
  width: min(100vw, 430px);
  max-height: 82vh;
  overflow: auto;
  padding: 18px 14px max(22px, env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: var(--paper);
  box-shadow: 0 -20px 50px rgba(36, 35, 49, .22);
}

.close-btn {
  float: right;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: #ebe8e0;
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
}

.drawer h2 {
  margin: 6px 44px 4px 0;
  font-size: 24px;
}

.drawer .big-letter {
  display: block;
  margin: 10px 0;
  color: #9d2430;
  font-size: 76px;
  font-weight: 900;
  line-height: 1;
}

.drawer p {
  color: var(--muted);
  line-height: 1.5;
}

.drawer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}

.drawer-actions button {
  min-height: 46px;
  border-radius: 11px;
  background: #ebe8e0;
  font-weight: 900;
}

.drawer-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.mini-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfaf8;
}

.mini-card strong {
  display: block;
  margin-bottom: 3px;
  font-size: 19px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  width: min(100vw, 430px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.nav-btn {
  min-height: 62px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  color: #888592;
  background: transparent;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 900;
}

.nav-btn.active {
  color: var(--blue);
  background: #eef2ff;
}

.icon {
  width: 24px;
  height: 24px;
  position: relative;
  display: block;
}

.icon::before,
.icon::after {
  content: "";
  position: absolute;
}

.book::before {
  inset: 3px 4px;
  border: 3px solid currentColor;
  border-radius: 3px;
}

.book::after {
  top: 4px;
  bottom: 4px;
  left: 11px;
  border-left: 2px solid currentColor;
}

.words::before {
  inset: 4px 3px;
  border: 3px solid currentColor;
  border-radius: 5px;
}

.words::after {
  width: 10px;
  height: 3px;
  left: 7px;
  top: 11px;
  background: currentColor;
  box-shadow: 0 5px currentColor;
}

.write::before {
  width: 17px;
  height: 5px;
  left: 3px;
  top: 12px;
  background: currentColor;
  transform: rotate(-35deg);
  border-radius: 4px;
}

.write::after {
  width: 14px;
  height: 3px;
  left: 5px;
  bottom: 4px;
  background: currentColor;
  border-radius: 3px;
}

.quiz::before {
  inset: 3px 5px;
  border: 3px solid currentColor;
  border-radius: 4px;
}

.quiz::after {
  width: 10px;
  height: 3px;
  left: 8px;
  top: 9px;
  background: currentColor;
  box-shadow: 0 5px currentColor, 0 10px currentColor;
}

.more::before {
  width: 6px;
  height: 6px;
  left: 3px;
  top: 9px;
  background: currentColor;
  border-radius: 50%;
  box-shadow: 8px 0 currentColor, 16px 0 currentColor;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}

@media (min-width: 700px) {
  body {
    padding: 24px 0;
  }

  .phone {
    min-height: calc(100vh - 48px);
    border-radius: 28px;
  }

  .bottom-nav {
    bottom: 24px;
    border-radius: 0 0 28px 28px;
  }
}
