:root {
  --ink: #080705;
  --ink-soft: #11100d;
  --charcoal: #1b1915;
  --ivory: #e8e0d0;
  --muted: #9b9487;
  --gold: #aa8c57;
  --gold-dim: rgba(170, 140, 87, .36);
  --panel: rgba(8, 7, 5, .66);
  --board-top: 13%;
  --board-left: 25%;
  --board-width: 50%;
  --board-height: auto;
  --serif: "Yu Mincho", "Hiragino Mincho ProN", "Times New Roman", serif;
  --sans: "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--ink); color: var(--ivory); }

body {
  min-width: 320px;
  overflow: hidden;
  font-family: var(--serif);
  background:
    radial-gradient(circle at 50% 35%, #2a2116 0, #0c0a07 38%, #050403 75%),
    var(--ink);
}

button, a { font: inherit; }
button { color: inherit; }

.app, .screen { width: 100%; height: 100svh; min-height: 600px; }

.screen {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 900ms ease, visibility 900ms;
  overflow: hidden;
}

.screen.is-active { opacity: 1; visibility: visible; pointer-events: auto; }

.screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 42%, rgba(0,0,0,.52) 100%);
}

.eyebrow, .label, .subtitle, .title-note, .game-header p, .capture-label,
.hair-heading, .move-counter, .turn-indicator, .thinking, .achievement span {
  font-family: var(--sans);
  letter-spacing: .22em;
  text-transform: uppercase;
}

.text-button {
  appearance: none;
  border: 0;
  border-bottom: 1px solid rgba(232, 224, 208, .32);
  background: transparent;
  color: var(--ivory);
  min-width: 136px;
  min-height: 46px;
  padding: 14px 10px 12px;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.35;
  letter-spacing: .14em;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  transition: color 240ms, border-color 240ms, opacity 240ms;
}

.text-button:hover, .text-button:focus-visible { color: #fff; border-color: var(--gold); outline: none; }
.text-button:disabled { cursor: default; opacity: .28; }
.primary-action { border-color: var(--gold); }
.quiet-link { display: block; margin: 14px auto 0; padding: 8px; border: 0; background: transparent; color: #a29a8d; font: 13px/1.5 var(--sans); letter-spacing: .16em; cursor: pointer; transition: color 240ms; }
.quiet-link:hover, .quiet-link:focus-visible { color: var(--ivory); outline: none; }
.install-action { color: var(--gold); }

/* Title */
.title-screen { display: grid; place-items: center; background: #050403; }
.title-backdrop, .title-vignette { position: absolute; inset: 0; }
.title-backdrop { opacity: .58; }
.title-portrait { position: absolute; width: min(68vw, 870px); height: 100%; left: 50%; transform: translateX(-50%); }
.title-image { object-fit: cover; object-position: 50% 20%; filter: grayscale(.18) sepia(.14) brightness(.72); }
.title-backdrop .portrait-fallback { background: radial-gradient(ellipse at 50% 30%, #8b6845 0 12%, #1d1710 25%, transparent 53%); }
.title-vignette { background: linear-gradient(90deg, #050403 0%, transparent 32%, transparent 68%, #050403 100%), linear-gradient(0deg, #050403 2%, transparent 45%, rgba(0,0,0,.52)); }
.title-content { z-index: 4; text-align: center; transform: translateY(4vh); text-shadow: 0 2px 18px #000; }
.title-content .eyebrow { color: var(--gold); font-size: 9px; margin: 0 0 24px; }
.title-content h1 { margin: 0; font-weight: 400; font-size: clamp(44px, 6.5vw, 92px); letter-spacing: .12em; }
.title-content h1 b { font-family: var(--sans); font-size: .67em; font-weight: 300; letter-spacing: .38em; margin-left: .12em; }
.subtitle { margin: 12px 0 0; font-size: clamp(10px, 1vw, 13px); color: #cfc5b2; }
.hairline { width: 1px; height: 62px; margin: 28px auto 18px; background: linear-gradient(var(--gold), transparent); }
.title-note { margin-top: 30px; font-size: 7px; color: #777166; }

/* Match */
.game-screen { background: radial-gradient(ellipse at 50% 32%, #2a2015, #0a0806 48%, #040302); }
.game-header { position: absolute; z-index: 25; top: 28px; left: 40px; right: 40px; display: flex; justify-content: space-between; align-items: baseline; }
.brand-small { display: flex; align-items: baseline; gap: 9px; letter-spacing: .12em; }
.brand-small span { font-size: 18px; }
.brand-small strong { font-family: var(--sans); font-size: 10px; font-weight: 400; letter-spacing: .28em; }
.game-header p { font-size: 7px; color: var(--muted); }

.portrait-stage {
  position: absolute;
  z-index: 2;
  width: min(59vw, 720px);
  height: calc(100svh - 82px);
  min-height: 540px;
  max-height: 980px;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  overflow: hidden;
}

.portrait-stage > img, .portrait-stage > .portrait-fallback { position: absolute; inset: 0; width: 100%; height: 100%; }
.portrait-stage > img { z-index: 1; object-fit: cover; object-position: 50% 20%; filter: sepia(.08) saturate(.84) brightness(.83) contrast(1.08); transition: opacity 650ms ease, filter 650ms ease; }
.portrait-fallback { background: radial-gradient(ellipse at 50% 28%, #9a734d 0 17%, #3a2a1d 18% 28%, transparent 42%); }
.fallback-head { position: absolute; width: 46%; aspect-ratio: 1.08; left: 27%; top: 14%; border-radius: 48% 48% 42% 42%; background: radial-gradient(circle at 52% 34%, #b88e67, #725038 72%, #2b1d15); box-shadow: 0 0 90px #6c482b; }
.fallback-body { position: absolute; width: 86%; height: 55%; left: 7%; bottom: -10%; border-radius: 45% 45% 0 0; background: linear-gradient(90deg, #090909, #25211d 48%, #080808); }

#go-board {
  position: absolute;
  z-index: 3;
  top: var(--board-top);
  left: var(--board-left);
  width: var(--board-width);
  height: var(--board-height);
  aspect-ratio: 1;
  cursor: crosshair;
  touch-action: manipulation;
  filter: drop-shadow(0 3px 7px rgba(0,0,0,.35));
}

.player-panel, .turn-indicator, .reaction, .thinking, .hair-delta { pointer-events: none; }
.player-panel { position: absolute; z-index: 26; top: 24%; width: 170px; }
.black-panel { left: 4.5vw; }
.white-panel { right: 4.5vw; text-align: right; }
.panel-number { display: block; color: var(--gold); font: 8px var(--sans); letter-spacing: .2em; padding-bottom: 12px; border-bottom: 1px solid var(--gold-dim); }
.player-stone { width: 34px; height: 34px; margin: 28px 0 17px; border-radius: 50%; }
.stone-black { background: radial-gradient(circle at 36% 27%, #5b5851, #111 48%, #000 77%); box-shadow: 0 6px 12px #000; }
.stone-white { margin-left: auto; background: radial-gradient(circle at 36% 27%, #fff, #d9d2c6 50%, #8f877a); box-shadow: 0 6px 12px #000; }
.player-panel .label { margin: 0; font-size: 8px; color: var(--muted); }
.player-panel h2 { margin: 7px 0 22px; font: 300 24px var(--sans); letter-spacing: .18em; }
.capture-label { display: flex; align-items: baseline; gap: 7px; color: #aaa295; font-size: 12px; line-height: 1.5; }
.white-panel .capture-label { justify-content: flex-end; }
.capture-label strong { color: #f0e8da; font-size: 27px; font-weight: 300; margin-left: 5px; }
.capture-label em { color: #c8a86d; font-size: 13px; font-style: normal; }
.hair-status { margin-top: 46px; }
.hair-heading { display: flex; justify-content: space-between; font-size: 12px; line-height: 1.5; color: #aaa295; }
.hair-heading strong { color: #f0e8da; font-size: 18px; font-weight: 400; }
.hair-track { height: 1px; margin-top: 12px; background: #3a352e; overflow: visible; }
.hair-track i { display: block; width: 0; height: 1px; background: var(--gold); box-shadow: 0 0 8px rgba(190,155,92,.5); transition: width 900ms cubic-bezier(.22,.8,.2,1); }

.turn-indicator { position: absolute; z-index: 26; top: 94px; left: 50%; transform: translateX(-50%); font-size: 11px; color: #aaa295; }
.turn-indicator span { display: inline-block; width: 5px; height: 5px; margin-right: 10px; border-radius: 50%; background: #151515; border: 1px solid #807a70; }
.turn-indicator b { font-weight: 400; }
.reaction { position: absolute; z-index: 26; left: 25%; right: 25%; bottom: 75px; min-height: 31px; margin: 0; text-align: center; color: #e5dccd; font-size: clamp(17px, 1.25vw, 18px); line-height: 1.8; letter-spacing: .1em; text-shadow: 0 2px 14px #000; transition: opacity 700ms; }
.game-controls { position: absolute; z-index: 27; bottom: 24px; left: 40px; right: 40px; display: flex; align-items: center; justify-content: space-between; }
.game-controls .text-button { min-width: 128px; }
.game-controls #restart-button { margin-left: auto; }
.move-counter { font-size: 7px; color: #716b60; }

.thinking { position: absolute; z-index: 6; left: 50%; top: 54%; transform: translate(-50%, -50%); font-size: 12px; line-height: 1.5; color: #d3cbbb; opacity: 0; text-shadow: 0 2px 12px #000; transition: opacity 300ms; }
.thinking.is-active { opacity: 1; }
.thinking i { display: block; width: 0; height: 1px; margin-top: 9px; background: var(--gold); }
.thinking.is-active i { animation: consideration 900ms ease-out forwards; }
@keyframes consideration { to { width: 100%; } }

.capture-veil { position: absolute; z-index: 5; left: var(--board-left); top: var(--board-top); width: var(--board-width); aspect-ratio: 1; border-radius: 50%; pointer-events: none; opacity: 0; background: radial-gradient(circle, transparent 35%, rgba(210,173,110,.08) 61%, transparent 74%); }
.capture-veil.show { animation: capture-veil 900ms ease-out both; }
.capture-veil.is-absolute.show { animation-duration: 1900ms; background: radial-gradient(circle, transparent 29%, rgba(210,173,110,.12) 58%, transparent 76%); }
@keyframes capture-veil { 0% { opacity: 0; transform: scale(.94); } 24% { opacity: 1; } 100% { opacity: 0; transform: scale(1.04); } }

.hair-delta { position: absolute; z-index: 8; left: 50%; top: 46%; transform: translate(-50%, 8px); width: max-content; max-width: 84%; opacity: 0; color: #f2eadc; font: 300 15px/1.6 var(--sans); letter-spacing: .14em; text-align: center; text-shadow: 0 2px 12px #000; }
.hair-delta.show { animation: delta 1800ms ease both; }
.hair-delta.is-heavy { font-size: 16px; letter-spacing: .17em; }
.hair-delta.is-absolute.show { animation: delta-absolute 2700ms cubic-bezier(.22,.7,.2,1) both; }
@keyframes delta { 0% { opacity: 0; transform: translate(-50%, 9px); } 18%,62% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -8px); } }
@keyframes delta-absolute { 0% { opacity: 0; transform: translate(-50%, 10px); } 14%,76% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -6px); } }

.debug-panel { display: none; position: absolute; z-index: 40; top: 80px; right: 18px; width: 250px; padding: 14px; background: rgba(0,0,0,.88); border: 1px solid #b19058; font: 10px/1.4 Consolas, monospace; color: #e2c88f; }
.debug-mode .debug-panel { display: block; }
.debug-mode #go-board { outline: 2px dashed #d4ad64; background: rgba(178, 137, 65, .08); }
.debug-panel h2 { margin: 0 0 9px; font-size: 10px; letter-spacing: .12em; }
.debug-panel dl { margin: 0; }
.debug-panel dl div { display: flex; justify-content: space-between; }
.debug-panel dt { color: #8f897e; }
.debug-panel dd { margin: 0; }
.debug-panel pre { margin: 10px 0 0; font-size: 9px; color: #bbb3a4; }
.debug-action { width: 100%; margin-top: 10px; padding: 7px; border: 1px solid #7f6741; background: transparent; color: #e2c88f; font: 9px Consolas, monospace; cursor: pointer; }
.debug-action:hover { background: rgba(170,140,87,.14); }

/* Result */
.result-screen { display: grid; place-items: center; background: #080705; }
.result-bg { position: absolute; inset: 0; opacity: .16; background: url("assets/zugo-man.webp") center 28% / cover no-repeat; filter: grayscale(1) blur(3px); }
.result-card { position: relative; z-index: 25; width: min(88vw, 540px); padding: 44px 54px; text-align: center; background: rgba(9,8,6,.74); border: 1px solid rgba(170,140,87,.24); box-shadow: 0 30px 100px #000; backdrop-filter: blur(12px); }
.result-card { opacity: 0; transform: translateY(10px); transition: opacity 900ms ease, transform 900ms ease, border-color 900ms ease; }
.result-card.is-revealed { opacity: 1; transform: translateY(0); }
.result-card.ending-win { border-top-color: rgba(196,161,96,.78); }
.result-card.ending-lose { border-bottom-color: rgba(196,161,96,.56); }
.result-card .eyebrow { margin: 0 0 20px; color: var(--gold); font-size: 8px; }
.result-card h1 { margin: 0; font: 300 clamp(38px, 6vw, 64px) var(--sans); letter-spacing: .15em; }
.result-rule { width: 1px; height: 42px; margin: 25px auto; background: var(--gold); }
.capture-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: rgba(170,140,87,.25); }
.capture-grid div { padding: 18px; background: rgba(8,7,5,.98); }
.capture-grid span, .hair-result span { display: block; color: #aaa295; font: 11px/1.5 var(--sans); letter-spacing: .16em; }
.capture-grid strong { display: block; margin-top: 7px; color: #f0e8da; font: 300 28px var(--sans); }
.hair-result { padding: 25px 0 15px; }
.hair-result strong { display: block; margin: 7px 0 15px; color: var(--gold); font: 300 30px var(--sans); }
.hair-result p { margin: 0; color: #d7cfc1; font-size: 17px; letter-spacing: .06em; line-height: 1.85; white-space: pre-line; }
.ending-code { margin: 11px 0 0; color: #6e675d; font: 6px var(--sans); letter-spacing: .2em; }
.result-actions { display: flex; justify-content: center; gap: 34px; margin-top: 28px; }

/* First encounter briefing */
.tutorial[hidden] { display: none; }
.tutorial { position: fixed; z-index: 90; inset: 0; display: grid; place-items: center; padding: 24px; }
.tutorial-scrim { position: absolute; inset: 0; background: rgba(2,2,2,.68); backdrop-filter: blur(3px); }
.tutorial-card { position: relative; width: min(88vw, 430px); padding: 38px 42px 34px; background: rgba(10,9,7,.96); border: 1px solid rgba(187,151,88,.36); box-shadow: 0 30px 90px #000; }
.tutorial-index { position: absolute; top: 20px; right: 24px; margin: 0; color: #716a5e; font: 7px var(--sans); letter-spacing: .16em; }
.tutorial-card .eyebrow { margin: 0 0 22px; color: var(--gold); font-size: 7px; }
.tutorial-card h2 { margin: 0; font-size: 29px; font-weight: 400; letter-spacing: .12em; }
.tutorial-card > p:not(.eyebrow):not(.tutorial-index) { min-height: 3.8em; margin: 18px 0 0; color: #d1c8ba; font-size: 17px; line-height: 1.85; letter-spacing: .045em; }
.tutorial-diagram { position: relative; width: 126px; height: 90px; margin: 26px auto 24px; background-image: linear-gradient(rgba(177,143,85,.34) 1px, transparent 1px), linear-gradient(90deg, rgba(177,143,85,.34) 1px, transparent 1px); background-size: 30px 30px; background-position: 3px 0; border: 1px solid rgba(177,143,85,.12); }
.tutorial-diagram::before, .tutorial-diagram::after { content: ''; position: absolute; border-radius: 50%; }
.diagram-surround::before { width: 16px; height: 16px; left: 56px; top: 37px; background: #eee5d4; box-shadow: -30px 0 0 #111, 30px 0 0 #111, 0 -30px 0 #111, 0 30px 0 #111; }
.diagram-capture::before { width: 17px; height: 17px; left: 25px; top: 7px; background: #eee5d4; box-shadow: 30px 30px 0 #eee5d4, 60px 60px 0 #eee5d4; }
.diagram-capture::after { width: 17px; height: 17px; right: 24px; top: 7px; background: #111; box-shadow: -60px 60px 0 #111; }
.diagram-hair { background-image: linear-gradient(90deg, #b7965e 0 62%, #342f28 62%); height: 2px; margin-top: 63px; margin-bottom: 75px; border: 0; }
.diagram-hair::before { content: 'HAIR 76%'; left: 0; top: -26px; width: auto; color: #d8c49a; border-radius: 0; font: 8px var(--sans); letter-spacing: .18em; }
.tutorial-actions { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.tutorial-actions .quiet-link { margin: 0; }
.tutorial-actions .text-button { min-width: 120px; }
.tutorial-open .game-screen { pointer-events: none; }

.achievement { position: fixed; z-index: 100; right: 28px; bottom: 28px; width: 290px; padding: 18px 20px; background: rgba(8,7,5,.96); border-left: 1px solid var(--gold); box-shadow: 0 12px 36px #000; opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity 500ms, transform 500ms; }
.achievement.show { opacity: 1; transform: translateY(0); }
.achievement span { display: block; margin-bottom: 8px; color: var(--gold); font-size: 9px; }
.achievement strong { color: #eee5d7; font-size: 16px; font-weight: 400; letter-spacing: .1em; }
.achievement p { margin: 9px 0 0; color: #b9b0a2; font-size: 14px; line-height: 1.75; letter-spacing: .045em; }

@media (max-width: 840px) {
  :root { --board-top: 16%; --board-left: 20%; --board-width: 60%; }
  .app, .screen { min-height: 560px; }
  .game-header { top: 18px; left: 18px; right: 18px; }
  .game-header p { display: none; }
  .portrait-stage { width: 100vw; height: calc(100svh - 55px); min-height: 520px; }
  .portrait-stage > img { object-fit: cover; }
  .player-panel { top: 64px; width: 116px; }
  .black-panel { left: 16px; }
  .white-panel { right: 16px; }
  .panel-number, .player-stone { display: none; }
  .player-panel .label { font-size: 10px; color: #aaa295; }
  .player-panel h2 { font-size: 17px; margin: 5px 0; }
  .capture-label { margin: 6px 0 0; font-size: 11px; line-height: 1.25; gap: 4px; }
  .capture-label strong { font-size: 22px; line-height: 1.25; margin-left: 1px; }
  .capture-label em { font-size: 12px; }
  .hair-status { margin-top: 4px; }
  .hair-heading { font-size: 10px; line-height: 1.25; }
  .hair-heading strong { font-size: 15px; line-height: 1.25; }
  .hair-track { margin-top: 4px; }
  .turn-indicator { top: 64px; }
  .reaction { left: 10%; right: 10%; bottom: 67px; }
  .game-controls { left: 18px; right: 18px; bottom: 15px; }
  .game-controls, .game-controls .text-button { pointer-events: auto; }
  .debug-panel { top: 128px; right: 8px; width: 210px; max-height: 45vh; overflow: auto; }
}

@media (max-width: 480px) {
  :root { --board-top: 16%; --board-left: 12%; --board-width: 76%; }
  .title-portrait { width: 120vw; }
  .title-content h1 { letter-spacing: .05em; }
  .title-content h1 b { display: block; margin: 9px 0 0; }
  .portrait-stage > img { object-position: 50% 16%; }
  .reaction { bottom: 76px; font-size: 17px; line-height: 1.8; }
  .move-counter { display: none; }
  .game-controls { justify-content: space-between; }
  .game-controls .text-button { min-width: 124px; min-height: 48px; }
  .result-card { padding: 34px 24px; }
  .tutorial { align-items: end; padding: 0; }
  .tutorial-card { width: 100%; padding: 30px 26px calc(24px + env(safe-area-inset-bottom)); border-left: 0; border-right: 0; border-bottom: 0; }
  .tutorial-card h2 { font-size: 25px; }
  .tutorial-diagram { margin-top: 20px; margin-bottom: 20px; }
  .result-actions { gap: 12px; }
  .result-actions .text-button { min-width: 126px; padding-inline: 8px; }
  .achievement { left: 16px; right: 16px; bottom: 18px; width: auto; }
}

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