:root {
  color-scheme: light dark;
  --bg: #fff8ef;
  --fg: #3a2f28;
  --card-bg: #ffffff;
  --border: #f0e0c9;
  --accent: #ff9f43;
  --accent-fg: #ffffff;
  --accent-2: #4fc3a1;
  --muted: #8a7d6f;
  --error-bg: #ffecec;
  --error-fg: #c0392b;
  --locked: #d8cfc2;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #241d17;
    --fg: #f5ece0;
    --card-bg: #322820;
    --border: #4a3c2f;
    --accent: #ffb56b;
    --accent-fg: #241d17;
    --accent-2: #5fd6b0;
    --muted: #b8a993;
    --error-bg: #3a1f1f;
    --error-fg: #ff8a80;
    --locked: #4a3c2f;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  display: flex;
  justify-content: center;
  padding: 20px 12px 60px;
}

main {
  width: 100%;
  max-width: 640px;
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 4px;
  text-align: center;
}

.subtitle {
  text-align: center;
  color: var(--muted);
  margin: 0 0 20px;
  font-size: 0.9rem;
}

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

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
}

.mascot-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.mascot-row .mascot {
  width: 84px;
  height: 84px;
  flex: none;
}

.speech-bubble {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 0.95rem;
}

.speech-bubble::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  border-width: 8px 8px 8px 0;
  border-style: solid;
  border-color: transparent var(--border) transparent transparent;
}

.speech-bubble::after {
  content: "";
  position: absolute;
  left: -6px;
  top: 50%;
  transform: translateY(-50%);
  border-width: 7px 7px 7px 0;
  border-style: solid;
  border-color: transparent var(--card-bg) transparent transparent;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font-size: 1rem;
}

input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.btn {
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn.block {
  width: 100%;
}

.error {
  background: var(--error-bg);
  color: var(--error-fg);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-bottom: 12px;
  display: none;
}

.error.visible {
  display: block;
}

.key-box {
  background: var(--bg);
  border: 1px dashed var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  word-break: break-all;
  margin: 10px 0;
}

.category-title {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 18px 4px 8px;
}

.game-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.game-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--fg);
}

.game-card .emoji {
  font-size: 2rem;
  flex: none;
}

.game-card .title {
  font-weight: 700;
  margin-bottom: 2px;
}

.game-card .desc {
  font-size: 0.8rem;
  color: var(--muted);
}

.level-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.level-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
}

.level-item.locked {
  opacity: 0.55;
}

.level-item .level-name {
  font-weight: 600;
}

.level-item .level-stat {
  font-size: 0.8rem;
  color: var(--muted);
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-2);
  color: #06322a;
  font-weight: 700;
}

.badge.locked {
  background: var(--locked);
  color: var(--muted);
}

.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 0.85rem;
}

.top-nav a {
  text-decoration: none;
  color: var(--accent);
}

.masu-wrap {
  overflow-x: auto;
  margin-bottom: 14px;
}

table.masu-table {
  border-collapse: collapse;
  margin: 0 auto;
}

table.masu-table th,
table.masu-table td {
  border: 1px solid var(--border);
  width: 42px;
  height: 38px;
  text-align: center;
  padding: 0;
}

table.masu-table th {
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 0.85rem;
}

table.masu-table th.corner {
  background: var(--card-bg);
}

table.masu-table input {
  width: 100%;
  height: 100%;
  border: none;
  text-align: center;
  font-size: 0.95rem;
  background: transparent;
  color: var(--fg);
  padding: 0;
}

table.masu-table input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

table.masu-table input.correct {
  background: color-mix(in oklab, var(--accent-2) 30%, transparent);
}

table.masu-table input.wrong {
  background: color-mix(in oklab, var(--error-fg) 25%, transparent);
}

.status-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  margin-bottom: 10px;
}

.quiz-question {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  margin: 18px 0;
}

.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.quiz-options button {
  padding: 14px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
  font-size: 1.1rem;
  cursor: pointer;
}

.quiz-options button.correct {
  background: var(--accent-2);
  color: #06322a;
  border-color: var(--accent-2);
}

.quiz-options button.wrong {
  background: var(--error-bg);
  color: var(--error-fg);
  border-color: var(--error-fg);
}

.result-box {
  text-align: center;
  padding: 20px 0;
}

.result-box .big {
  font-size: 2rem;
  font-weight: 800;
  margin: 8px 0;
}

.memory-grid {
  display: grid;
  gap: 8px;
  justify-content: center;
  margin-bottom: 14px;
}

.memory-card {
  width: 60px;
  height: 60px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: transparent;
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.memory-card.open,
.memory-card.matched {
  background: var(--card-bg);
  color: var(--fg);
}

.memory-card.matched {
  opacity: 0.5;
  cursor: default;
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  width: 84px;
  height: 84px;
}

.shape-grid.big {
  width: 140px;
  height: 140px;
  margin: 0 auto 16px;
}

.shape-cell {
  border-radius: 4px;
  background: var(--border);
}

.shape-cell.on {
  background: var(--accent);
}

.flash-number {
  text-align: center;
  font-size: 4rem;
  font-weight: 800;
  padding: 40px 0;
}

.loading,
.empty {
  text-align: center;
  color: var(--muted);
  padding: 20px 0;
}
