:root {
  --bg: #f7f3eb;
  --surface: #fffaf2;
  --surface-strong: #ffffff;
  --text: #1f2933;
  --muted: #667085;
  --line: #ded6ca;
  --primary: #1f7a6b;
  --primary-strong: #14584d;
  --accent: #b15c38;
  --danger: #b42318;
  --warning: #946200;
  --focus: #2563eb;
  --shadow: 0 14px 38px rgba(31, 41, 51, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

button,
select,
input,
textarea {
  min-height: 44px;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

button:hover {
  background: var(--primary-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

button.secondary {
  background: #e8f1ee;
  color: var(--primary-strong);
}

button.secondary:hover {
  background: #d9e9e4;
}

button.warning {
  background: #f4e7c7;
  color: var(--warning);
}

button.danger {
  background: #fde0dc;
  color: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  padding: 9px 11px;
}

textarea {
  resize: vertical;
  min-height: 220px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.6;
}

.app-header,
.tabs,
main {
  width: min(1180px, calc(100% - 32px));
  margin-inline: auto;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 0 16px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1.1;
}

h2 {
  font-size: 24px;
  line-height: 1.2;
}

h3 {
  font-size: 20px;
}

.muted {
  color: var(--muted);
}

.stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stats span {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  padding: 8px 12px;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
  overflow-x: auto;
}

.tab {
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.tab.active {
  background: var(--surface);
  color: var(--primary-strong);
  border: 1px solid var(--line);
  border-bottom-color: var(--surface);
}

main {
  padding-bottom: 56px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.inline-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: min(100%, 440px);
}

.inline-controls select,
.inline-controls input {
  flex: 1 1 180px;
}

.study-card,
.panel,
.create-form,
.card-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.study-card {
  min-height: 480px;
  padding: clamp(18px, 4vw, 32px);
}

.empty-state {
  min-height: 340px;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
}

.word-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
}

.word {
  font-size: clamp(42px, 11vw, 88px);
  line-height: 1;
  overflow-wrap: anywhere;
}

.phonetic {
  color: var(--accent);
  font-size: 18px;
  margin-top: 8px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--muted);
  background: var(--surface-strong);
  font-size: 13px;
}

.answer {
  display: none;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}

.answer.visible {
  display: grid;
}

.meaning {
  font-size: 24px;
  font-weight: 750;
}

.example {
  font-size: 18px;
}

.controls,
.grade-controls,
.speech-controls,
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.controls {
  margin: 22px 0;
}

.speech-box {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}

.speech-controls {
  margin-top: 12px;
}

.speech-controls input {
  min-width: 260px;
  flex: 1 1 280px;
}

.assessment {
  margin-top: 14px;
  border-left: 4px solid var(--primary);
  padding: 10px 12px;
  background: rgba(31, 122, 107, 0.08);
}

.assessment.retry {
  border-left-color: var(--danger);
  background: rgba(180, 35, 24, 0.08);
}

.assessment.close {
  border-left-color: var(--warning);
  background: rgba(148, 98, 0, 0.08);
}

.grade-controls {
  margin-top: 24px;
}

.form-grid,
.create-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.create-form {
  padding: 18px;
  margin-bottom: 18px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 650;
}

label input,
label textarea,
label select {
  color: var(--text);
  font-weight: 400;
}

.block-label {
  margin: 16px 0;
}

.wide {
  grid-column: 1 / -1;
}

.result {
  margin-top: 16px;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1f2933;
  color: #edf2f7;
  padding: 14px;
  overflow-x: auto;
}

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

.card-row {
  padding: 14px 16px;
  display: grid;
  grid-template-columns: minmax(140px, 0.8fr) minmax(0, 1.2fr) auto;
  gap: 14px;
  align-items: center;
  box-shadow: none;
}

.card-row strong {
  font-size: 18px;
}

.due {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 32px));
  border-radius: 8px;
  background: #1f2933;
  color: white;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.toast.visible {
  opacity: 1;
}

@media (max-width: 760px) {
  .app-header,
  .section-head,
  .word-head {
    align-items: stretch;
    flex-direction: column;
  }

  .stats {
    justify-content: flex-start;
  }

  .form-grid,
  .create-form,
  .card-row {
    grid-template-columns: 1fr;
  }

  .due {
    text-align: left;
  }
}

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