:root {
  color-scheme: light;
  --ink: #111111;
  --paper: #fffef7;
  --yellow: #ffe600;
  --yellow-soft: #fff8a8;
  --blue: #1f65ff;
  --blue-soft: #dbe8ff;
  --pink: #ff4f8b;
  --pink-soft: #ffe0eb;
  --red: #ed332b;
  --muted: #686868;
  --shadow: 6px 7px 0 #111111;
  --small-shadow: 3px 4px 0 #111111;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: var(--yellow);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 1px 1px, rgba(17, 17, 17, 0.12) 1.2px, transparent 1.3px) 0 0 / 22px 22px,
    var(--yellow);
  font-size: 16px;
  line-height: 1.55;
}

button,
a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

button:focus-visible,
a:focus-visible,
[role="gridcell"]:focus-visible {
  outline: 4px solid var(--blue);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.site-shell {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.site-header {
  min-height: 82px;
  padding: 8px clamp(16px, 4vw, 52px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--yellow);
  border-bottom: 4px solid var(--ink);
  position: relative;
  z-index: 5;
}

.brand {
  display: inline-block;
  color: var(--ink);
  text-decoration: none;
  user-select: none;
}

.brand-logo {
  display: block;
  width: clamp(80px, 8.5vw, 90px);
  height: auto;
  pointer-events: none;
}

.header-button,
.icon-button {
  border: 3px solid var(--ink);
  color: var(--ink);
  background: var(--paper);
  font-weight: 900;
  cursor: pointer;
}

.header-button {
  min-height: 46px;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--small-shadow);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.header-button:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 5px 0 var(--ink);
}

.header-button:active {
  transform: translate(3px, 3px);
  box-shadow: none;
}

.header-button span {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  margin-right: 3px;
  border-radius: 50%;
  color: var(--yellow);
  background: var(--ink);
}

.game-shell {
  width: 100%;
  max-width: 1220px;
  margin: 0 auto;
  padding: clamp(18px, 4vw, 44px) clamp(14px, 3vw, 34px) 48px;
  flex: 1;
}

.panel {
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.eyebrow,
.toolbar-kicker,
.status-kicker {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 1000;
  letter-spacing: 0.14em;
}

.start-card {
  min-height: min(680px, calc(100vh - 190px));
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(340px, 0.95fr);
  align-items: stretch;
  overflow: hidden;
}

.start-copy {
  padding: clamp(28px, 6vw, 74px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.start-copy .eyebrow { margin-bottom: 14px; }

.start-copy h1 {
  max-width: 680px;
  margin: 0;
  font-size: clamp(2.4rem, 5.4vw, 4.35rem);
  line-height: 1.04;
  letter-spacing: -0.075em;
  font-weight: 1000;
}

.headline-line {
  display: block;
  width: fit-content;
  white-space: nowrap;
}

.headline-line.marker {
  background: linear-gradient(transparent 62%, var(--yellow) 62%);
}

.start-lead {
  max-width: 610px;
  margin: 26px 0 0;
  font-size: clamp(1rem, 2vw, 1.18rem);
  line-height: 1.8;
  font-weight: 750;
}

.start-lead strong { font-weight: 1000; }

.start-actions {
  margin-top: 30px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 13px;
}

.start-button,
.purchase-button,
.rematch-button {
  min-height: 58px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 1000;
  cursor: pointer;
  text-decoration: none;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.primary-button,
.rematch-button {
  color: var(--yellow);
  background: var(--ink);
  box-shadow: 5px 6px 0 var(--blue);
}

.primary-button:hover,
.rematch-button:hover {
  transform: translate(-2px, -2px);
  box-shadow: 7px 8px 0 var(--blue);
}

.secondary-button {
  background: var(--paper);
  box-shadow: var(--small-shadow);
}

.secondary-button:hover {
  transform: translate(-1px, -1px);
  background: var(--yellow-soft);
  box-shadow: 4px 5px 0 var(--ink);
}

.purchase-button {
  background: var(--yellow);
  box-shadow: 5px 6px 0 var(--pink);
}

.purchase-button:hover {
  transform: translate(-2px, -2px);
  background: var(--yellow-soft);
  box-shadow: 7px 8px 0 var(--pink);
}

.start-button:active,
.purchase-button:active,
.rematch-button:active {
  transform: translate(4px, 4px);
  box-shadow: none;
}

.choice-piece {
  width: 22px;
  aspect-ratio: 1;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-radius: 50%;
  box-shadow: inset 3px 3px 0 rgba(255, 255, 255, 0.42);
}

.yellow-choice .choice-piece {
  border-color: var(--yellow);
  background: var(--yellow);
}

.white-choice .choice-piece {
  border-color: var(--ink);
  background: #ffffff;
}

.start-visual {
  min-height: 510px;
  padding: clamp(28px, 5vw, 58px);
  display: grid;
  place-content: center;
  background: var(--ink);
  position: relative;
  overflow: hidden;
}

.visual-watermark {
  position: absolute;
  right: -12px;
  bottom: 4px;
  color: rgba(255, 230, 0, 0.12);
  font-size: clamp(3.1rem, 7vw, 6.7rem);
  line-height: 0.75;
  font-weight: 1000;
  writing-mode: vertical-rl;
  letter-spacing: -0.06em;
}

.preview-rules {
  width: min(420px, 72vw);
  display: grid;
  gap: 25px;
  position: relative;
  z-index: 1;
}

.preview-row {
  min-height: 132px;
  padding: 20px 22px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  border: 4px solid var(--ink);
  border-radius: 16px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 8px 10px 0 rgba(0, 0, 0, 0.42);
}

.preview-row.is-win { transform: rotate(-2.5deg); }
.preview-row.is-lose { transform: rotate(2deg); }

.preview-label {
  padding: 5px 8px;
  border-radius: 5px;
  color: var(--ink);
  background: var(--yellow);
  font-size: 0.72rem;
  font-weight: 1000;
  letter-spacing: 0.08em;
}

.preview-row.is-lose .preview-label {
  color: var(--paper);
  background: var(--blue);
}

.preview-pieces {
  display: flex;
  justify-content: center;
  gap: clamp(3px, 0.7vw, 8px);
}

.preview-pieces i {
  width: clamp(36px, 4vw, 48px);
  aspect-ratio: 1;
  display: block;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: inset 5px 5px 0 rgba(255, 255, 255, 0.42), 2px 3px 0 var(--ink);
}

.preview-row.is-lose .preview-pieces i { background: #ffffff; }

.preview-row strong {
  font-size: clamp(2.3rem, 5vw, 4rem);
  line-height: 1;
  letter-spacing: -0.08em;
}

.visual-caption {
  position: relative;
  z-index: 2;
  width: fit-content;
  margin: 30px auto 0;
  padding: 8px 13px;
  border-radius: 5px;
  color: var(--ink);
  background: var(--yellow);
  font-size: 0.9rem;
  font-weight: 1000;
  transform: rotate(-2deg);
}

.play-layout {
  display: grid;
  gap: 18px;
}

.game-toolbar {
  min-height: 53px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.game-toolbar > div {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.toolbar-kicker { font-size: 0.72rem; }

.turn-copy {
  font-size: clamp(1.35rem, 3vw, 2.15rem);
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.new-game-button {
  border: 0;
  padding: 8px;
  color: var(--ink);
  background: transparent;
  font-weight: 900;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.game-panel {
  padding: clamp(18px, 3vw, 30px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(270px, 315px);
  gap: clamp(20px, 3.5vw, 42px);
  align-items: center;
}

.board-panel { min-width: 0; }

.players {
  display: grid;
  grid-template-columns: minmax(125px, 1fr) auto minmax(125px, 1fr);
  align-items: center;
  gap: 11px;
  margin-bottom: 16px;
}

.player-card {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 13px;
  border: 3px solid var(--ink);
  border-radius: 13px;
  background: #ffffff;
  font-size: 0.92rem;
  font-weight: 850;
  transition: background-color 180ms ease, box-shadow 180ms ease;
}

.player-card.is-cpu { box-shadow: inset 0 6px 0 var(--pink); }
.player-card.is-human { box-shadow: inset 0 6px 0 var(--blue); }

.player-card.is-active {
  background: var(--yellow);
  box-shadow: 4px 5px 0 var(--ink);
}

.player-card b {
  margin-left: auto;
  font-weight: 1000;
}

.versus-mark {
  font-size: 0.76rem;
  font-weight: 1000;
}

.piece-dot {
  width: 23px;
  aspect-ratio: 1;
  display: inline-block;
  flex: 0 0 auto;
  border: 2px solid var(--ink);
  border-radius: 50%;
  box-shadow: inset 3px 3px 0 rgba(255, 255, 255, 0.46);
}

.piece-dot.white { background: #ffffff; }
.piece-dot.yellow { background: var(--yellow); }

.board-wrap {
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
}

.board {
  width: 100%;
  aspect-ratio: 1.12;
  border: 4px solid var(--ink);
  border-radius: 24px;
  background: var(--ink);
  box-shadow: 6px 7px 0 var(--yellow);
  position: relative;
  overflow: hidden;
}

.board::after {
  content: "";
  position: absolute;
  inset: 3.5%;
  border: 1px solid rgba(255, 230, 0, 0.24);
  border-radius: 50%;
  pointer-events: none;
}

.board svg {
  width: 100%;
  height: 100%;
  display: block;
}

.board .cell {
  cursor: pointer;
  outline: none;
}

.board .cell[aria-disabled="true"] { cursor: default; }

.board .cell-shape {
  fill: #1c1c1c;
  stroke: #716a28;
  stroke-width: 1.5;
  transition: fill 120ms ease, stroke 120ms ease;
}

.board .cell:not([aria-disabled="true"]):hover .cell-shape,
.board .cell:not([aria-disabled="true"]):focus-visible .cell-shape {
  fill: #303030;
  stroke: var(--yellow);
  stroke-width: 3;
}

.board .focus-ring {
  fill: none;
  stroke: white;
  stroke-width: 4;
  opacity: 0;
  pointer-events: none;
}

.board .cell:not([aria-disabled="true"]):focus-visible .focus-ring { opacity: 1; }

.board .piece {
  stroke: #111014;
  stroke-width: 3.2;
  filter: drop-shadow(0 5px 3px rgba(0, 0, 0, 0.34));
  transform-box: fill-box;
  transform-origin: center;
}

.board .piece.white { fill: var(--paper); }
.board .piece.yellow { fill: var(--yellow); }

.board .piece-shine {
  fill: rgba(255, 255, 255, 0.62);
  pointer-events: none;
}

.board .piece.just-placed {
  animation: piece-in 260ms cubic-bezier(0.22, 1.35, 0.5, 1) both;
}

.board .last-ring {
  fill: none;
  stroke: var(--red);
  stroke-width: 4;
  stroke-dasharray: 5 5;
  pointer-events: none;
}

.board .cell.outcome-win .cell-shape {
  fill: #50372c;
  stroke: var(--red);
  stroke-width: 4;
  animation: result-pulse 900ms ease-in-out infinite alternate;
}

.board .cell.outcome-loss .cell-shape {
  fill: #263d5a;
  stroke: #5e9cff;
  stroke-width: 4;
  animation: result-pulse 900ms ease-in-out infinite alternate;
}

.side-panel {
  display: grid;
  gap: 16px;
  align-content: center;
}

.rule-pair {
  display: grid;
  gap: 8px;
}

.rule-pair > div {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 10px 2px;
  border-bottom: 3px solid var(--ink);
  line-height: 1.15;
}

.rule-number {
  font-family: Arial, sans-serif;
  font-size: 3.6rem;
  line-height: 0.78;
  font-weight: 1000;
  letter-spacing: -0.08em;
}

.rule-pair span:not(.rule-number) {
  font-size: 0.86rem;
  font-weight: 900;
}

.rule-pair strong {
  font-size: 1.42rem;
  white-space: nowrap;
}

.rule-pair > div:first-child strong { color: var(--red); }
.rule-pair > div:last-child strong { color: var(--blue); }

.status-card {
  min-height: 185px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: var(--small-shadow);
}

.status-kicker {
  color: var(--muted);
  font-size: 0.72rem;
}

.status-card h2 {
  margin: 7px 0;
  font-size: 1.24rem;
  line-height: 1.35;
}

.status-card p {
  margin: 0 0 16px;
  font-size: 0.92rem;
}

.swap-button {
  width: 100%;
  min-height: 48px;
  margin-top: auto;
  padding: 10px 14px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 3px 4px 0 var(--ink);
  font-weight: 1000;
  cursor: pointer;
}

.swap-button:hover { background: var(--yellow-soft); }

.site-footer {
  min-height: 52px;
  padding: 12px clamp(16px, 4vw, 52px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border-top: 3px solid var(--ink);
  background: var(--paper);
  font-size: 0.82rem;
  font-weight: 800;
}

.footer-credit b { font-weight: 1000; }

.footer-links {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px 18px;
}

.site-footer a,
.text-link {
  color: var(--ink);
  font-weight: 900;
  text-underline-offset: 4px;
}

.site-footer .footer-purchase {
  padding: 5px 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  text-decoration: none;
}

.site-footer .footer-purchase:hover { background: var(--yellow-soft); }

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translate(-50%, 18px);
  max-width: calc(100% - 32px);
  padding: 10px 17px;
  border: 2px solid var(--paper);
  border-radius: 999px;
  color: var(--paper);
  background: var(--ink);
  font-size: 0.88rem;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.rules-dialog,
.result-dialog {
  padding: 0;
  border: 4px solid var(--ink);
  border-radius: 22px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 10px 12px 0 var(--ink);
}

.rules-dialog::backdrop,
.result-dialog::backdrop {
  background: rgba(17, 17, 17, 0.72);
  backdrop-filter: blur(4px);
}

.rules-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: min(86vh, 820px);
  overflow: hidden;
}

.dialog-head {
  padding: 20px 22px 17px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  border-bottom: 3px solid var(--ink);
  background: var(--yellow);
}

.dialog-head .eyebrow { margin: 0 0 4px; }

.dialog-head h2 {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.05em;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.6rem;
  line-height: 1;
}

.rules-body {
  max-height: calc(min(86vh, 820px) - 88px);
  padding: 24px;
  overflow-y: auto;
}

.rule-lead {
  padding: 17px 18px;
  border-left: 8px solid var(--blue);
  background: var(--blue-soft);
}

.rule-lead strong { font-size: 1.05rem; }
.rule-lead p { margin: 6px 0 0; }

.rule-steps {
  margin: 24px 0;
  padding: 0;
  display: grid;
  gap: 14px;
  list-style: none;
}

.rule-steps li {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 14px;
  align-items: start;
}

.rule-steps li > span {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  color: var(--yellow);
  background: var(--ink);
  font-size: 1.1rem;
  font-weight: 1000;
}

.rule-steps strong { font-size: 1rem; }

.rule-steps p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.rule-note {
  margin: 0 0 17px;
  padding: 13px 15px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  font-size: 0.87rem;
  font-weight: 750;
}

.result-dialog {
  width: min(460px, calc(100% - 30px));
  padding: 30px;
  text-align: center;
  overflow: visible;
}

.result-mark {
  width: 82px;
  aspect-ratio: 1;
  margin: -74px auto 16px;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50%;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 5px 5px 0 var(--ink);
  font-family: Arial, sans-serif;
  font-size: 3rem;
  line-height: 1;
  font-weight: 1000;
}

.result-dialog .eyebrow {
  padding: 3px 9px;
  color: var(--yellow);
  background: var(--ink);
}

.result-dialog h2 {
  margin: 13px 0 8px;
  font-size: clamp(1.8rem, 7vw, 2.65rem);
  line-height: 1.2;
}

.result-dialog > p { margin: 0 auto 20px; }

.result-actions {
  display: grid;
  gap: 12px;
}

.result-actions .purchase-button,
.rematch-button { width: 100%; }

.choose-color-button {
  margin-top: 16px;
  padding: 7px;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-size: 0.88rem;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

@keyframes piece-in {
  from { opacity: 0; transform: scale(0.22); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes result-pulse {
  from { stroke-opacity: 0.58; }
  to { stroke-opacity: 1; }
}

@media (max-width: 900px) {
  .start-card { grid-template-columns: 1fr; }
  .start-visual { min-height: 420px; }
  .game-panel { grid-template-columns: 1fr; align-items: start; }
  .side-panel { grid-template-columns: 1fr 1fr; align-items: stretch; }
}

@media (max-width: 680px) {
  .site-header { min-height: 70px; padding: 7px 14px; }
  .brand-logo { width: 72px; }
  .header-button { min-height: 40px; padding: 6px 11px; font-size: 0.85rem; }
  .game-shell { padding: 14px 10px 34px; }
  .panel { border-width: 3px; border-radius: 18px; box-shadow: 4px 5px 0 var(--ink); }
  .start-card { min-height: auto; }
  .start-copy { padding: 32px 22px 38px; }
  .start-copy h1 { font-size: clamp(2.25rem, 11.5vw, 3.15rem); }
  .start-lead { font-size: 0.96rem; }
  .start-actions { align-items: stretch; }
  .start-button,
  .purchase-button { min-height: 54px; padding-inline: 16px; font-size: 0.92rem; }
  .start-visual { min-height: 350px; padding: 30px 19px; order: -1; }
  .preview-rules { width: min(340px, 83vw); gap: 18px; }
  .preview-row { min-height: 104px; padding: 15px 13px; gap: 10px; }
  .preview-pieces i { width: clamp(31px, 9.2vw, 41px); }
  .visual-caption { margin-top: 22px; font-size: 0.78rem; }
  .game-toolbar { align-items: flex-start; }
  .game-toolbar > div { display: grid; gap: 3px; }
  .turn-copy { font-size: 1.35rem; }
  .new-game-button { font-size: 0.82rem; }
  .game-panel { padding: 12px; gap: 22px; }
  .players { gap: 6px; margin-bottom: 10px; }
  .player-card { min-height: 45px; padding: 7px 8px; border-width: 2px; font-size: 0.82rem; }
  .piece-dot { width: 19px; }
  .board { border-width: 3px; border-radius: 15px; box-shadow: 3px 4px 0 var(--yellow); }
  .side-panel { grid-template-columns: 1fr; }
  .rule-pair { grid-template-columns: 1fr 1fr; }
  .rule-pair > div { grid-template-columns: auto 1fr; padding-inline: 3px; }
  .rule-number { grid-row: 1 / span 2; font-size: 3rem; }
  .rule-pair strong { grid-column: 2; font-size: 1.18rem; }
  .status-card { min-height: 165px; }
  .site-footer { align-items: flex-start; flex-direction: column; gap: 7px; }
  .rules-body { padding: 18px; }
  .result-dialog { padding: 26px 20px 22px; }
}

@media (max-width: 430px) {
  .start-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .purchase-button { grid-column: 1 / -1; }
  .start-button { padding-inline: 9px; font-size: 0.86rem; }
  .preview-label { padding-inline: 6px; font-size: 0.62rem; }
  .preview-row strong { font-size: 2.2rem; }
  .player-card span:not(.piece-dot) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
