﻿:root {
  --bg-top: #f8f3df;
  --bg-bottom: #f3e3c2;
  --panel: rgba(255, 251, 239, 0.9);
  --panel-strong: #fff7e3;
  --text-main: #28313a;
  --text-soft: #5d6770;
  --accent: #c55b2d;
  --accent-dark: #8b3514;
  --line: rgba(63, 49, 27, 0.14);
  --button-bg: #fffdf6;
  --button-shadow: 0 10px 26px rgba(87, 60, 19, 0.14);
  --focus-ring: #0d6470;
  --content-width: min(980px, calc(100vw - 24px));
  --base-size: 18px;
}

* {
  box-sizing: border-box;
}

html {
  font-size: var(--base-size);
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "BIZ UDPGothic", "Yu Gothic UI", "Hiragino Sans", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.85), transparent 32%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body.large-text {
  --base-size: 20px;
}

body.high-contrast {
  --bg-top: #f9f7ef;
  --bg-bottom: #e8deb3;
  --panel: rgba(255, 255, 255, 0.96);
  --panel-strong: #fffcea;
  --text-main: #121212;
  --text-soft: #262626;
  --accent: #8a3200;
  --accent-dark: #401200;
  --line: rgba(0, 0, 0, 0.22);
  --button-bg: #ffffff;
  --focus-ring: #003f63;
}

body.records-open {
  overflow: hidden;
}

.is-hidden {
  display: none !important;
}

button,
canvas,
select {
  touch-action: manipulation;
}

button,
select {
  border: 2px solid transparent;
  border-radius: 20px;
  background: var(--button-bg);
  color: var(--text-main);
  box-shadow: var(--button-shadow);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  min-height: 60px;
  padding: 0.7rem 1rem;
  transition: transform 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

button:hover,
select:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
select:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

.app-shell {
  width: var(--content-width);
  margin: 0 auto;
  padding: 20px 0 36px;
}

.hero {
  padding: 18px 8px 10px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 0.45rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-dark);
}

.hero h1,
.records-head h2,
.course-panel h2 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 1.08;
}

.records-head h2,
.course-panel h2 {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
}

.lead {
  width: min(44rem, calc(100vw - 40px));
  margin: 0.9rem auto 0;
  color: var(--text-soft);
  line-height: 1.6;
}

.game-panel,
.tips-card,
.records-panel,
.course-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 32px;
  box-shadow: 0 20px 40px rgba(87, 60, 19, 0.12);
  backdrop-filter: blur(10px);
}

.game-panel {
  padding: 18px;
}

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

.status-card,
.records-summary-card {
  padding: 0.9rem 1rem;
  border-radius: 22px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.status-card-clickable {
  display: grid;
  gap: 0.45rem;
}

.records-mini-btn {
  min-height: 44px;
  padding: 0.45rem 0.8rem;
  font-size: 0.9rem;
}

.status-label {
  display: block;
  color: var(--text-soft);
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
}

.status-card strong,
.records-summary-card strong {
  font-size: clamp(1.3rem, 2vw, 1.8rem);
}

.canvas-frame {
  margin-top: 16px;
  border-radius: 30px;
  overflow: hidden;
  border: 1px solid rgba(73, 55, 24, 0.16);
  background: #e9d5aa;
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  touch-action: none;
}

.message-text {
  margin: 14px 4px 2px;
  min-height: 1.6em;
  text-align: center;
  font-weight: 700;
  color: var(--accent-dark);
}

.start-row {
  margin-top: 10px;
}

.start-btn-wide {
  width: 100%;
  min-height: 64px;
  font-size: 1.08rem;
}

.controls {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

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

.button-row button {
  flex: 1 1 180px;
}

.action-row button {
  flex-basis: calc(33.333% - 8px);
}

.difficulty-row button {
  flex-basis: 200px;
}

.mode-row button {
  flex-basis: calc(50% - 6px);
}

.primary-btn,
.choice-btn.is-active {
  background: linear-gradient(180deg, #ffe2ba, #ffc789);
  border-color: rgba(139, 53, 20, 0.22);
}

.tips-card {
  margin-top: 16px;
  padding: 20px 22px 18px;
}

.tips-card h2 {
  margin: 0 0 0.7rem;
  font-size: 1.2rem;
}

.tips-card ul {
  margin: 0;
  padding-left: 1.3rem;
  line-height: 1.7;
}

.keyboard-note {
  margin: 1rem 0 0;
  color: var(--text-soft);
}

kbd {
  padding: 0.15rem 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-family: inherit;
  font-weight: 700;
}

.records-overlay,
.course-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 18px;
}

.course-overlay {
  z-index: 10000;
}

.records-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(52, 40, 18, 0.36);
}

.records-panel,
.course-panel {
  position: relative;
  z-index: 1;
  width: min(980px, calc(100vw - 20px));
  max-height: min(92vh, 980px);
  overflow: auto;
  padding: 18px;
}

.course-panel {
  width: min(760px, calc(100vw - 20px));
}

.records-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.records-eyebrow {
  margin-bottom: 0.35rem;
}

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

.records-field {
  display: grid;
  gap: 0.45rem;
}

.records-field span {
  color: var(--text-soft);
  font-weight: 700;
}

.records-field select {
  width: 100%;
}

.course-help {
  margin: 14px 0 0;
  color: var(--text-soft);
}

.course-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.course-card {
  display: grid;
  gap: 0.25rem;
  text-align: left;
  min-height: 88px;
  padding: 1rem 1.1rem;
}

.course-card-title {
  font-size: 1.05rem;
}

.course-card-meta {
  color: var(--text-soft);
  font-size: 0.92rem;
  font-weight: 600;
}

.course-card.is-active {
  background: linear-gradient(180deg, #ffe2ba, #ffc789);
  border-color: rgba(139, 53, 20, 0.24);
}

.records-summary {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 16px;
}

.records-date-quicklist {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  max-height: min(44vh, 480px);
  overflow-y: auto;
  padding-right: 4px;
}

.records-date-chip {
  min-height: 62px;
  padding: 0.75rem 0.95rem;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text-main);
  box-shadow: none;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  text-align: left;
}

.records-date-chip.is-selected {
  background: linear-gradient(180deg, #ffe2ba, #ffc789);
  border-color: rgba(139, 53, 20, 0.28);
}

.records-date-chip.is-fastest {
  background: linear-gradient(180deg, #fff0a7, #ffd45c);
  border-color: rgba(147, 101, 9, 0.34);
  color: #5c3a00;
}

.records-date-chip.is-selected.is-fastest {
  background: linear-gradient(180deg, #ffe37e, #ffbf47);
  border-color: rgba(120, 73, 0, 0.42);
}

.records-date-chip-date {
  font-size: 1rem;
}

.records-date-chip-time {
  color: var(--text-soft);
  font-size: 0.98rem;
  white-space: nowrap;
}

.records-date-chip.is-fastest .records-date-chip-time {
  color: #5c3a00;
}

.records-empty-text {
  margin: 16px 0 8px;
  color: var(--accent-dark);
  font-weight: 700;
}

.records-list-wrap {
  margin-top: 10px;
}

.records-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.records-list li {
  padding: 0.9rem 1rem;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.56);
}

.records-item-title {
  display: block;
  font-weight: 700;
}

.records-item-meta {
  display: block;
  margin-top: 0.2rem;
  color: var(--text-soft);
}

@media (min-width: 1024px) {
  .app-shell {
    width: min(940px, calc(100vw - 32px));
    padding-top: 12px;
    padding-bottom: 24px;
  }

  .hero {
    padding: 10px 8px 8px;
  }

  .hero h1 {
    font-size: clamp(2rem, 3vw, 2.9rem);
  }

  .lead {
    width: min(38rem, calc(100vw - 72px));
    margin-top: 0.55rem;
    font-size: 0.96rem;
  }

  .game-panel {
    padding: 14px;
  }

  .status-strip,
  .canvas-frame,
  .start-row,
  .controls {
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
  }

  .status-strip {
    gap: 10px;
  }

  .status-card,
  .records-summary-card {
    padding: 0.75rem 0.85rem;
  }

  .status-card strong,
  .records-summary-card strong {
    font-size: clamp(1.2rem, 1.7vw, 1.55rem);
  }

  .canvas-frame {
    margin-top: 12px;
  }

  .message-text {
    margin-top: 12px;
    font-size: 0.98rem;
  }

  .start-row {
    margin-top: 8px;
  }

  .start-btn-wide {
    min-height: 58px;
  }

  .controls {
    gap: 10px;
    margin-top: 12px;
  }

  .button-row {
    gap: 10px;
  }

  .button-row button {
    min-height: 54px;
    padding: 0.6rem 0.9rem;
  }

  .tips-card {
    margin-top: 12px;
    padding: 16px 18px 16px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100vw - 16px, 760px);
    padding-top: 12px;
    padding-bottom: 24px;
  }

  .game-panel,
  .tips-card,
  .records-panel,
  .course-panel {
    border-radius: 24px;
  }

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

  .game-panel,
  .records-panel,
  .course-panel {
    padding: 12px;
  }

  .tips-card {
    padding: 16px;
  }
}

@media (max-width: 520px) {
  body {
    background:
      radial-gradient(circle at top center, rgba(255, 255, 255, 0.72), transparent 30%),
      linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  }

  .hero h1,
  .records-head h2,
  .course-panel h2 {
    font-size: clamp(1.8rem, 9vw, 2.5rem);
  }

  .lead {
    width: auto;
    margin-inline: 8px;
  }

  .button-row button,
  .records-head button,
  .records-field select,
  .course-panel button {
    min-height: 64px;
    flex-basis: calc(50% - 6px);
  }

  .difficulty-row button,
  .records-grid,
  .records-summary {
    grid-template-columns: 1fr;
  }

  .mode-row button {
    flex-basis: 100%;
  }

  .records-head {
    flex-direction: column;
  }
}

@media (max-width: 390px) {
  body {
    --base-size: 16px;
  }

  .app-shell {
    width: min(100vw - 10px, 760px);
    padding-top: 8px;
    padding-bottom: 18px;
  }

  .hero {
    padding: 10px 6px 8px;
  }

  .lead {
    margin-top: 0.55rem;
    line-height: 1.45;
  }

  .game-panel,
  .records-panel,
  .course-panel {
    padding: 8px;
    border-radius: 20px;
  }

  .tips-card {
    margin-top: 12px;
    padding: 14px 12px 14px;
    border-radius: 20px;
  }

  .status-strip {
    gap: 8px;
  }

  .status-card,
  .records-summary-card {
    padding: 0.7rem 0.75rem;
    border-radius: 18px;
  }

  .status-label {
    font-size: 0.82rem;
    margin-bottom: 0.28rem;
  }

  .status-card strong,
  .records-summary-card strong {
    font-size: 1.55rem;
  }

  .records-mini-btn {
    min-height: 40px;
    padding: 0.3rem 0.55rem;
    font-size: 0.84rem;
  }

  .canvas-frame {
    margin-top: 10px;
  }

  .message-text {
    margin-top: 12px;
    font-size: 0.94rem;
  }

  .start-row {
    margin-top: 8px;
  }

  .start-btn-wide {
    min-height: 58px;
    font-size: 1rem;
  }

  .controls {
    gap: 8px;
    margin-top: 10px;
  }

  .button-row {
    gap: 8px;
  }

  .button-row button,
  .records-head button,
  .records-field select,
  .course-panel button {
    min-height: 56px;
    padding: 0.55rem 0.7rem;
  }
}
