:root {
  --navy: #12345b;
  --navy-dark: #0c2949;
  --text: #17304f;
  --muted: #66788c;
  --line: #c9d3de;
  --page: #f7f5ef;
  --card: #fffdf8;
  --blue: #dceefe;
  --blue-border: #8dbde8;
  --green: #e5f3d8;
  --green-border: #9fc986;
  --yellow: #fff0bd;
  --yellow-border: #e6c35a;
  --red: #ef6464;
  --red-soft: #ffe4e4;
  --shadow: 0 14px 35px rgba(18, 52, 91, 0.10);
  --radius: 18px;
  --radius-small: 12px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(255,255,255,.9), transparent 35%),
    linear-gradient(135deg, #f9f7f0 0%, #f2f6f8 100%);
  color: var(--text);
  font-family:
    "Hiragino Sans",
    "Yu Gothic",
    "YuGothic",
    "Noto Sans JP",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 4px solid rgba(41, 129, 202, .30);
  outline-offset: 3px;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  min-height: calc(100vh - 28px);
  margin: 14px auto;
  background: rgba(255, 253, 248, .96);
  border: 1px solid rgba(18, 52, 91, .20);
  border-radius: 22px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topbar {
  min-height: 70px;
  padding: 10px 18px;
  background: linear-gradient(90deg, var(--navy-dark), var(--navy));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  letter-spacing: .05em;
}

.eyebrow {
  margin: 0 0 2px;
  font-size: .72rem;
  letter-spacing: .08em;
  opacity: .78;
}

.screen {
  display: none;
  min-height: calc(100vh - 112px);
  padding: clamp(20px, 4vw, 48px);
}

.screen.active {
  display: block;
  animation: screen-in .22s ease;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.hidden {
  display: none !important;
}

.hero-card,
.content-card {
  width: min(900px, 100%);
  margin: 0 auto;
}

.hero-card {
  text-align: center;
}

.subject-label {
  display: inline-flex;
  margin: 0 0 14px;
  padding: 7px 13px;
  border: 1px solid #bac7d3;
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 700;
  letter-spacing: .04em;
}

.hero-card h2,
.select-card h2,
.result-card h2 {
  margin: 0;
  color: var(--navy);
  font-size: clamp(2rem, 5vw, 3.5rem);
  letter-spacing: .07em;
}

.lead {
  margin: 12px 0 28px;
  color: var(--muted);
  font-weight: 600;
  line-height: 1.8;
}

.lead.small {
  margin-bottom: 24px;
}

.mode-list {
  display: grid;
  gap: 16px;
  width: min(760px, 100%);
  margin: 0 auto 18px;
}

.mode-card,
.challenge-card,
.dan-button {
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}

.mode-card:hover,
.challenge-card:hover,
.dan-button:hover,
.primary-button:hover,
.secondary-button:hover,
.outline-button:hover,
.small-button:hover,
.keypad button:hover {
  transform: translateY(-2px);
  filter: brightness(1.015);
}

.mode-card:active,
.challenge-card:active,
.dan-button:active,
.primary-button:active,
.secondary-button:active,
.outline-button:active,
.small-button:active,
.keypad button:active {
  transform: translateY(1px) scale(.99);
}

.mode-card {
  min-height: 92px;
  padding: 18px 26px;
  border-radius: 14px;
  display: grid;
  gap: 7px;
  text-align: center;
  box-shadow: 0 6px 12px rgba(18,52,91,.05);
}

.mode-card.blue,
.challenge-card.blue { background: var(--blue); border-color: var(--blue-border); }
.mode-card.green,
.challenge-card.green { background: var(--green); border-color: var(--green-border); }
.mode-card.yellow,
.challenge-card.yellow { background: var(--yellow); border-color: var(--yellow-border); }

.mode-name {
  font-size: clamp(1.2rem, 2.6vw, 1.7rem);
  font-weight: 800;
}

.mode-description {
  font-size: .92rem;
  color: #40556c;
  font-weight: 600;
}

.outline-button,
.small-button,
.primary-button,
.secondary-button {
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
}

.outline-button,
.small-button {
  background: #fff;
  border: 1px solid #aebcc9;
  color: var(--navy);
}

.outline-button {
  padding: 11px 22px;
}

.outline-button.compact {
  width: 100%;
  padding: 10px 12px;
}

.small-button {
  padding: 10px 16px;
}

.select-card {
  text-align: center;
}

.dan-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  width: min(760px, 100%);
  margin: 0 auto;
}

.dan-button {
  min-height: 94px;
  border-radius: 14px;
  background: #fff;
  font-size: clamp(1.25rem, 3vw, 1.9rem);
  font-weight: 800;
  box-shadow: 0 5px 13px rgba(18,52,91,.05);
}

.note {
  margin: 24px auto 0;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.7;
}

.challenge-list {
  width: min(820px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 16px;
}

.challenge-card {
  width: 100%;
  min-height: 108px;
  padding: 20px 24px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}

.challenge-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: clamp(1.15rem, 2.5vw, 1.65rem);
}

.challenge-card small {
  display: block;
  color: #40556c;
  font-size: .92rem;
  font-weight: 600;
  line-height: 1.6;
}

.arrow {
  font-size: 2.5rem;
  font-weight: 300;
}

.play-layout {
  width: min(1100px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 175px minmax(0, 1fr) 135px;
  gap: 18px;
  align-items: stretch;
}

.status-panel,
.problem-panel,
.timer-panel {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 7px 20px rgba(18,52,91,.06);
}

.status-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.status-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 900;
}

.status-subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.status-list,
.result-summary {
  margin: 0;
}

.status-list > div,
.result-summary > div {
  display: grid;
  gap: 4px;
  padding: 11px 0;
  border-bottom: 1px solid #e4e9ee;
}

.status-list dt,
.result-summary dt {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
}

.status-list dd,
.result-summary dd {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 900;
}

.lives-block {
  margin-top: auto;
}

.lives-block p {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
}

.lives {
  display: flex;
  gap: 7px;
  font-size: 1.45rem;
}

.problem-panel {
  padding: clamp(18px, 3vw, 34px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.feedback {
  min-height: 31px;
  margin-bottom: 8px;
  text-align: center;
  font-weight: 900;
  font-size: 1.05rem;
}

.feedback.correct { color: #2b7a35; }
.feedback.wrong { color: #bd3d3d; }

.problem-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(130px, 210px);
  gap: 18px;
  align-items: center;
  margin-bottom: 24px;
}

.problem-text,
.answer-display {
  min-height: 112px;
  border: 1px solid #aebbc8;
  border-radius: 14px;
  background: #fffdfa;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--navy);
  font-weight: 900;
}

.problem-text {
  padding: 12px 20px;
  font-size: clamp(2rem, 6vw, 4.1rem);
  letter-spacing: .06em;
  white-space: nowrap;
}

.answer-display {
  padding: 12px;
  font-size: clamp(2.2rem, 6vw, 4.3rem);
  letter-spacing: .04em;
}

.answer-display.placeholder {
  color: #b4bdc6;
}

.keypad {
  width: min(470px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 11px;
}

.keypad button {
  min-height: 64px;
  border: 1px solid #aebbc8;
  border-radius: 11px;
  background: #fff;
  color: var(--navy);
  font-size: clamp(1.25rem, 3vw, 1.7rem);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(18,52,91,.05);
}

.keypad .clear-key {
  background: var(--red-soft);
  border-color: #f1aaaa;
  font-size: 1.05rem;
}

.keypad .enter-key {
  background: var(--blue);
  border-color: var(--blue-border);
  font-size: 1.05rem;
}

.keyboard-note {
  margin: 16px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: .83rem;
  font-weight: 700;
}

.timer-panel {
  padding: 18px 10px;
  text-align: center;
  background: linear-gradient(180deg, #fffaf0, #fffdf8);
  border-color: #e9d796;
}

.timer-panel p {
  margin: 0 0 12px;
  color: #6d5a25;
  font-size: .9rem;
  font-weight: 900;
}

.timer-panel strong {
  display: block;
  font-size: 2.6rem;
  color: var(--navy);
}

.timer-panel span {
  color: var(--muted);
  font-size: .85rem;
  font-weight: 800;
}

.timer-ring {
  width: 70px;
  height: 70px;
  margin: 18px auto 0;
}

.timer-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-track,
.timer-progress {
  fill: none;
  stroke-width: 6;
}

.timer-track {
  stroke: #e6e6df;
}

.timer-progress {
  stroke: #7abb8b;
  stroke-linecap: round;
  stroke-dasharray: 132;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset .1s linear;
}

.result-card {
  text-align: center;
}

.result-card h2 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
}

.result-message {
  min-height: 1.5em;
  margin: 12px 0 20px;
  color: var(--muted);
  font-weight: 800;
}

.result-grid {
  display: grid;
  grid-template-columns: minmax(280px, .9fr) minmax(320px, 1.1fr);
  gap: 24px;
  text-align: left;
}

.result-summary,
.mistake-box {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.result-summary > div {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.result-summary dt {
  font-size: .98rem;
  color: var(--text);
}

.result-summary dd {
  font-size: 1.4rem;
}

.mistake-box h3 {
  margin: 0 0 14px;
  font-size: 1.2rem;
}

.mistake-list {
  max-height: 280px;
  overflow-y: auto;
  padding-right: 6px;
}

.mistake-item {
  padding: 11px 0;
  border-bottom: 1px solid #e4e9ee;
  line-height: 1.6;
}

.mistake-item strong {
  display: block;
}

.mistake-item span {
  color: var(--muted);
  font-size: .9rem;
}

.no-mistakes {
  margin: 0;
  color: #2b7a35;
  font-weight: 800;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 24px;
}

.primary-button,
.secondary-button {
  min-width: 190px;
  padding: 13px 20px;
}

.primary-button {
  border: 1px solid var(--blue-border);
  background: var(--blue);
}

.secondary-button {
  border: 1px solid #aebbc8;
  background: #f2f3f4;
}

.usage-dialog {
  width: min(560px, calc(100% - 30px));
  padding: 0;
  border: 0;
  border-radius: 18px;
  box-shadow: 0 22px 60px rgba(0,0,0,.26);
}

.usage-dialog::backdrop {
  background: rgba(12, 41, 73, .45);
}

.usage-dialog form {
  padding: 28px;
}

.usage-dialog h2 {
  margin-top: 0;
  color: var(--navy);
}

.usage-dialog p {
  line-height: 1.8;
}

@media (max-width: 900px) {
  .play-layout {
    grid-template-columns: 145px minmax(0, 1fr);
  }

  .timer-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: auto auto auto 70px;
    justify-content: center;
    align-items: center;
    gap: 10px;
  }

  .timer-panel p,
  .timer-panel strong,
  .timer-panel span,
  .timer-ring {
    margin: 0;
  }

  .timer-panel strong {
    font-size: 2rem;
  }

  .timer-ring {
    width: 50px;
    height: 50px;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .screen {
    min-height: calc(100vh - 70px);
    padding: 18px 14px;
  }

  .topbar {
    min-height: 64px;
  }

  .dan-grid {
    gap: 10px;
  }

  .dan-button {
    min-height: 72px;
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  .status-panel {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
    gap: 10px 18px;
  }

  .status-list {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .status-list > div {
    border: 1px solid #e1e6eb;
    border-radius: 10px;
    padding: 8px;
  }

  .lives-block {
    margin: 0;
  }

  .problem-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .problem-text,
  .answer-display {
    min-height: 84px;
  }

  .answer-display {
    min-height: 70px;
  }

  .timer-panel {
    grid-column: auto;
  }

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

  .result-actions {
    flex-direction: column;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }
}

@media (orientation: landscape) and (max-height: 650px) and (min-width: 700px) {
  .app-shell {
    min-height: calc(100vh - 12px);
    margin: 6px auto;
  }

  .topbar {
    min-height: 54px;
    padding-block: 7px;
  }

  .screen {
    min-height: calc(100vh - 66px);
    padding: 14px 20px;
  }

  .problem-panel {
    padding: 14px 24px;
  }

  .problem-row {
    margin-bottom: 12px;
  }

  .problem-text,
  .answer-display {
    min-height: 78px;
  }

  .keypad {
    gap: 7px;
  }

  .keypad button {
    min-height: 47px;
  }

  .keyboard-note {
    margin-top: 8px;
  }

  .status-panel,
  .timer-panel {
    padding: 12px;
  }

  .mode-card {
    min-height: 70px;
    padding: 12px 20px;
  }

  .mode-list {
    gap: 10px;
  }
}

/* 「マスターへの道」シリーズ共通UI */
:root{--navy:#3f8061;--navy-dark:#30664c;--text:#2f4037;--muted:#6b7b72;--line:#d6e0da;--page:#f4f7f5;--card:#fff;--blue:#e5edf7;--blue-border:#7897bd;--green:#e7f2e9;--green-border:#7aa384;--yellow:#f8edcf;--yellow-border:#d1ae5d;--red:#a35f5f;--red-soft:#f9e7e9;--shadow:0 8px 22px rgba(37,68,52,.08)}
body{background:#f4f7f5;font-family:-apple-system,BlinkMacSystemFont,"Hiragino Sans","Yu Gothic",sans-serif}
.app-shell{background:#fff;border-color:var(--line);border-radius:20px;box-shadow:var(--shadow)}
.topbar{min-height:72px;padding:10px 20px;background:#fff;color:var(--text);border-bottom:2px solid #dfe8e2}
.eyebrow{color:var(--navy-dark);font-weight:800;letter-spacing:.1em;opacity:1}
.topbar h1{display:flex;align-items:baseline;gap:.38em;font-size:1.55rem;letter-spacing:.02em}
.title-name{color:var(--navy-dark)}.title-series{font-size:.68em;color:var(--text)}
.hero-card{padding:clamp(20px,3vw,34px);background:#fff;border:1px solid var(--line);border-radius:18px;box-shadow:var(--shadow);text-align:center}
.mode-card,.dan-button,.challenge-card{border-radius:16px;box-shadow:0 4px 0 rgba(49,78,62,.13)}
.outline-button,.small-button,.primary-button,.secondary-button{border-radius:14px}
.outline-button,.small-button{background:#edf3ef;border-color:#c7d6cd;color:var(--navy-dark)}
.small-button{min-width:104px;min-height:50px}
.result-card{padding:30px 24px;border:1px solid var(--line);border-top:6px solid var(--navy);border-radius:18px;box-shadow:var(--shadow)}
.primary-button,.secondary-button{min-height:50px}
.primary-button{border-color:var(--navy);background:var(--navy);color:#fff}
.secondary-button{border-color:#c7d6cd;background:#edf3ef}
