:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --card: #ffffff;
  --text: #1f1f1f;
  --muted: #6b6b6b;
  --primary: #1a73e8;
  --primary-soft: #e7f0fe;
  --success: #1b9a59;
  --error: #d93025;
  --border: #e0e0e0;
  --page-accent: linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0));
  --card-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
  --button-text: #1f1f1f;
  --question-accent: #0f2d66;
  --surface: #ffffff;
  --surface-soft: rgba(26, 115, 232, 0.05);
  --surface-soft-border: rgba(26, 115, 232, 0.15);
  --surface-strong: rgba(26, 115, 232, 0.2);
  --scatter-a: rgba(255, 244, 230, 0.7);
  --scatter-b: rgba(232, 245, 255, 0.8);
  --feedback-overlay: rgba(231, 250, 239, 0.92);
  --feedback-shadow: rgba(27, 154, 89, 0.2);
}

:root[data-theme="ocean"] {
  --bg: #eef6f8;
  --card: #ffffff;
  --text: #18313f;
  --muted: #5a7484;
  --primary: #1f7a8c;
  --primary-soft: #dff3f7;
  --success: #238b63;
  --error: #c74e43;
  --border: #cfe0e7;
  --page-accent: linear-gradient(180deg, rgba(218, 239, 245, 0.8), rgba(238, 246, 248, 0));
  --card-shadow: 0 16px 28px rgba(31, 122, 140, 0.12);
  --button-text: #18313f;
  --question-accent: #185e6d;
  --surface: #fcfeff;
  --surface-soft: rgba(31, 122, 140, 0.08);
  --surface-soft-border: rgba(31, 122, 140, 0.15);
  --surface-strong: rgba(31, 122, 140, 0.24);
  --scatter-a: rgba(219, 242, 245, 0.85);
  --scatter-b: rgba(239, 250, 247, 0.9);
  --feedback-overlay: rgba(228, 247, 239, 0.94);
  --feedback-shadow: rgba(35, 139, 99, 0.18);
}

:root[data-theme="meadow"] {
  --bg: #f5f8ef;
  --card: #fffef9;
  --text: #2f3f2f;
  --muted: #6a7b62;
  --primary: #6b8f3d;
  --primary-soft: #ecf3df;
  --success: #2d8c57;
  --error: #bc5348;
  --border: #d9e2c9;
  --page-accent: linear-gradient(180deg, rgba(234, 242, 218, 0.9), rgba(245, 248, 239, 0));
  --card-shadow: 0 16px 28px rgba(107, 143, 61, 0.12);
  --button-text: #2f3f2f;
  --question-accent: #526f2f;
  --surface: #ffffff;
  --surface-soft: rgba(107, 143, 61, 0.08);
  --surface-soft-border: rgba(107, 143, 61, 0.15);
  --surface-strong: rgba(107, 143, 61, 0.22);
  --scatter-a: rgba(244, 240, 219, 0.8);
  --scatter-b: rgba(231, 245, 222, 0.9);
  --feedback-overlay: rgba(234, 247, 236, 0.94);
  --feedback-shadow: rgba(45, 140, 87, 0.18);
}

:root[data-theme="sunset"] {
  --bg: #fcf4ee;
  --card: #fffaf6;
  --text: #442b2f;
  --muted: #816569;
  --primary: #cf6f4b;
  --primary-soft: #f8e4db;
  --success: #49865e;
  --error: #c44d4d;
  --border: #ecd5c8;
  --page-accent: linear-gradient(180deg, rgba(249, 224, 209, 0.9), rgba(252, 244, 238, 0));
  --card-shadow: 0 16px 30px rgba(207, 111, 75, 0.14);
  --button-text: #442b2f;
  --question-accent: #9d5033;
  --surface: #fffdfb;
  --surface-soft: rgba(207, 111, 75, 0.08);
  --surface-soft-border: rgba(207, 111, 75, 0.15);
  --surface-strong: rgba(207, 111, 75, 0.22);
  --scatter-a: rgba(255, 233, 214, 0.84);
  --scatter-b: rgba(255, 245, 229, 0.92);
  --feedback-overlay: rgba(238, 247, 239, 0.94);
  --feedback-shadow: rgba(73, 134, 94, 0.18);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  background: var(--bg);
  background-image: var(--page-accent);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: 24px;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.game {
  width: 100%;
  max-width: 900px;
  display: grid;
  gap: 20px;
}

.settings-btn {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--button-text);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.settings-panel {
  position: fixed;
  top: 64px;
  right: 18px;
  width: 260px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  padding: 12px;
  z-index: 20;
}

.settings-panel__section + .settings-panel__section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.settings-panel__header {
  font-weight: 700;
  margin-bottom: 10px;
}

.settings-panel__actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.settings-panel__actions button {
  flex: 1;
  padding: 6px 8px;
  font-size: 0.85rem;
}

.theme-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.theme-swatch {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid transparent;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.65);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.theme-swatch:hover {
  transform: translateY(-1px);
}

.theme-swatch.is-active {
  border-color: var(--text);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.theme-swatch:focus-visible {
  outline: 3px solid var(--primary-soft);
  outline-offset: 2px;
}

.settings-panel__list {
  display: grid;
  gap: 8px;
}

.settings-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
}

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

h1 {
  font-size: 2rem;
  margin-bottom: 6px;
}

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

.scoreboard {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.scoreboard__item {
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  padding: 10px 14px;
  border-radius: 10px;
  min-width: 90px;
  text-align: center;
}

.scoreboard__item .label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  display: grid;
  gap: 12px;
  box-shadow: var(--card-shadow);
}

.question__type {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.question__body {
  display: grid;
  gap: 8px;
  font-size: 1.6rem;
}

.question__body .question-multiplication {
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-align: center;
  color: var(--question-accent);
}

.question__body .q-icon {
  font-size: 2.4rem;
}

.direction-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(80px, 1fr));
  gap: 12px;
  align-items: center;
  justify-items: center;
  padding: 12px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: var(--surface);
}

.direction-slot {
  width: 100%;
  min-height: 90px;
  display: grid;
  align-items: center;
  justify-items: center;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--surface-soft);
}

.direction-slot[data-position="left"] {
  border-color: var(--surface-soft-border);
}

.direction-slot[data-position="center"] {
  border-color: var(--surface-strong);
}

.direction-slot[data-position="right"] {
  border-color: var(--surface-soft-border);
}

.direction-marker {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  box-shadow: 0 10px 20px var(--surface-strong);
}

.scatter-field {
  position: relative;
  min-height: 220px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: linear-gradient(135deg, var(--scatter-a), var(--scatter-b));
  overflow: hidden;
}

.scatter-item {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  line-height: 1;
}

.math-stack {
  width: var(--math-width, 4ch);
  display: grid;
  gap: 4px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.math-stack__line {
  line-height: 1.1;
}

.math-stack__rule {
  border-bottom: 2px solid var(--text);
  width: 100%;
}

.clock {
  display: flex;
  justify-content: center;
  padding: 10px 0;
}

.clock__face {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: 4px solid var(--text);
  position: relative;
  background: var(--surface);
}

.clock__number {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(calc(var(--position) * 30deg)) translateY(-68px) rotate(calc(var(--position) * -30deg));
  transform-origin: center;
  font-size: 1rem;
  font-weight: 700;
}

.clock__minute {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(calc(var(--position) * 30deg)) translateY(-102px) rotate(calc(var(--position) * -30deg));
  transform-origin: center;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

.clock__hand {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: 0% 50%;
  transform: translateY(-50%) rotate(calc(var(--angle) - 90deg));
  background: var(--text);
  border-radius: 999px;
}

.clock__hand--hour {
  width: 62px;
  height: 6px;
}

.clock__hand--minute {
  width: 78px;
  height: 4px;
}

.question__hint {
  color: var(--muted);
  font-size: 0.95rem;
}

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

.option {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: border 0.2s ease, background 0.2s ease, transform 0.1s ease;
  font-size: 1.4rem;
  box-shadow: var(--card-shadow);
}

.option:hover {
  border-color: var(--primary);
}

.option.selected {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.option.correct {
  border-color: var(--success);
}

.option.incorrect {
  border-color: var(--error);
}

.option .opt-icon {
  font-size: 1.6rem;
}

.option--icon-only {
  justify-content: center;
  min-height: 120px;
}

.option--icon-only .opt-icon {
  font-size: 4.2rem;
  width: 4.2rem;
  height: 4.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.option--icon-only .opt-icon.fa-caret-up {
  transform: scale(1.2);
  transform-origin: center;
}

.controls {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

button {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--button-text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
}

button.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  width: 100%;
}

button.secondary:disabled,
button.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.feedback {
  min-height: 24px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 400ms ease;
}

.feedback.correct {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2.5rem, 6vw, 5rem);
  background: var(--feedback-overlay);
  color: var(--success);
  letter-spacing: 0.04em;
  text-shadow: 0 8px 18px var(--feedback-shadow);
  z-index: 10;
  pointer-events: none;
}

.feedback.visible {
  opacity: 1;
}

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

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

@media (max-width: 600px) {
  .controls {
    flex-direction: column;
    align-items: stretch;
  }
}
