:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #dbeafe;
  --mint: #16a34a;
  --mint-soft: #dcfce7;
  --amber: #f59e0b;
  --amber-soft: #fef3c7;
  --rose: #e11d48;
  --rose-soft: #ffe4e6;
  --shadow: 0 18px 45px rgba(23, 32, 51, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.08), transparent 35%),
    linear-gradient(315deg, rgba(22, 163, 74, 0.08), transparent 42%),
    var(--bg);
  color: var(--ink);
  font-family:
    ui-rounded,
    "Hiragino Maru Gothic ProN",
    "Yu Gothic",
    "Meiryo",
    system-ui,
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 40px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 900;
  font-size: 22px;
  padding: 0;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  background: var(--accent);
  color: white;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.22);
}

.top-actions,
.result-actions,
.stats-actions,
.quiz-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.main {
  flex: 1;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 40px;
}

.main:focus {
  outline: none;
}

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.02fr) minmax(360px, 0.98fr);
  gap: clamp(20px, 4vw, 40px);
  align-items: center;
  min-height: calc(100vh - 126px);
}

.start-panel {
  display: grid;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 72px;
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 16px;
  font-size: 20px;
}

.home-stats {
  min-height: 52px;
  color: var(--muted);
  font-weight: 700;
}

.home-stats strong {
  color: var(--ink);
  font-size: 22px;
}

.mode-list {
  display: grid;
  gap: 12px;
  width: min(480px, 100%);
}

.mode-button,
.solid-button,
.outline-button,
.ghost-button,
.danger-button,
.text-button,
.answer-button {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  min-height: 44px;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    background 150ms ease,
    box-shadow 150ms ease;
}

.mode-button:focus-visible,
.solid-button:focus-visible,
.outline-button:focus-visible,
.ghost-button:focus-visible,
.danger-button:focus-visible,
.text-button:focus-visible,
.answer-button:focus-visible,
.brand:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.28);
  outline-offset: 2px;
}

.mode-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  box-shadow: 0 10px 28px rgba(23, 32, 51, 0.08);
}

.mode-button:hover,
.solid-button:hover,
.outline-button:hover,
.ghost-button:hover,
.danger-button:hover,
.answer-button:hover {
  transform: translateY(-1px);
}

.mode-button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.25);
}

.mode-title {
  font-size: 20px;
  font-weight: 900;
}

.mode-meta {
  flex: 0 0 auto;
  color: inherit;
  opacity: 0.78;
  font-size: 13px;
  font-weight: 900;
}

.number-board {
  display: grid;
  grid-template-columns: repeat(10, minmax(28px, 1fr));
  gap: 6px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.board-corner,
.board-header,
.board-cell {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 6px;
  font-weight: 900;
}

.board-corner,
.board-header {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.board-cell {
  background: var(--surface-2);
  color: #26334d;
  font-size: 17px;
}

.quiz-layout,
.result-layout,
.stats-layout {
  display: grid;
  gap: 18px;
}

.quiz-layout {
  width: min(760px, 100%);
  margin: 0 auto;
  padding-top: 24px;
}

.quiz-status,
.stats-heading,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.progress-text {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 32px;
  font-weight: 900;
}

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

.timer-pill {
  min-width: 88px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: center;
  font-weight: 900;
}

.progress-track {
  height: 12px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--mint));
  transition: width 180ms ease;
}

.problem-panel {
  display: grid;
  gap: 18px;
  justify-items: center;
  padding: clamp(28px, 7vw, 64px) clamp(18px, 6vw, 56px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.problem {
  min-height: 1.1em;
  font-size: 132px;
  line-height: 1;
  font-weight: 1000;
  letter-spacing: 0;
}

.answer-form {
  display: grid;
  grid-template-columns: minmax(140px, 240px) auto;
  gap: 10px;
  width: min(430px, 100%);
}

input[data-answer-input] {
  width: 100%;
  min-height: 66px;
  padding: 8px 18px;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  color: var(--ink);
  background: white;
  font-size: 34px;
  font-weight: 900;
  text-align: center;
}

.answer-button,
.solid-button,
.outline-button,
.ghost-button,
.danger-button,
.text-button,
.keypad-button {
  padding: 0 18px;
  font-weight: 900;
}

.answer-button,
.solid-button,
.keypad-button.enter {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.answer-button:hover,
.solid-button:hover,
.keypad-button.enter:hover {
  background: var(--accent-strong);
}

.outline-button,
.ghost-button,
.text-button {
  background: var(--surface);
  color: var(--ink);
}

.ghost-button {
  min-height: 38px;
  padding: 0 13px;
  background: rgba(255, 255, 255, 0.72);
}

.text-button {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.danger-button {
  background: var(--rose-soft);
  border-color: #fecdd3;
  color: #9f1239;
}

.compact {
  min-height: 38px;
  padding: 0 13px;
}

.feedback {
  min-height: 28px;
  margin: 0;
  font-size: 20px;
  font-weight: 900;
}

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

.feedback.wrong {
  color: var(--rose);
}

.touch-keypad {
  display: none;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.main.touch-entry .touch-keypad {
  display: grid;
}

.keypad-button {
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.keypad-button.utility {
  background: var(--surface-2);
}

.main.touch-entry .answer-button {
  display: none;
}

.main.touch-entry .answer-form {
  grid-template-columns: minmax(120px, 220px);
  justify-content: center;
}

.shake {
  animation: shake 180ms linear;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-8px);
  }
  75% {
    transform: translateX(8px);
  }
}

.result-hero {
  display: grid;
  gap: 8px;
  justify-items: center;
  text-align: center;
  padding: 28px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.result-hero h1 {
  font-size: 48px;
}

.score-number {
  font-size: 112px;
  line-height: 0.95;
  color: var(--accent);
  font-weight: 1000;
}

.score-caption {
  color: var(--muted);
  font-weight: 900;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.summary-card {
  min-height: 102px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.summary-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.summary-card strong {
  font-size: 30px;
  line-height: 1;
}

.result-actions {
  justify-content: center;
}

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

.detail-section {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.fact-list {
  display: grid;
  gap: 8px;
}

.fact-row {
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--surface-2);
}

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

.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  min-height: 28px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 13px;
}

.tag.fast {
  color: #166534;
  background: var(--mint-soft);
}

.tag.mid {
  color: #92400e;
  background: var(--amber-soft);
}

.tag.slow,
.tag.wrong {
  color: #9f1239;
  background: var(--rose-soft);
}

.empty-state {
  min-height: 74px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 6px;
  font-weight: 800;
  text-align: center;
  padding: 16px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.legend .fast {
  background: var(--mint);
}

.legend .mid {
  background: var(--amber);
}

.legend .slow {
  background: var(--rose);
}

.heatmap {
  display: grid;
  grid-template-columns: repeat(10, minmax(38px, 1fr));
  gap: 6px;
}

.heatmap-cell {
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid rgba(23, 32, 51, 0.08);
  text-align: center;
  font-weight: 900;
}

button.heatmap-cell {
  appearance: none;
  cursor: pointer;
}

button.heatmap-cell:disabled {
  cursor: default;
}

button.heatmap-cell:not(:disabled):hover {
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.14);
}

.heatmap-cell.header {
  min-height: 38px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.heatmap-cell.no-data {
  color: var(--muted);
  background: var(--surface-2);
}

.heatmap-cell.fast {
  background: var(--mint-soft);
  color: #166534;
}

.heatmap-cell.mid {
  background: var(--amber-soft);
  color: #92400e;
}

.heatmap-cell.slow {
  background: var(--rose-soft);
  color: #9f1239;
}

.heatmap-fact {
  font-size: 14px;
}

.heatmap-time {
  font-size: 12px;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 6px;
  background: var(--surface-2);
  font-weight: 900;
}

.history-date {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.fact-detail {
  scroll-margin-top: 16px;
}

.attempt-list {
  display: grid;
  gap: 8px;
}

.attempt-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  padding: 9px 10px;
  border-radius: 6px;
  background: var(--surface-2);
}

.attempt-row.wrong {
  background: var(--rose-soft);
}

.attempt-main {
  display: grid;
  gap: 2px;
}

.attempt-main span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.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;
}

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  .home-grid,
  .result-columns {
    grid-template-columns: 1fr;
  }

  .home-grid {
    align-items: start;
    min-height: 0;
  }

  h1 {
    font-size: 56px;
  }

  .problem {
    font-size: 108px;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

}

@media (max-width: 620px) {
  .topbar,
  .quiz-status,
  .stats-heading,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .stats-actions,
  .result-actions {
    width: 100%;
  }

  .top-actions > *,
  .stats-actions > *,
  .result-actions > * {
    flex: 1;
  }

  .main {
    width: min(100% - 20px, 1120px);
    padding-top: 10px;
  }

  .brand {
    font-size: 18px;
  }

  h1 {
    font-size: 36px;
  }

  .problem {
    font-size: 76px;
  }

  .main.touch-entry {
    padding-top: 4px;
    padding-bottom: 8px;
  }

  .main.touch-entry .quiz-layout {
    gap: 8px;
    min-height: calc(100dvh - 96px);
    padding-top: 0;
  }

  .main.touch-entry .quiz-status {
    align-items: center;
    flex-direction: row;
  }

  .main.touch-entry .eyebrow {
    margin-bottom: 2px;
  }

  .main.touch-entry .progress-text {
    font-size: 24px;
  }

  .main.touch-entry .timer-pill {
    min-width: 72px;
    padding: 6px 10px;
  }

  .main.touch-entry .problem-panel {
    gap: 8px;
    padding: 12px;
  }

  .main.touch-entry .problem {
    font-size: 64px;
  }

  .main.touch-entry input[data-answer-input] {
    min-height: 48px;
    font-size: 28px;
  }

  .main.touch-entry .feedback {
    min-height: 22px;
    font-size: 16px;
  }

  .main.touch-entry .keypad-button {
    min-height: 48px;
  }

  .result-hero h1 {
    font-size: 34px;
  }

  .score-number {
    font-size: 64px;
  }

  .summary-card strong {
    font-size: 24px;
  }

  .number-board,
  .heatmap {
    gap: 4px;
  }

  .number-board {
    padding: 8px;
  }

  .board-corner,
  .board-header,
  .board-cell {
    border-radius: 4px;
    font-size: 12px;
  }

  .answer-form {
    grid-template-columns: 1fr;
  }

  .answer-button {
    min-height: 54px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .fact-row,
  .history-row,
  .attempt-row {
    grid-template-columns: 1fr auto;
  }

  .fact-row .tag:first-of-type,
  .attempt-main,
  .history-date {
    grid-column: 1 / -1;
  }

  .heatmap {
    overflow-x: auto;
    grid-template-columns: repeat(10, 48px);
    padding-bottom: 4px;
  }
}
