:root {
  color-scheme: light;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  color: #263332;
  background: #f4f9f6;
  --ink: #263332;
  --muted: #536b62;
  --line: #c9ded6;
  --strong: #175847;
  --focus: #2f8f70;
}

* { box-sizing: border-box; }
body { margin: 0; line-height: 1.65; }
[hidden] { display: none !important; }
a { color: #185e49; text-underline-offset: 0.17em; }
a:focus-visible, button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
button { font: inherit; cursor: pointer; touch-action: manipulation; }
button[aria-disabled="true"], button:disabled { cursor: default; }
button:disabled { opacity: 0.55; }
h1, h2, p, dl, dd { margin: 0; }
h2 { line-height: 1.35; }
h2[tabindex="-1"]:focus { outline: none; }

.page {
  width: min(1120px, calc(100% - 32px));
  margin-inline: auto;
}
.breadcrumbs {
  display: flex;
  gap: 0.5rem;
  margin: 16px 0 10px;
  font-size: 0.875rem;
  color: var(--muted);
}
.page-heading { margin: 0 0 19px; }
h1 { font-size: clamp(1.65rem, 4.4vw, 2.35rem); letter-spacing: 0.02em; line-height: 1.3; }
.page-heading p { margin-top: 6px; color: var(--muted); }

.game {
  --toolbar-space: 0px;
  text-size-adjust: 100%;
  border: 1px solid #c7ded4;
  border-radius: 16px;
  background: #fcfefd;
  box-shadow: 0 12px 34px #173d3020;
}
.game:has(> .game-tools:not([hidden])) { --toolbar-space: 44px; }
.view { padding: clamp(16px, 3.5vw, 36px); }
.view-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}
.mode-label {
  padding: 3px 10px;
  border: 1px solid #c3ded1;
  border-radius: 20px;
  color: var(--strong);
  background: #edf8f1;
  font-size: 0.875rem;
  font-weight: 800;
}
.primary, .secondary, .text-button {
  min-height: 44px;
  padding: 7px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 800;
}
.primary { color: #fff; border-color: var(--strong); background: var(--strong); }
.secondary { color: var(--strong); background: #fff; }
.text-button { padding-inline: 10px; color: var(--strong); background: #f4faf6; }
@media (hover: hover) {
  .primary:hover { background: #24745d; }
  .secondary:not(:disabled):hover, .text-button:hover { background: #e7f5ed; }
}

.difficulty-view {
  min-height: 445px;
  display: grid;
  grid-template-columns: minmax(245px, 0.84fr) minmax(0, 1.16fr);
  align-items: center;
  gap: clamp(18px, 5vw, 58px);
}
.difficulty-view h2 { font-size: clamp(1.6rem, 3.1vw, 2.4rem); }
.difficulty-buttons { display: grid; gap: 10px; margin-top: 18px; }
.difficulty-button {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 10px;
  text-align: left;
  align-items: center;
  min-height: 68px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f4faf6;
  color: var(--strong);
}
.difficulty-button strong { font-size: 1.1rem; }
.difficulty-button span { font-size: 0.875rem; color: var(--muted); }
.difficulty-button .difficulty-detail { grid-row: 2; }
.difficulty-button .difficulty-progress { grid-column: 2; grid-row: 1 / span 2; font-weight: 800; }
@media (hover: hover) {
  .difficulty-button:hover { background: #e8f7ee; border-color: #7fb49f; }
}

.cover-frame {
  width: 100%;
  aspect-ratio: 1.36;
  border: 1px solid #d5e6db;
  border-radius: 14px;
  overflow: hidden;
  background: #d8eee7;
}
.cover-frame canvas { display: block; width: 100%; height: 100%; }

.picker-view { max-width: 650px; margin-inline: auto; }
.picker-heading {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.picker-heading p { margin-top: 2px; color: var(--muted); }
.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  border: 8px solid #315650;
  border-radius: 12px;
  background: #315650;
  padding: 1px;
}
.puzzle-pane {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 49px;
  padding: 4px 3px;
  border: 1px solid #badbd5;
  border-radius: 3px;
  background: linear-gradient(145deg, #ecf7f5, #d1e9e6);
  color: #28514a;
  font-size: clamp(1rem, 3.6vw, 1.35rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.puzzle-pane.is-cleared { background: linear-gradient(145deg, #f7fff8, #bfe7c8); }
.puzzle-pane .check {
  position: absolute;
  top: 3px;
  right: 5px;
  font-size: clamp(0.88rem, 2.6vw, 1rem);
  line-height: 1;
  color: #145841;
}
.puzzle-pane.is-next { box-shadow: inset 0 0 0 2px #2a7965; }
.puzzle-pane:focus-visible { outline-color: #fff; outline-offset: -4px; }
@media (hover: hover) {
  .puzzle-pane:hover { background: #f5fffa; }
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(190px, 0.85fr);
  grid-template-areas: "board status" "board actions";
  grid-template-rows: auto 1fr;
  align-items: start;
  gap: 15px clamp(18px, 4vw, 52px);
  max-width: 870px;
  margin-inline: auto;
}
.play-status { grid-area: status; padding-top: 9px; }
.play-status h2 { font-size: clamp(1.3rem, 3.7vw, 1.75rem); }
.counters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 13px 0 11px; }
.counters div { background: #eef8f4; border: 1px solid #d7e9e2; border-radius: 8px; padding: 7px 10px; }
.counters dt { color: var(--muted); font-size: 0.875rem; font-weight: 700; }
.counters dd { color: var(--strong); font-size: 1.5rem; font-weight: 800; line-height: 1.35; }
.counters small { font-size: 0.85rem; }
#boardHint { color: var(--muted); font-size: 0.875rem; }
.board {
  --slots: 6;
  grid-area: board;
  display: grid;
  grid-template: repeat(var(--slots), minmax(0, 1fr)) / repeat(var(--slots), minmax(0, 1fr));
  width: min(100%, 478px, max(350px, calc(100svh - 355px)));
  aspect-ratio: 1;
  margin-inline: auto;
  min-width: 0;
}
#glass {
  grid-area: 2 / 2 / -1 / -1;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: block;
  border-radius: 8px;
}
.board-control {
  display: grid;
  place-items: center;
  align-self: center;
  justify-self: center;
  width: calc(100% - 2px);
  height: calc(100% - 2px);
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 1px solid #b6d7c9;
  border-radius: 8px;
  background: #e7f4ed;
  color: #1d644e;
  font-size: clamp(1.05rem, 4.3vw, 1.4rem);
  line-height: 1;
  font-weight: 800;
}
.board-control.is-empty, .board-control[aria-disabled="true"] {
  background: #f5faf7;
  color: #678177;
  border-color: #d7e7df;
}
.board-control.is-guided {
  border-color: #397859;
  background: #d7eedc;
  box-shadow: inset 0 0 0 2px #78a98d;
}
.board-control:focus-visible { outline-offset: -3px; }
@media (hover: hover) {
  .board-control:not(.is-empty):hover { background: #cceadd; }
}
.play-actions { grid-area: actions; min-width: 0; }
.result { min-height: 3.35em; color: var(--muted); font-weight: 700; }
.result.is-won { color: var(--strong); }
.result.is-lost { color: #82490f; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.page-details { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; margin: 21px 0 14px; }
.info-panel { border: 1px solid #d9e7e0; border-radius: 11px; background: #fcfefd; padding: 15px 18px; }
.info-panel h2 { font-size: 1.16rem; }
.info-panel p { margin-top: 6px; color: var(--muted); }
.info-panel ol, .info-panel ul { margin: 6px 0; padding-left: 1.4rem; }
.feedback { margin-bottom: 24px; }
.feedback > a { display: inline-block; margin-top: 5px; }
.fallback { padding: 12px; }

@media (max-width: 720px), (max-height: 500px) and (orientation: landscape) {
  .difficulty-view { grid-template-columns: 1fr; gap: 16px; min-height: 0; }
  .cover-frame { height: min(120px, 19svh); }
  .play-layout {
    grid-template-columns: minmax(0,1fr);
    grid-template-areas: "status" "board" "actions";
    grid-template-rows: auto;
    gap: 6px;
  }
  .play-status { padding-top: 0; }
  .play-status h2 { font-size: 1.15rem; }
  .counters { gap: 5px; margin-block: 4px; }
  .counters div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px;
    padding: 2px 5px;
  }
  .counters dt, .counters small, #boardHint, .result { font-size: 0.8125rem; }
  .counters dt, .counters dd { white-space: nowrap; }
  .counters dd { font-size: 1rem; }
  .board { width: min(100%, 380px, max(215px, calc(100svh - 206px - var(--toolbar-space)))); }
  .board-control { width: 100%; height: 100%; border-radius: 6px; }
  .result { line-height: 1.4; min-height: 2.8em; }
  .actions { gap: 4px; margin-top: 4px; }
  .actions button {
    flex: 1 1 0;
    min-width: 0;
    padding-inline: 5px;
    font-size: 0.8125rem;
    line-height: 1.2;
    overflow-wrap: anywhere;
  }
  .puzzle-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .puzzle-pane { min-height: 44px; }
  .page-details { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .page { width: calc(100% - 24px); }
  .view { padding: 13px; }
  .view-top { margin-bottom: 10px; }
  .difficulty-buttons { margin-top: 12px; }
  .page-heading { margin-bottom: 13px; }
  .difficulty-buttons { gap: 6px; }
  .difficulty-button { min-height: 48px; padding-block: 3px; }
}
@media (max-width: 389px) {
  .game:has(.play-view:not([hidden])) { margin-inline: -8px; }
  .play-view { padding: 6px 2px; }
  .play-view .view-top { margin-bottom: 4px; }
  .play-view .view-top, .play-status, .play-actions { margin-inline: 8px; }
  .play-status {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 3px 5px;
  }
  .play-status h2 { font-size: 0.875rem; white-space: nowrap; }
  .play-status .counters { margin: 0; }
  .play-status .counters div { padding-inline: 3px; }
  .play-status #boardHint { grid-column: 1 / -1; }
  .picker-heading { gap: 6px; }
  .picker-heading button { padding-inline: 7px; font-size: 0.8125rem; }
}
@media (min-width: 480px) and (max-height: 500px) and (orientation: landscape) {
  .view { padding: 8px 12px; }
  .difficulty-view {
    min-height: 0;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: 12px;
  }
  .difficulty-view h2 { font-size: 1.2rem; }
  .difficulty-buttons { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; margin-top: 5px; }
  .difficulty-button { display: block; min-height: 44px; padding: 4px; text-align: center; }
  .difficulty-button strong, .difficulty-button span { display: block; font-size: 0.8125rem; }
  .cover-frame { height: min(105px, 33svh); }
  .picker-view .view-top, .picker-heading { margin-bottom: 5px; }
  .picker-heading > div { display: flex; align-items: baseline; gap: 8px; }
  .puzzle-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); border-width: 6px; }
  .puzzle-pane { min-height: 44px; }
  .play-view {
    display: grid;
    grid-template-columns: minmax(0, min(calc(100% - 232px), 360px, calc(100svh - 18px - var(--toolbar-space)))) minmax(0, 1fr);
    grid-template-areas: "board nav" "board status" "board actions";
    grid-template-rows: auto auto 1fr;
    align-items: start;
    gap: 4px 12px;
  }
  .play-layout { display: contents; }
  .play-view .view-top { grid-area: nav; margin: 0; }
  .play-view .mode-label { padding-inline: 6px; white-space: nowrap; }
  .play-status { padding-top: 0; }
  .counters { margin-block: 4px; }
  .counters div { padding-inline: 3px; }
  .result { min-height: 0; }
  .board { width: 100%; }
  .board-control { width: 100%; height: 100%; }
}
@media (min-width: 550px) and (max-height: 500px) and (orientation: landscape) {
  .puzzle-grid { grid-template-columns: repeat(10, minmax(0, 1fr)); border-width: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}
