:root {
  --bg: #f6f2e8;
  --panel: rgba(255, 252, 246, 0.95);
  --border: #d6c9b6;
  --text: #21313c;
  --muted: #5c6c73;
  --accent: #ffb703;
  --known: #3a9b6c;
  --unknown: #df5f42;
  --ghost: #f0e6d7;
  --shadow: 0 16px 40px rgba(76, 56, 32, 0.12);
  --radius: 24px;
  --display-font: "Trebuchet MS", "Avenir Next", "PingFang SC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Verdana", "PingFang SC", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 214, 102, 0.45), transparent 24%),
    radial-gradient(circle at top right, rgba(135, 206, 235, 0.25), transparent 28%),
    linear-gradient(180deg, #fef8ef 0%, #f6f2e8 100%);
  overflow: hidden;
}

button,
select,
input,
textarea {
  font: inherit;
}

.app-shell {
  max-width: 1920px;
  margin: 0 auto;
  padding: 16px;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
}

.card {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar,
.settings-panel,
.study-panel,
.result-panel {
  padding: 16px 18px;
}

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

.topbar h1,
.study-panel h2 {
  margin: 0;
  font-family: var(--display-font);
}

.topbar h1 {
  font-size: clamp(1.55rem, 2.4vw, 2.2rem);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--unknown);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.subtle {
  margin: 4px 0 0;
  color: var(--muted);
}

.topbar-actions,
.secondary-actions,
.import-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.focus-summary {
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  background: #fff3d3;
  color: #7b5700;
  font-weight: 700;
}

.settings-panel {
  max-height: min(44dvh, 390px);
  overflow: auto;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 12px;
  align-items: end;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-group label,
.result-panel h4,
.result-panel h3 {
  font-weight: 700;
}

.control-group select,
.control-group input,
textarea {
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 2px solid var(--border);
  background: #fffdf8;
}

.control-group.wide {
  grid-column: span 1;
}

.builtin-group {
  gap: 10px;
}

.advanced-settings {
  margin-top: 12px;
}

.advanced-settings summary {
  cursor: pointer;
  list-style: none;
  font-weight: 800;
  font-size: 1.1rem;
}

.advanced-settings summary::-webkit-details-marker {
  display: none;
}

.advanced-settings[open] summary {
  margin-bottom: 12px;
}

.builtin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.progress-actions {
  margin-top: 12px;
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(260px, 19vw, 340px);
  gap: 16px;
  margin-top: 0;
  min-height: 0;
}

.sidebar {
  display: grid;
  gap: 12px;
  min-height: 0;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.progress-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.progress-headline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mini-badges {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.mini-badge {
  padding: 10px 14px;
  border-radius: 999px;
  background: #fff4cf;
  color: #8b5e00;
  font-weight: 800;
}

.mini-badge.soft {
  background: #eef7ff;
  color: #2a5f87;
}

.word-card {
  min-height: 0;
  margin-top: 12px;
  padding: 22px 24px 24px;
  border-radius: 28px;
  border: 3px dashed #e1d2bc;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 249, 239, 0.96)),
    repeating-linear-gradient(
      -45deg,
      rgba(255, 183, 3, 0.08) 0 16px,
      rgba(255, 183, 3, 0.02) 16px 32px
    );
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  overflow: auto;
  gap: 10px;
}

.unit-badge {
  margin: 0 0 6px;
  padding: 12px 22px;
  border-radius: 999px;
  background: #ebf6ff;
  color: #1b597c;
  font-weight: 800;
  font-size: clamp(1.2rem, 2vw, 1.8rem);
  align-self: flex-start;
}

.group-badge {
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff4cf;
  color: #8b5e00;
  font-weight: 800;
}

.group-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cheer-text {
  margin: 10px 0 0;
  color: #7b5700;
  font-size: clamp(0.95rem, 1.1vw, 1.15rem);
  font-weight: 700;
}

.hint-btn {
  position: relative;
  min-width: 34px;
  min-height: 34px;
  padding: 0 10px;
  border: none;
  border-radius: 999px;
  background: #edf4fb;
  color: #2a5f87;
  font-weight: 900;
  cursor: help;
}

.hint-btn.warm {
  background: #fff4cf;
  color: #8b5e00;
}

.hint-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%) translateY(6px);
  width: max-content;
  max-width: min(320px, 70vw);
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(33, 49, 60, 0.96);
  color: #fffdf8;
  font-size: 0.9rem;
  line-height: 1.4;
  box-shadow: 0 12px 24px rgba(33, 49, 60, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
  white-space: normal;
  z-index: 20;
}

.hint-btn:hover::after,
.hint-btn:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.mode-badge {
  margin: 10px 0 8px;
  padding: 8px 18px;
  border-radius: 999px;
  background: #ffe4c9;
  color: #925319;
  font-weight: 800;
}

#wordText {
  margin: 8px 0 0;
  font-size: clamp(5.2rem, 11vw, 9.5rem);
  line-height: 0.98;
  letter-spacing: 0.02em;
  text-wrap: balance;
}

.word-card.meaning-visible #wordText,
.word-card.spelling-visible #wordText {
  font-size: clamp(3.4rem, 7vw, 6.5rem);
}

.word-card.dictation-visible #wordText {
  font-size: clamp(2.8rem, 5vw, 4.8rem);
}

.phonetic,
.example,
#meaningText {
  margin: 12px 0 0;
}

.phonetic {
  font-size: clamp(1.2rem, 1.7vw, 1.6rem);
  color: #46616c;
}

.meaning-block {
  margin-top: 8px;
  padding: 14px 18px;
  width: min(100%, 840px);
  border-radius: 20px;
  background: #fff1d8;
}

#meaningText {
  font-size: clamp(1.35rem, 2.2vw, 1.9rem);
  font-weight: 700;
  white-space: pre-line;
}

.example {
  color: var(--muted);
  font-size: 1rem;
}

.dictation-prompt {
  margin-top: 10px;
  padding: 12px 16px;
  border-radius: 18px;
  background: #eef7ff;
  color: #2a5f87;
  font-size: clamp(1.1rem, 1.8vw, 1.35rem);
  font-weight: 700;
}

.spelling-panel {
  margin-top: 12px;
  width: min(100%, 760px);
  padding: 14px 16px;
  border-radius: 20px;
  background: #eef9f2;
  border: 2px solid #cfe7d6;
  text-align: left;
}

.spelling-panel label {
  display: block;
  margin-bottom: 8px;
  font-weight: 800;
  font-size: 1.2rem;
}

.spelling-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.spelling-row input {
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 16px;
  border: 2px solid #b9d2c0;
  font-size: 1.3rem;
}

.spelling-feedback {
  margin: 10px 0 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.spelling-feedback.success {
  color: var(--known);
}

.spelling-feedback.error {
  color: var(--unknown);
}

.primary-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
  flex: 0 0 auto;
}

.large-btn,
.primary-btn,
.secondary-btn,
.ghost-btn,
.known-btn,
.unknown-btn {
  min-height: 52px;
  border: none;
  border-radius: 18px;
  padding: 14px 18px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease, box-shadow 0.18s ease;
}

.large-btn {
  font-size: clamp(1.1rem, 1.4vw, 1.45rem);
}

button:hover,
button:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(56, 42, 24, 0.14);
}

.primary-btn {
  background: var(--accent);
  color: #3c2c00;
}

.secondary-btn {
  background: #fff3d3;
  color: #5f4500;
}

.ghost-btn {
  background: var(--ghost);
  color: #5f5544;
}

.known-btn {
  background: var(--known);
  color: white;
  min-height: 68px;
}

.unknown-btn {
  background: var(--unknown);
  color: white;
  min-height: 68px;
}

.secondary-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  flex: 0 0 auto;
  margin-top: 10px;
}

textarea {
  width: 100%;
  resize: vertical;
  font-size: 1rem;
  max-height: 180px;
}

.result-metrics p {
  margin: 10px 0;
  font-weight: 700;
}

.result-list {
  margin: 12px 0 0;
  padding-left: 20px;
  max-height: none;
  min-height: 0;
  overflow: auto;
}

.result-list li {
  margin-bottom: 8px;
}

.compact-panel {
  padding-top: 18px;
}

.study-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.result-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.word-card {
  flex: 1 1 auto;
}

.result-metrics {
  flex: 0 0 auto;
}

.completion-banner {
  margin-top: 18px;
  padding: 20px;
  border-radius: 20px;
  background: #e9f8ee;
  border: 2px solid #c0e4cd;
  text-align: center;
}

.completion-banner h2 {
  margin-bottom: 8px;
  font-size: 2rem;
}

.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
  }

  .settings-grid,
  .primary-actions,
  .main-layout {
    grid-template-columns: 1fr;
  }

  .spelling-row {
    grid-template-columns: 1fr;
  }

  .builtin-row {
    grid-template-columns: 1fr;
  }

  .topbar,
  .progress-row {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    align-items: flex-start;
  }

  .app-shell {
    padding: 16px;
  }

  .word-card {
    min-height: 320px;
  }

  #wordText {
    font-size: clamp(3.6rem, 18vw, 6rem);
  }
}

@media (max-width: 1280px) and (min-width: 1081px) {
  .main-layout {
    grid-template-columns: minmax(0, 1fr) 260px;
    gap: 12px;
  }

  .settings-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    gap: 10px;
  }
}

@media (max-height: 980px) {
  .topbar,
  .settings-panel,
  .study-panel,
  .result-panel {
    padding: 14px 16px;
  }

  .topbar h1 {
    font-size: clamp(1.35rem, 2vw, 1.8rem);
  }

  .word-card {
    padding: 14px 16px 18px;
  }

  #wordText {
    font-size: clamp(4.2rem, 8vw, 7rem);
  }
}

@media (max-height: 820px) {
  .eyebrow {
    display: none;
  }

  .focus-summary {
    padding: 8px 12px;
    font-size: 0.92rem;
  }

  #wordText {
    font-size: clamp(3.5rem, 7vw, 5.8rem);
  }

  .meaning-block,
  .spelling-panel {
    padding: 12px 14px;
  }

  .secondary-actions {
    gap: 8px;
  }

  .ghost-btn {
    min-height: 44px;
    padding: 10px 14px;
  }
}

@media (max-width: 1600px) and (max-height: 980px) {
  .keyboard-help {
    display: none;
  }
}
