:root {
  color-scheme: light;
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  color: #1e293b;
  background: #f0f4f8;
  --blue: #1d4ed8;
  --border: #c8d4e4;
  --muted: #475569;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
.app { width: min(100%, 660px); margin: auto; padding: 24px 12px; }
h1 { margin: 0 0 16px; color: var(--blue); font-size: clamp(1.5rem, 5vw, 2rem); }
h2 { margin: 0; font-size: 1.4rem; }
.panel { padding: clamp(8px, 3vw, 24px); border: 1px solid var(--border); border-radius: 12px; background: #fff; }

fieldset { margin: 0 0 20px; padding: 0; border: 0; }
legend { margin-bottom: 8px; padding: 0; font-weight: 700; }
.choices, .result-actions { display: flex; gap: 8px; }
.choices label { position: relative; flex: 1; }
.choices input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.choices span { display: block; padding: 10px 4px; border: 1px solid var(--border); border-radius: 8px; text-align: center; cursor: pointer; }
.choices small { display: block; color: var(--muted); }
.choices input:checked + span { border-color: var(--blue); background: #eaf1ff; color: #1742a0; font-weight: 700; }
.help { color: var(--muted); line-height: 1.6; }

button {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f6f8fc;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover { background: #e9eff8; }
button:focus-visible, .choices input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 3px; }
.primary { border-color: var(--blue); background: var(--blue); color: #fff; }
.primary:hover { background: #1742a0; }
.start { width: 100%; }

.game-summary { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; font-weight: 700; }
.timer, .board, .problem { font-variant-numeric: tabular-nums; }
.timer { color: #1742a0; font-size: 1.18em; font-weight: 750; }
.board { width: 100%; table-layout: fixed; border-collapse: collapse; text-align: center; }
.board td, .board th { height: 32px; border: 1px solid var(--border); padding: 0; font-size: clamp(10px, 3.13vw, 16px); }
.board th { background: #eaf1ff; }
.board td { font-weight: 600; }
.board .current { position: relative; z-index: 1; outline: 2px solid var(--blue); outline-offset: -2px; background: #dbeafe; }
.board .solved { color: #145a45; background: #eff9f4; }
.problem { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 16px 0 0; font-size: 1.45rem; font-weight: 750; }
.board input {
  display: block;
  width: 100%;
  height: 28px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
}
.board .current:focus-within { outline-width: 3px; }
.board .current:has([aria-invalid="true"]) { outline-color: #a12b1c; }
#answer-preview { min-width: 4ch; max-width: 40%; overflow: hidden; border-bottom: 2px solid var(--blue); color: #1742a0; text-align: center; white-space: nowrap; }
.feedback { min-height: 1.45em; margin: 4px 0 8px; color: #922617; font-size: .875rem; text-align: center; }
.keypad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; max-width: 360px; margin: auto; }
.keypad button { font-size: 1.2rem; }
.keypad .edit-key { grid-column: span 2; font-size: .9rem; }
.result-time { margin: 8px 0 0; }
#result-settings { margin: 6px 0 12px; color: var(--muted); }
.result-actions { flex-wrap: wrap; margin-top: 16px; }
.result-actions button { flex: 1 1 135px; padding: 0 8px; }

@media (max-width: 400px) {
  .app { padding: 12px 6px; }
  .panel { padding: 8px; }
  .board td, .board th { height: 28px; }
}

@media (max-width: 520px) {
  .board input { width: 138%; height: 24px; transform: scale(.72); transform-origin: left center; }
}
