:root {
  --bg: #f4f2ec;
  --surface: #fffdf8;
  --ink: #1c1915;
  --muted: #6b6560;
  --accent: #c45c3e;
  --accent-dim: #a84a32;
  --line: #e3ddd4;
  --ok: #2d6a4f;
  --bad: #9b2226;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(28, 25, 21, 0.08);
  --font: "Source Han Sans SC", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui,
    sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
}

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 960px;
  margin: 0 auto;
  padding: 16px max(18px, env(safe-area-inset-left)) max(32px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-right));
  width: 100%;
}

.screen {
  display: none;
  flex-direction: column;
  gap: 16px;
  animation: fadeIn 0.28s ease;
}

.screen.active {
  display: flex;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

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

.topbar[hidden] {
  display: none !important;
}

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.auth-menu {
  position: relative;
}

.btn-account-name {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  min-height: 44px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  max-width: min(240px, 70vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-account-name:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.auth-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  min-width: 140px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.auth-dropdown .btn-logout-item {
  width: 100%;
  justify-content: center;
}

.home-main-actions {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 4px;
}

.btn-home-xl {
  width: 100%;
  font-size: clamp(1.35rem, 5vw, 1.7rem);
  font-weight: 700;
  padding: 28px 22px;
  min-height: 92px;
  border-radius: 18px;
}

.btn-replay {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.icon-speaker {
  flex-shrink: 0;
  opacity: 0.9;
}

.row-actions--mark {
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.btn-mark-lg {
  min-height: 64px;
  min-width: min(42vw, 200px);
  padding: 20px 36px;
  font-size: clamp(1.15rem, 4vw, 1.35rem);
  font-weight: 700;
  border-radius: 16px;
}

.row-actions--practice-footer {
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-top: 8px;
  gap: 12px;
}

.row-actions--practice-footer .btn {
  flex: 0 1 auto;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 18px 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.stat {
  padding: 14px;
  border-radius: 12px;
  background: linear-gradient(160deg, #fff 0%, #faf7f0 100%);
  border: 1px solid var(--line);
}

.stat .n {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
}

.stat .l {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

button,
.btn {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  min-height: 48px;
  min-width: 48px;
  touch-action: manipulation;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}

button:active,
.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(196, 92, 62, 0.35);
}

.btn-primary:hover {
  background: var(--accent-dim);
}

.btn-secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--line);
}

.btn-ok {
  background: var(--ok);
  color: #fff;
}

.btn-bad {
  background: var(--bad);
  color: #fff;
}

input,
textarea,
select {
  font: inherit;
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 12px 14px;
  background: #fff;
}

textarea {
  min-height: 140px;
  resize: vertical;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.9rem;
  color: var(--muted);
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.error-msg {
  color: var(--bad);
  font-size: 0.9rem;
}

.auth-screen-title {
  margin: 0 0 14px;
  font-size: 1.2rem;
  font-weight: 700;
}

.auth-switch-row {
  margin-top: 16px;
  text-align: center;
}

.btn-link {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-link:hover {
  color: var(--accent-dim);
}

.onboard-full-btn {
  width: 100%;
  margin-top: 16px;
}

.onboard-textarea {
  min-height: 160px;
  margin-top: 8px;
}

.onboard-ocr-hint {
  margin-top: 10px;
  margin-bottom: 0;
}

.listen-panel {
  text-align: center;
  padding: 28px 16px;
}

.listen-panel .status {
  margin-top: 12px;
  color: var(--muted);
}

.word-display {
  font-size: clamp(1.5rem, 5vw, 2.25rem);
  text-align: center;
  margin: 16px 0;
  line-height: 1.6;
  min-height: 2.5rem;
  letter-spacing: 0.08em;
}

.word-char--han.word-char--tap {
  cursor: pointer;
  padding: 4px 6px;
  margin: 0 2px;
  border-radius: 8px;
  border-bottom: 2px solid var(--accent);
  transition: background 0.15s ease, color 0.15s ease;
}

.word-char--han.word-char--tap:hover {
  background: rgba(196, 92, 62, 0.12);
}

.word-char--other {
  opacity: 0.55;
  padding: 0 2px;
}

.stroke-stage {
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #faf8f4;
  border-radius: 12px;
  border: 1px dashed var(--line);
}

.stroke-stage[hidden] {
  display: none !important;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 21, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.overlay.active {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: 18px;
  max-width: 420px;
  width: 100%;
  max-height: 80vh;
  overflow: auto;
  padding: 22px;
  box-shadow: var(--shadow);
}

.summary-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.summary-list li {
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  margin-bottom: 8px;
}

.item-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.item-table th,
.item-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.item-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
}

.item-table .btn {
  padding: 8px 12px;
  min-height: 40px;
  font-size: 0.85rem;
  margin-right: 6px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #eee8df;
  color: var(--muted);
}

.badge.rev {
  background: #fde8e8;
  color: var(--bad);
}

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

.vocab-section-title {
  margin: 8px 0 12px;
  font-size: clamp(1rem, 3.5vw, 1.15rem);
  font-weight: 600;
}

.vocab-count-num {
  color: var(--accent);
  font-weight: 700;
}

.vocab-ocr-hint {
  margin-top: 14px;
  margin-bottom: 0;
}

.row-actions--ocr {
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.btn-ocr {
  flex: 1 1 calc(50% - 6px);
  min-height: 48px;
  min-width: 140px;
}

.row-actions--wrap {
  flex-wrap: wrap;
}

@media (min-width: 768px) {
  #app {
    padding: 24px max(24px, env(safe-area-inset-left)) max(40px, env(safe-area-inset-bottom))
      max(24px, env(safe-area-inset-right));
  }

  .btn-ocr {
    flex: 0 1 auto;
    min-width: 160px;
  }
}

@media (min-width: 1024px) {
  #app {
    max-width: 920px;
  }
}

@media (pointer: fine) {
  button:focus-visible,
  .btn:focus-visible,
  input:focus-visible,
  textarea:focus-visible,
  select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
}
