:root {
  color-scheme: light;
  --paper: #f1e6d5;
  --cream: #fff3d9;
  --forest: #23382b;
  --muted: #655849;
  --line: #57412b43;
  --gold: #f1c47e;
  --red: #862d30;
  --board-ratio: .741935;
  --display: Georgia, 'Times New Roman', serif;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  --field: #806040;
  --scene: none;
  margin: 0;
  color: #262a21;
  background: radial-gradient(ellipse at 12% 42%, #fff2da, transparent 64%), var(--paper);
}
body[data-mode=kuyu] { --scene: url('assets/kuyu.webp'); }
body[data-mode=ucgen] { --field: #685a47; --scene: url('assets/ucgen.webp'); }
a { color: inherit; }
:is(a, button, canvas, input, summary):focus-visible { outline: 3px solid #b4682b; outline-offset: 3px; }
button { font: inherit; color: inherit; cursor: pointer; }
:is(a, button, canvas) { -webkit-tap-highlight-color: transparent; }

.street-shell { width: min(1080px, calc(100% - 56px)); margin: 0 auto; padding-bottom: max(22px, env(safe-area-inset-bottom)); }
.street-header { display: flex; align-items: center; justify-content: space-between; min-height: 73px; border-bottom: 1px solid var(--line); gap: 10px; }
.brand { text-decoration: none; display: inline-flex; align-items: center; gap: 11px; color: var(--forest); min-width: 0; }
.brand-stone {
  width: 30px; height: 30px; flex: 0 0 auto; border-radius: 50%;
  background: radial-gradient(circle at 33% 27%, #fff0cc 0 8%, transparent 11%), linear-gradient(65deg, transparent 32%, #41786a 34% 55%, transparent 59%), radial-gradient(circle at 37% 33%, #e7ae72, #aa6b42 73%, #603727);
  transform: rotate(-10deg);
}
.brand-text { display: grid; }
.brand-text small { font-size: 8px; font-weight: 800; letter-spacing: .3em; line-height: 1; }
.brand strong { font: bold 28px/.95 var(--display); letter-spacing: -.04em; }
.header-actions, .home-link, .sound-button { display: flex; align-items: center; }
.header-actions { gap: 8px; }
.home-link { min-height: 44px; gap: 8px; padding: 0 12px; border: 1px solid var(--line); border-radius: 99px; font-size: 13px; font-weight: 750; line-height: 1.16; text-decoration: none; }
.sound-button { min-height: 44px; min-width: 44px; justify-content: center; border: 1px solid transparent; border-radius: 99px; background: transparent; }
.sound-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sound-muted, .sound-button[aria-pressed=false] .sound-waves { display: none; }
.sound-button[aria-pressed=false] .sound-muted { display: initial; }
.home-link:hover, .sound-button:hover { background: #e7d8be; }

.mode-tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 16px 0 0; }
.mode-tabs a {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 15px; border: 1px solid var(--line);
  border-radius: 6px; color: var(--forest); text-decoration: none; font-size: 13px; font-weight: 750; line-height: 1.15;
}
.mode-tabs a:hover { background: #edddc6; }
.mode-tabs a[aria-current=page] { border-color: #742828; background: var(--red); color: var(--cream); box-shadow: 0 2px 0 #532323; }

.street-layout {
  display: grid; grid-template-columns: minmax(250px, 395px) minmax(340px, 505px);
  grid-template-areas: 'guide card' 'rules card'; grid-template-rows: auto 1fr;
  column-gap: clamp(25px, 6vw, 90px); align-items: start; justify-content: space-between; margin-top: 19px;
}
.match-guide { grid-area: guide; min-width: 0; padding-top: 25px; }
.match-guide h1 { margin: 0 0 11px; font: bold clamp(48px, 6.1vw, 81px)/.93 var(--display); letter-spacing: -.068em; text-wrap: balance; overflow-wrap: anywhere; }
.objective { margin: 0; color: var(--muted); font-size: 17px; max-width: 27ch; line-height: 1.5; }
.match-options { display: flex; align-items: center; flex-wrap: wrap; gap: 7px 11px; margin: 24px 0 17px; }
.opponents { display: flex; align-items: stretch; border: 1px solid #7860455c; border-radius: 8px; padding: 2px; }
.opponent-button, .restart-button { min-height: 44px; border: 0; border-radius: 6px; font-size: 12px; font-weight: 750; line-height: 1.22; }
.opponent-button { padding: 7px 12px; background: transparent; }
.opponent-button[aria-pressed=true] { background: var(--forest); color: var(--cream); }
.opponent-button:hover:not([aria-pressed=true]) { background: #e9d9be; }
.restart-button { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; background: transparent; color: var(--red); }
.restart-button span:first-child { font-size: 20px; line-height: 1; }
.restart-button:hover { background: #edddc6; }
.instructions { grid-area: rules; max-width: 42ch; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.instructions summary { display: list-item; padding: 10px 0; color: var(--forest); font-size: 14px; font-weight: 750; cursor: pointer; }
.instructions p { margin: 5px 0 12px; }

.street-card {
  grid-area: card; overflow: hidden; width: 100%; min-width: 0; border: 1px solid #60634e; border-radius: 15px;
  background: #26372d; color: var(--cream);
  box-shadow: 0 13px 30px #37241126, 0 3px 8px #3724112a, inset 0 1px #fff8dc27;
}
.street-score { display: grid; grid-template-columns: 1fr minmax(100px, 1.3fr) 1fr; align-items: center; gap: 5px; padding: 9px 8px; }
.score-chit { --marble: #56c9bd; --marble-bright: #ccf4d6; min-width: 0; min-height: 48px; display: flex; align-items: center; gap: 6px; padding: 4px 6px; border: 1px solid transparent; border-radius: 7px; }
.score-chit.active { border-color: #f1c47e80; background: #101b1554; }
.player-two { --marble: #edaa55; --marble-bright: #ffe1a0; flex-direction: row-reverse; }
.player-marble { width: 15px; height: 15px; flex: 0 0 auto; border-radius: 50%; background: radial-gradient(circle at 31% 26%, #fff4d1 0 9%, transparent 12%), radial-gradient(circle at 45% 34%, var(--marble-bright), var(--marble) 69%, #192722); box-shadow: 0 1px 3px #0c1513; }
.player-name { color: #f4deb5; font-size: 11px; font-weight: 750; line-height: 1.2; overflow-wrap: anywhere; }
.score-chit strong { margin-left: auto; font: bold 26px/1 var(--display); font-variant-numeric: tabular-nums; }
.player-two strong { margin-left: 0; margin-right: auto; }
.turn-card { display: grid; gap: 3px; text-align: center; line-height: 1.15; }
.turn-caption { font-size: 12px; font-weight: 780; }
.turn-card small { color: #dfc99d; font-size: 10px; }

.street-ground {
  margin: 0 auto; width: min(calc(100% - 14px), 460px, calc((100svh - 244px) * var(--board-ratio))); min-width: min(calc(100% - 14px), 244px);
  aspect-ratio: 460 / 620; border-radius: 10px; overflow: hidden; outline: 1px solid #21170eaa;
  background: var(--scene) center center / 100% 100%, var(--field);
}
#street-canvas {
  display: block; width: 100%; height: 100%; aspect-ratio: 460 / 620; touch-action: none; cursor: grab;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
body[data-turn=bot] #street-canvas, body[data-phase=over] #street-canvas { cursor: default; }
#street-canvas:active { cursor: grabbing; }
#street-canvas:focus-visible { outline: 3px solid #ffe0a2; outline-offset: -4px; }
.control-strip { display: grid; gap: 3px; min-height: 41px; justify-items: center; padding: 7px 9px; }
.street-feedback { min-height: 18px; margin: 0; font-size: 12px; text-align: center; color: #f4e4c0; }
.launch-control { width: min(100%, 300px); display: flex; gap: 8px; align-items: center; color: #f4e4be; font-size: 11px; font-weight: 700; }
.launch-control input { width: 100%; min-width: 0; min-height: 44px; accent-color: var(--gold); cursor: ew-resize; }
.launch-control span { flex: 0 0 auto; }

.result-dialog { width: min(calc(100% - 30px), 410px); max-height: calc(100svh - 22px); overflow: auto; padding: 25px 21px; border: 1px solid #4f332191; border-radius: 17px; background: #fff0d7; color: #29291f; text-align: center; box-shadow: 0 20px 95px #16120b70; }
.result-dialog::backdrop { background: #1a1910ad; backdrop-filter: blur(4px); }
.result-mode { margin: 0 0 6px; color: var(--red); text-transform: uppercase; font-size: 11px; font-weight: 800; letter-spacing: .11em; }
.result-dialog h2 { margin: 0 0 8px; font: bold 41px/.95 var(--display); letter-spacing: -.048em; overflow-wrap: anywhere; }
.result-score { margin: 12px 0; color: var(--red); font: bold 49px/1 var(--display); letter-spacing: -.04em; }
.result-summary { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.result-actions { display: grid; gap: 7px; }
.result-actions :is(button, a) { min-height: 44px; display: grid; place-content: center; padding: 6px; border: 1px solid var(--line); border-radius: 7px; text-decoration: none; font-size: 14px; font-weight: 750; }
.result-actions a { border-color: transparent; color: var(--forest); }
.play-again { border-color: #6d2427 !important; background: var(--red); color: var(--cream); }
.review-match { background: transparent; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 760px) {
  .street-shell { width: min(calc(100% - 24px), 480px); padding-bottom: 12px; }
  .street-header { min-height: 56px; }
  .brand { gap: 6px; }
  .brand-stone { width: 22px; height: 22px; }
  .brand strong { font-size: clamp(17px, 5.4vw, 24px); }
  .brand-text small { font-size: 7px; }
  .home-link { min-height: 44px; padding: 0 9px; font-size: 11px; }
  .header-actions { gap: 2px; }
  .mode-tabs { gap: 5px; margin-top: 9px; }
  .mode-tabs a { flex: 1 1 42%; padding: 6px 8px; text-align: center; font-size: 12px; min-height: 44px; }
  .street-layout { display: flex; flex-direction: column; gap: 5px; margin-top: 9px; }
  .match-guide { width: 100%; padding: 0; }
  .match-guide h1 { margin: 0 0 3px; font-size: 35px; line-height: 1; }
  .objective { max-width: none; font-size: 12px; line-height: 1.3; }
  .match-options { margin: 6px 0 1px; gap: 4px; justify-content: space-between; }
  .opponent-button { padding: 4px 7px; }
  .opponent-button, .restart-button { min-height: 44px; font-size: 11px; }
  .restart-button { gap: 4px; padding: 4px 5px; }
  .instructions { max-width: none; border-top: 0; width: 100%; }
  .instructions summary { min-height: 44px; padding: 12px 0 8px; font-size: 12px; }
  .instructions p { font-size: 12px; margin: 4px 0 7px; }
  .street-score { min-height: 51px; padding: 4px 6px; gap: 2px; }
  .score-chit { min-height: 42px; gap: 4px; padding: 3px 5px; }
  .score-chit strong { font-size: 23px; }
  .player-marble { width: 12px; height: 12px; }
  .player-name { font-size: 10px; }
  .turn-caption { font-size: 11px; }
  .turn-card small { font-size: 9px; }
  .street-ground { width: min(calc(100% - 12px), 400px, calc((100svh - 353px) * var(--board-ratio))); min-width: min(calc(100% - 12px), 220px); }
  .control-strip { min-height: 36px; gap: 0; padding: 5px 8px 7px; }
  .street-feedback { font-size: 11px; }
}
@media (max-width: 760px) and (max-height: 680px) {
  .street-shell { width: min(calc(100% - 20px), 480px); }
  .match-guide { display: contents; }
  .match-guide h1 { font-size: 29px; }
  .objective { display: none; }
  .match-options { order: 2; width: 100%; }
  .instructions { order: 3; }
  .street-ground { width: min(calc(100% - 12px), 360px, calc((100svh - 334px) * var(--board-ratio))); min-width: min(calc(100% - 12px), 204px); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }

/* Cup matches keep the story beside the board on wide screens. */
body[data-cup-stage=avlu] {
  --chapter-art: url('assets/kupa-arsa.webp');
  --chapter-wash: #352919;
  --chapter-frame: #333b28;
  --chapter-border: #887248;
  --chapter-accent: #f7d39a;
  --chapter-paper: #f7e2bc;
}

body[data-cup-stage=cini] {
  --chapter-art: url('assets/kupa-sokak.webp');
  --chapter-wash: #202b28;
  --chapter-frame: #263d38;
  --chapter-border: #68846f;
  --chapter-accent: #d4e1bd;
  --chapter-paper: #e6dbc4;
}

body[data-cup-stage] {
  background: radial-gradient(ellipse at 12% 38%, var(--chapter-paper), transparent 73%), var(--paper);
}

body[data-cup-stage] .street-layout {
  margin-top: 17px;
  row-gap: 13px;
}

body[data-cup-stage] .match-guide {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: clamp(310px, 32vw, 418px);
  padding: 20px 22px 13px;
  border: 1px solid var(--chapter-border);
  border-radius: 12px;
  overflow: hidden;
  color: #fff4dd;
  background: var(--chapter-wash);
  box-shadow: 0 7px 15px #3f2e202e;
}

body[data-cup-stage] .match-guide::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  background:
    linear-gradient(0deg, var(--chapter-wash) 7%, #1c211cda 27%, #241f1655 57%, transparent 79%),
    var(--chapter-art) 53% 32% / cover;
}

.cup-stage-kicker {
  margin: 0 0 7px;
  color: var(--chapter-accent);
  font-size: .69rem;
  font-weight: 780;
  letter-spacing: .085em;
  line-height: 1;
  text-transform: uppercase;
}

body[data-cup-stage] .match-guide h1 {
  margin: 0 0 4px;
  font-size: clamp(2.6rem, 6vw, 4.6rem);
  line-height: .94;
  text-wrap: initial;
}

body[data-cup-stage] .objective {
  max-width: 35ch;
  color: #fff1d2;
  font-size: .98rem;
  font-weight: 660;
  line-height: 1.32;
}

.cup-brief {
  max-width: 37ch;
  margin: 8px 0 0;
  color: #fbebcdec;
  font-size: .82rem;
  line-height: 1.35;
}

body[data-cup-stage] .match-options { margin: 6px 0 0; }

body[data-cup-stage] .restart-button {
  min-height: 44px;
  padding: 5px 8px 5px 0;
  color: var(--chapter-accent);
}

body[data-cup-stage] .restart-button:hover { background: #ebc37626; }

body[data-cup-stage] .street-card {
  background: var(--chapter-frame);
  border-color: var(--chapter-border);
}

body[data-cup-stage] .score-chit.active {
  border-color: var(--chapter-border);
  background: #14231861;
}

.cup-result-note { margin: 0 0 13px; color: var(--forest); font-size: 14px; font-weight: 700; }
.result-actions .result-next { color: var(--cream); }
.result-next:not([hidden]) + .play-again { color: var(--forest); border-color: var(--line) !important; background: transparent; }

@media (max-width: 760px) {
  body[data-cup-stage] .street-layout { margin-top: 8px; row-gap: 6px; }
  body[data-cup-stage] .match-guide {
    min-height: 126px;
    padding: 12px 12px 10px;
    border-radius: 9px;
    justify-content: flex-end;
  }
  body[data-cup-stage] .match-guide::before {
    background:
      linear-gradient(90deg, #221d17e9 7%, #242117ba 40%, #29251946 76%, #29251919),
      linear-gradient(0deg, #1b2117db, transparent 66%),
      var(--chapter-art) center 52% / cover;
  }
  .cup-stage-kicker { margin-bottom: 5px; padding-right: 108px; font-size: .62rem; overflow-wrap: anywhere; }
  body[data-cup-stage] .match-guide h1 { margin-bottom: 4px; font-size: clamp(1.6rem, 7vw, 2.4rem); }
  body[data-cup-stage] .objective { display: block; font-size: .76rem; }
  .cup-brief { max-width: 45ch; margin: 4px 0 0; font-size: .7rem; }
  body[data-cup-stage] .match-options { position: absolute; right: 6px; top: 0; width: auto; margin: 0; }
  body[data-cup-stage] .restart-button { background: #19241c86; padding: 5px 6px; font-size: .62rem; }
  body[data-cup-stage] .restart-button span:first-child { font-size: 17px; }
  body[data-cup-stage] .street-ground {
    width: min(calc(100% - 12px), 400px, calc((100svh - 295px) * var(--board-ratio)));
    min-width: min(calc(100% - 12px), 178px);
  }
  body[data-cup-stage=cini] .street-ground { width: min(calc(100% - 12px), 400px, calc((100svh - 333px) * var(--board-ratio))); }
}

@media (max-width: 760px) and (max-height: 680px) {
  body[data-cup-stage] .match-guide { min-height: 109px; padding: 8px 10px; }
  body[data-cup-stage] .street-ground { width: min(calc(100% - 12px), 360px, calc((100svh - 270px) * var(--board-ratio))); }
  body[data-cup-stage=cini] .street-ground { width: min(calc(100% - 12px), 360px, calc((100svh - 320px) * var(--board-ratio))); }
}
