:root {
  color-scheme: light;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #e9ebf1;
  --text: #1c2027;
  --muted: #6b7280;
  --border: #d9dce4;
  --accent: #2563eb;
  --green: #22a55e;
  --green-strong: #17864a;
  --red: #e04545;
  --red-strong: #b53838;
  --shadow: 0 1px 3px rgba(23, 26, 32, 0.1);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101318;
  --surface: #1a1f28;
  --surface-2: #252c38;
  --text: #e9ecf1;
  --muted: #9aa4b2;
  --border: #303948;
  --accent: #6a9bff;
  --green: #3ecf85;
  --green-strong: #2ca76a;
  --red: #f2635e;
  --red-strong: #d24a45;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  line-height: 1.4;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px clamp(12px, 4vw, 28px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.05rem, 1.15rem, 1.3rem);
}

#theme-toggle {
  min-width: 44px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 0.95rem;
}

/* ---------- screens ---------- */

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(14px, 4vw, 28px);
}

.screen {
  animation: fadeIn 0.2s ease;
}

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

.screen-title {
  font-size: clamp(1.25rem, 1.5rem, 1.7rem);
  margin: 4px 0 8px;
}

/* ---------- menu ---------- */

.menu-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-btn {
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: clamp(1rem, 1.05rem, 1.15rem);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.menu-btn:active {
  transform: scale(0.99);
}

.link-btn,
.icon-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1rem;
  cursor: pointer;
}

/* ---------- session ---------- */

.session-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.direction-label {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: clamp(0.9rem, 1rem, 1.1rem);
}

.progress-label {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: clamp(0.9rem, 1rem, 1.05rem);
}

.progress-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
  margin-bottom: 16px;
}

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

/* ---------- matching board ---------- */

.board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 3vw, 16px);
}

.col-label {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 2px;
}

.cell {
  min-height: 48px;
  padding: clamp(10px, 2.5vw, 14px);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: clamp(1rem, 0.9rem + 1.2vw, 1.35rem);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  word-break: break-word;
  line-height: 1.25;
}

.cell.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.cell.correct {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  animation: flash 0.35s ease;
}

.cell.wrong {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  animation: shake 0.45s ease;
}

@keyframes flash {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(4px);
  }
}

/* ---------- summary ---------- */

.stat {
  font-size: clamp(1.05rem, 1.15rem, 1.3rem);
  margin: 8px 0 14px;
}

.wrong-list {
  list-style: none;
  margin: 0;
  padding: 4px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.wrong-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: clamp(0.95rem, 1rem, 1.1rem);
}

.wrong-list li:last-child {
  border-bottom: none;
}

.wrong-list li.perfect {
  color: var(--green-strong);
  font-weight: 600;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.btn {
  min-height: 48px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  font-size: 1rem;
  box-shadow: var(--shadow);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- misc ---------- */

.error-box {
  background: var(--surface);
  border: 1px solid var(--red);
  border-left: 5px solid var(--red);
  border-radius: 12px;
  padding: 16px;
}

.error-title {
  font-weight: 700;
  margin: 0 0 8px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  animation: fadeIn 0.15s ease;
}

.overlay.hidden {
  display: none;
}

.announcement {
  background: var(--surface);
  color: var(--text);
  padding: clamp(18px, 4vw, 28px);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  font-size: clamp(1.1rem, 1.3rem, 1.5rem);
  font-weight: 600;
  text-align: center;
  max-width: 90%;
}
