:root {
  --paper: #f6f3eb;
  --surface: #fffdf8;
  --ink: #202b33;
  --muted: #68747b;
  --line: #ccd2cf;
  --x: #e45545;
  --o: #1979a5;
  --accent: #1d765b;
  --yellow: #efc84a;
  --shadow: 0 18px 45px rgba(32, 43, 51, 0.1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  line-height: 1.7;
}
button, a { font: inherit; }
button { color: inherit; }
a { color: inherit; }

.site-header {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px clamp(18px, 5vw, 72px);
  border-bottom: 1px solid rgba(32, 43, 51, 0.1);
  background: rgba(246, 243, 235, 0.94);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 800; }
.brand-mark { width: 30px; height: 30px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
.brand-mark i { background: var(--ink); border-radius: 2px; }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { background: var(--yellow); }
nav { display: flex; gap: 28px; }
nav a { color: var(--muted); font-size: 14px; text-decoration: none; font-weight: 700; }
nav a:hover { color: var(--accent); }

main { overflow: hidden; }
.ad-space {
  width: min(100% - 32px, 970px);
  height: 90px;
  margin: 22px auto;
  display: grid;
  place-items: center;
  border: 1px dashed #c8cbc5;
  color: #9a9d98;
  background: rgba(255, 255, 255, 0.35);
  font-size: 11px;
}
.game-shell { width: min(100% - 32px, 1120px); margin: 30px auto 54px; }
.game-heading { text-align: center; margin-bottom: 28px; }
.main-game-shell { position: relative; padding-top: 28px; border-top: 4px solid var(--ink); }
.main-game-shell::before, .main-game-shell::after { content: ""; position: absolute; top: -4px; width: 44px; height: 4px; background: var(--yellow); }
.main-game-shell::before { left: 0; }
.main-game-shell::after { right: 0; }
.game-edition { width: fit-content; margin: 0 auto 12px; display: flex; border: 1px solid var(--ink); font-size: 10px; font-weight: 900; line-height: 1; }
.game-edition span { padding: 7px 10px; }
.game-edition span:first-child { background: var(--ink); color: #fff; }
.eyebrow, .section-kicker { color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: 0; margin: 0 0 4px; }
h1 { font-size: clamp(34px, 6vw, 58px); line-height: 1.15; margin: 0; letter-spacing: 0; }
.game-heading > p:last-child { margin: 8px 0 0; color: var(--muted); }

.game-layout {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 540px);
  justify-content: center;
  align-items: start;
  gap: clamp(28px, 5vw, 70px);
}
.settings {
  min-height: 510px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.setting-group + .setting-group { margin-top: 20px; }
.setting-label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 800; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; background: #e9e9e2; }
.segment, .difficulty button {
  min-height: 40px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}
.segment.active { background: var(--ink); color: #fff; }
.difficulty { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.difficulty button { border: 1px solid var(--line); background: #fff; padding: 4px; }
.difficulty button.active { border-color: var(--accent); color: var(--accent); background: #e8f4ef; }
.setting-group.inactive { opacity: 0.4; }
.rule-card { display: flex; gap: 12px; align-items: center; margin: 22px 0; padding: 14px; background: #fff5cf; border-left: 4px solid var(--yellow); }
.rule-card p { margin: 0; font-size: 12px; line-height: 1.6; }
.rule-icon { flex: 0 0 34px; height: 34px; display: grid; place-items: center; background: var(--yellow); font-weight: 900; }
.new-game { width: 100%; min-height: 46px; border: 0; background: var(--accent); color: #fff; font-weight: 800; cursor: pointer; }
.new-game:hover { background: #155d47; }
.board-reset { display: block; width: min(220px, 70%); margin: 16px auto 0; }

.play-area { width: min(100%, 540px); }
.scoreboard { height: 42px; display: flex; align-items: center; justify-content: center; gap: 16px; font-size: 13px; }
.scoreboard div { min-width: 128px; display: flex; align-items: center; gap: 9px; }
.scoreboard div:first-child { justify-content: flex-end; }
.scoreboard strong { font-size: 25px; line-height: 1; }
.scoreboard b { min-width: 18px; text-align: center; font-size: 18px; }
.x-color { color: var(--x); }
.o-color { color: var(--o); }
.score-divider { color: #a6adaa; }
.status { height: 48px; display: grid; place-items: center; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); background: rgba(255, 253, 248, 0.7); font-weight: 800; font-size: 15px; }
.board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  background: var(--ink);
  padding: 8px;
  border: 2px solid var(--ink);
  box-shadow: 12px 12px 0 rgba(29, 118, 91, 0.16), var(--shadow);
}
.cell {
  min-width: 0;
  min-height: 0;
  border: 0;
  background: var(--surface);
  display: grid;
  place-items: center;
  cursor: pointer;
  position: relative;
  font-size: clamp(58px, 10vw, 92px);
  font-weight: 700;
  line-height: 1;
  transition: background 120ms ease;
}
.cell:hover:empty { background: #f3eedf; }
.cell.x { color: var(--x); }
.cell.o { color: var(--o); }
.cell.oldest::after { content: ""; position: absolute; inset: 8px; border: 3px solid var(--yellow); animation: pulse 1.35s infinite; pointer-events: none; }
.cell.win { background: #fff0af; }
.cell:disabled { cursor: default; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.six-board { grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(6, 1fr); gap: 4px; padding: 5px; }
.six-board .cell { font-size: clamp(25px, 5vw, 48px); }
.six-board .cell.oldest::after { inset: 3px; border-width: 2px; }
.piece-guide { height: 44px; display: flex; align-items: center; justify-content: center; gap: 9px; color: var(--muted); font-size: 12px; }
.guide-dot { width: 10px; height: 10px; border: 2px solid var(--yellow); }

.other-games { width: min(100% - 32px, 1120px); margin: 108px auto 72px; }
.other-games-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.other-games-heading h2 { margin: 0 0 14px; font-size: 28px; line-height: 1.25; }
.other-games-heading .section-kicker { order: 2; margin-bottom: 17px; }
.game-banners { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.game-banner { min-height: 260px; position: relative; overflow: hidden; display: block; border: 2px solid var(--ink); border-radius: 4px; background: var(--surface); color: #fff; text-decoration: none; }
.game-banner img { width: 100%; height: 100%; position: absolute; inset: 0; display: block; object-fit: cover; object-position: center; transition: transform 220ms ease; }
.game-banner:first-child img { object-position: center 42%; }
.game-banner-copy { min-height: 104px; position: absolute; inset: auto 0 0; z-index: 1; display: flex; flex-direction: column; justify-content: center; padding: 16px 64px 16px 20px; background: rgba(32, 43, 51, 0.94); }
.game-banner-copy small { color: var(--yellow); font-size: 10px; font-style: normal; font-weight: 900; }
.game-banner-copy strong { margin-top: 3px; font-size: 22px; line-height: 1.3; }
.game-banner-copy em { color: #d7dedf; font-size: 12px; font-style: normal; }
.game-banner-arrow { width: 38px; height: 38px; position: absolute; z-index: 2; right: 18px; bottom: 32px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.55); border-radius: 50%; font-size: 20px; transition: background 160ms ease, color 160ms ease; }
.game-banner:hover img { transform: scale(1.035); }
.game-banner:hover .game-banner-arrow { background: var(--yellow); border-color: var(--yellow); color: var(--ink); }
.game-banner:focus-visible { outline: 4px solid var(--yellow); outline-offset: 3px; }
.ad-middle { margin-top: 72px; }
.content-section { width: min(100% - 32px, 940px); margin: 86px auto; }
.content-section h2 { font-size: 32px; margin: 0 0 26px; line-height: 1.3; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.steps article { padding: 30px 24px; }
.steps article + article { border-left: 1px solid var(--line); }
.steps span { color: var(--accent); font-weight: 900; font-size: 12px; }
.steps h3 { margin: 10px 0 8px; font-size: 18px; }
.steps p, .strategy p { margin: 0; color: var(--muted); font-size: 14px; }
.strategy { margin-top: 30px; padding: 28px; background: var(--surface); border-left: 4px solid var(--accent); }
.strategy h3 { margin: 0 0 8px; }
.more-link { display: inline-block; margin-top: 22px; color: var(--accent); font-size: 14px; font-weight: 800; text-decoration: none; }
.more-link:hover { text-decoration: underline; }
.faq { max-width: 760px; }
.faq details { border-top: 1px solid var(--line); }
.faq details:last-child { border-bottom: 1px solid var(--line); }
.faq summary { padding: 18px 4px; font-weight: 800; cursor: pointer; }
.faq details p { margin: -6px 4px 20px; color: var(--muted); font-size: 14px; }

footer { padding: 42px clamp(18px, 5vw, 72px); background: var(--ink); color: #fff; display: grid; grid-template-columns: 1fr auto; gap: 26px; align-items: end; }
footer strong { font-size: 20px; }
footer p { margin: 4px 0 0; color: #bec7cb; font-size: 13px; }
.footer-links { display: flex; gap: 22px; font-size: 12px; }
footer small { color: #89979d; grid-column: 1 / -1; }

.legal-page main { width: min(100% - 32px, 760px); margin: 60px auto 100px; overflow: visible; }
.legal-page h1 { font-size: 38px; margin-bottom: 30px; }
.legal-page h2 { margin-top: 36px; font-size: 20px; }
.legal-page p, .legal-page li { color: var(--muted); font-size: 14px; }
.back-link { display: inline-block; margin-bottom: 26px; color: var(--accent); font-weight: 800; text-decoration: none; }

.article-page main { width: min(100% - 32px, 900px); margin: 58px auto 100px; overflow: visible; }
.article-page h1 { max-width: 760px; font-size: clamp(34px, 6vw, 50px); }
.page-lead { max-width: 720px; margin: 16px 0 42px; color: var(--muted); font-size: 16px; }
.article-body { display: grid; gap: 50px; }
.article-body section { border-top: 1px solid var(--line); padding-top: 28px; }
.article-body h2 { margin: 0 0 14px; font-size: 25px; }
.article-body h3 { margin: 24px 0 6px; font-size: 18px; }
.article-body p, .article-body li { color: var(--muted); font-size: 14px; }
.article-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.article-grid article { padding: 22px; border: 1px solid var(--line); background: var(--surface); }
.article-grid article h3 { margin-top: 0; }
.faq-list details { border-top: 1px solid var(--line); }
.faq-list details:last-child { border-bottom: 1px solid var(--line); }
.faq-list summary { padding: 20px 4px; font-weight: 800; cursor: pointer; }
.faq-list details p { margin: -4px 4px 22px; }
.page-cta { padding: 28px; background: var(--ink); color: #fff; }
.page-cta h2 { color: #fff; }
.page-cta p { color: #c7d0d3; }
.page-cta a { display: inline-block; margin-top: 8px; padding: 10px 18px; background: var(--yellow); color: var(--ink); text-decoration: none; font-weight: 800; }

@media (max-width: 780px) {
  .site-header nav { display: none; }
  .game-shell { margin-top: 18px; }
  .game-layout { grid-template-columns: 1fr; }
  .play-area { grid-row: 1; margin: 0 auto; }
  .settings { grid-row: 2; min-height: auto; }
  .game-banners { grid-template-columns: 1fr; }
  .game-banner { min-height: 230px; }
  .steps { grid-template-columns: 1fr; }
  .article-grid { grid-template-columns: 1fr; }
  .steps article + article { border-left: 0; border-top: 1px solid var(--line); }
  footer { grid-template-columns: 1fr; align-items: start; }
  footer small { grid-column: auto; }
}

@media (max-width: 420px) {
  .ad-space { height: 60px; }
  h1 { font-size: 36px; }
  .game-heading > p:last-child { font-size: 13px; }
  .board { gap: 5px; padding: 5px; }
  .main-game-shell { padding-top: 22px; }
  .other-games { margin-top: 76px; }
  .other-games-heading { align-items: start; flex-direction: column; gap: 0; }
  .other-games-heading .section-kicker { order: 0; margin-bottom: 2px; }
  .other-games-heading h2 { font-size: 24px; }
  .game-banner { min-height: 215px; }
  .game-banner-copy { min-height: 98px; padding-left: 16px; }
  .game-banner-copy strong { font-size: 20px; }
  .cell { font-size: 17vw; }
  .six-board .cell { font-size: 8vw; }
  .scoreboard div { min-width: 105px; }
  .content-section { margin: 64px auto; }
  .footer-links { flex-direction: column; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .cell.oldest::after { animation: none; }
}

.gravity-page { background: #f2f0e9; }
.three-intro { width: min(100% - 32px, 1120px); margin: 36px auto 26px; }
.three-intro h1 { margin: 0; font-size: clamp(40px, 7vw, 72px); }
.three-intro > p:last-child { margin: 8px 0 0; color: var(--muted); }
.three-game { min-height: 700px; display: grid; grid-template-columns: 300px minmax(0, 1fr); background: #161b1a; color: #f8f7f2; position: relative; }
.three-toolbar { z-index: 3; padding: 30px 24px; background: #f7f4ec; color: var(--ink); border-right: 1px solid #343b38; }
.three-toolbar .setting-group + .setting-group { margin-top: 22px; }
.three-score { margin: 30px 0 22px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.three-score div { min-height: 48px; display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 10px; }
.three-score div + div { border-top: 1px solid var(--line); }
.column-picker { margin-bottom: 20px; }
.column-pad { width: 156px; display: grid; grid-template-columns: repeat(4, 36px); grid-template-rows: repeat(4, 36px); gap: 4px; }
.column-pad button { min-width: 0; min-height: 0; border: 1px solid #afb6b2; background: #fff; color: var(--muted); font-size: 10px; font-weight: 800; cursor: pointer; }
.column-pad button:hover, .column-pad button.hovered { border-color: var(--accent); background: #e8f4ef; color: var(--accent); }
.column-pad button:disabled { opacity: .3; cursor: default; }
.ball-swatch { width: 18px; height: 18px; border-radius: 50%; display: block; }
.ball-swatch.black { background: #181b1a; border: 1px solid #000; box-shadow: inset 3px 3px 5px rgba(255,255,255,.18); }
.ball-swatch.white { background: #fffdf4; border: 1px solid #a9ada8; }
.three-viewport { min-width: 0; min-height: 700px; position: relative; overflow: hidden; }
#three-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#three-canvas:active { cursor: grabbing; }
.three-status { position: absolute; z-index: 2; top: 18px; left: 50%; transform: translateX(-50%); min-width: min(360px, calc(100% - 36px)); padding: 10px 20px; text-align: center; background: rgba(246,243,235,.94); color: var(--ink); font-weight: 800; border-bottom: 3px solid var(--yellow); pointer-events: none; }
.three-level { position: absolute; right: 18px; top: 50%; transform: translateY(-50%); display: grid; gap: 26px; color: rgba(255,255,255,.55); font-size: 11px; pointer-events: none; }
.gravity-rules { margin-top: 110px; }
.gravity-detail { margin-top: 34px; }
.gravity-detail article { border-radius: 0; }

@media (max-width: 860px) {
  .three-game { grid-template-columns: 1fr; }
  .three-toolbar { border-right: 0; border-bottom: 1px solid #343b38; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
  .three-toolbar .setting-group + .setting-group { margin-top: 0; }
  .three-score { margin: 0; }
  .three-toolbar .new-game { align-self: end; }
  .three-viewport { min-height: min(82vh, 680px); }
}

@media (max-width: 560px) {
  .three-intro h1 { font-size: 42px; }
  .three-game { min-height: 0; }
  .three-toolbar { grid-template-columns: 1fr; padding: 22px 18px; }
  .three-viewport { min-height: 520px; }
  .three-status { top: 12px; font-size: 13px; }
  .three-level { right: 8px; }
}
