:root {
  color-scheme: light;
  --ink: #172622;
  --muted: #65736d;
  --paper: #fffdf8;
  --line: rgba(35, 71, 62, 0.16);
  --accent: #c83f37;
  --accent-dark: #9f2f2a;
  --safe: #1f8c7e;
  --warning: #d8952f;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(180deg, rgba(248, 253, 250, 0.94), rgba(237, 247, 244, 0.96)),
    #edf7f4;
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  overflow-x: hidden;
  touch-action: manipulation;
}

button {
  font: inherit;
}

.game-app {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(0.75rem, 2.4vw, 1.5rem);
  display: grid;
  grid-template-columns: minmax(280px, 0.58fr) minmax(280px, 0.42fr);
  gap: clamp(0.75rem, 2.4vw, 1.5rem);
  align-items: center;
}

.play-area,
.hud {
  min-width: 0;
}

.play-area {
  display: grid;
  justify-items: center;
}

.board-shell {
  width: min(100%, 420px, 74vh);
  aspect-ratio: 3 / 4;
  padding: clamp(0.45rem, 1.2vw, 0.75rem);
  border: 1px solid rgba(36, 80, 70, 0.24);
  border-radius: 8px;
  background: #f9f1df;
  box-shadow: 0 22px 64px rgba(35, 58, 52, 0.18);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: #edf7f4;
}

.hud {
  display: grid;
  gap: 0.85rem;
  align-content: center;
}

.title-block,
.score-grid > div,
.status-text,
.help-text,
.modal-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 12px 28px rgba(37, 61, 54, 0.08);
}

.title-block {
  padding: clamp(0.85rem, 2vw, 1.15rem);
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--safe);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.8vw, 2rem);
  line-height: 1.18;
  letter-spacing: 0;
}

.title-block p:last-child {
  margin: 0.55rem 0 0;
  color: #495852;
  font-size: 0.95rem;
  line-height: 1.65;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
  margin: 0;
}

.score-grid > div {
  min-height: 74px;
  padding: 0.65rem 0.55rem;
}

.score-grid dt {
  margin: 0 0 0.25rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.score-grid dd {
  margin: 0;
  font-size: clamp(1rem, 2vw, 1.35rem);
  font-weight: 900;
  line-height: 1.05;
}

.stage-select,
.modal-stage-select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 12px 28px rgba(37, 61, 54, 0.08);
}

.stage-select {
  display: grid;
  gap: 0.45rem;
  padding: 0.65rem;
}

.stage-select-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.55rem;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
}

.stage-select-head small,
.modal-stage-select p {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.stage-picker {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.35rem;
}

.stage-button {
  min-height: 46px;
  border: 1px solid rgba(31, 140, 126, 0.22);
  border-radius: 8px;
  background: linear-gradient(180deg, #fffef9, #f2ead8);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.stage-button span,
.stage-button small {
  display: block;
  line-height: 1.05;
}

.stage-button span {
  font-size: 1rem;
}

.stage-button small {
  margin-top: 0.18rem;
  color: #66726d;
  font-size: 0.58rem;
  font-weight: 900;
}

.stage-button:hover,
.stage-button.is-selected {
  border-color: rgba(199, 63, 55, 0.72);
  background: linear-gradient(180deg, #fff4df, #ffd77f);
  color: #3a211c;
}

.modal-stage-select {
  display: grid;
  gap: 0.45rem;
  margin: 0.75rem 0;
  padding: 0.7rem;
}

.status-text,
.help-text {
  margin: 0;
  padding: 0.75rem 0.85rem;
  color: #4f463f;
  font-size: 0.9rem;
  line-height: 1.6;
}

.button-row,
.pull-panel,
.modal-actions {
  display: grid;
  gap: 0.5rem;
}

.button-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.button-row button,
.pull-button,
.modal-actions button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #df5d53, #b73530);
  color: #fff;
  font-weight: 900;
  box-shadow: inset 0 -3px 0 rgba(74, 21, 18, 0.22);
  cursor: pointer;
}

.button-row button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.button-row button:hover:not(:disabled),
.pull-button:hover,
.modal-actions button:hover {
  background: linear-gradient(180deg, #e86c61, #c13c35);
}

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

.pull-button {
  min-height: 76px;
  display: grid;
  gap: 0.16rem;
  place-items: center;
}

.pull-button span {
  font-size: 1.04rem;
}

.pull-button small {
  color: rgba(255, 255, 255, 0.86);
  font-size: 0.78rem;
  font-weight: 800;
}

.pull-button.is-active {
  background: linear-gradient(180deg, #2ba58e, #1c776c);
}

.game-modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(19, 35, 31, 0.18);
  backdrop-filter: blur(8px);
}

.game-modal[hidden] {
  display: none;
}

.modal-panel {
  width: min(410px, 100%);
  padding: clamp(1rem, 4vw, 1.35rem);
}

.modal-kicker {
  margin: 0 0 0.45rem;
  color: var(--safe);
  font-size: 0.82rem;
  font-weight: 900;
}

.modal-panel h2 {
  margin: 0;
  font-size: clamp(1.35rem, 6vw, 1.85rem);
  letter-spacing: 0;
}

.modal-panel p {
  line-height: 1.65;
}

.modal-score {
  padding: 0.7rem 0.75rem;
  border-radius: 8px;
  background: #fff7df;
  font-weight: 900;
}

.modal-actions {
  grid-template-columns: 1fr;
}

.modal-actions button {
  min-height: 52px;
}

#modal-title-button {
  background: #2d7469;
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .game-app {
    width: min(100vw, 56.25vh);
    min-height: 100svh;
    padding: 0.55rem;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 0.5rem;
  }

  .board-shell {
    width: 100%;
    max-height: 63svh;
  }

  .title-block,
  .help-text {
    display: none;
  }

  .hud {
    gap: 0.5rem;
  }

  .score-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.35rem;
  }

  .score-grid > div {
    min-height: 56px;
    padding: 0.45rem 0.35rem;
  }

  .score-grid dt {
    font-size: 0.62rem;
  }

  .score-grid dd {
    font-size: 0.92rem;
  }

  .stage-select {
    padding: 0.45rem;
  }

  .stage-select-head small {
    display: none;
  }

  .stage-button {
    min-height: 34px;
    padding: 0.2rem 0;
  }

  .stage-button span {
    font-size: 0.82rem;
  }

  .stage-button small {
    display: none;
  }

  .status-text {
    padding: 0.55rem 0.65rem;
    font-size: 0.78rem;
    line-height: 1.45;
  }

  .button-row button {
    min-height: 42px;
    font-size: 0.82rem;
  }

  .pull-button {
    min-height: 58px;
  }

  .pull-button span {
    font-size: 0.9rem;
  }

  .pull-button small {
    font-size: 0.68rem;
  }
}

@media (max-width: 380px) {
  .board-shell {
    max-height: 59svh;
  }

  .status-text {
    display: none;
  }
}
