:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: "New York", "Iowan Old Style", Georgia, serif;
  --ink: #1b2c24;
  --paper: #f5ecda;
  --paper-line: #ddcfb6;
  --paper-muted: #5d6252;
  --chalk: #fff3dc;
  --muted: #d1c1a7;
  --gold: #f4cd82;
  --teal: #b8e1d5;
  --coral: #ffc6a2;
  --line: rgba(249, 232, 190, .19);
  --arena-art: url("assets/saha.webp");
  --arena-ground: #8b6038;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  isolation: isolate;
  display: grid;
  align-items: center;
  color: var(--chalk);
  background: #17261e;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body[data-arena="aksam"] { --arena-art: url("assets/kupa-final-zemin.webp"); --arena-ground: #584836; }

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 15%, rgba(18, 40, 27, .06), rgba(10, 24, 18, .93) 91%),
    linear-gradient(rgba(13, 33, 23, .66), rgba(14, 27, 22, .96)),
    var(--arena-art) center 39% / cover;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid #e7ad49;
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.duel-app {
  width: min(100%, 630px);
  height: 100%;
  /* The 460 × 620 board ratio keeps the controls close on tall phones. */
  height: min(100dvh, calc(134.8vw + 134px));
  max-height: 954px;
  margin-inline: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding:
    max(4px, env(safe-area-inset-top, 0px))
    env(safe-area-inset-right, 0px)
    max(4px, env(safe-area-inset-bottom, 0px))
    env(safe-area-inset-left, 0px);
  background: linear-gradient(160deg, rgba(32, 49, 38, .72), rgba(13, 29, 24, .8));
  border-inline: 1px solid rgba(249, 232, 190, .08);
}

.hud {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: stretch;
  gap: 7px;
  padding: 8px 8px 10px;
}

.player {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  min-width: 0;
  min-height: 48px;
  padding: 7px;
  color: var(--teal);
  background: rgba(12, 26, 20, .42);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: background .18s, border-color .18s;
}

.player.p1 { color: var(--coral); }

.player.active {
  background: rgba(231, 207, 158, .12);
  border-color: currentColor;
}

.player .name {
  font-size: clamp(.6rem, 2.2vw, .72rem);
  font-weight: 760;
  letter-spacing: .055em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.p1 .name { text-align: right; }

.player strong {
  font-family: var(--display);
  font-size: clamp(1.2rem, 5vw, 1.75rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.chip {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: 0 2px 4px #0009, inset 0 0 2px #fff7;
}

.p0 .chip {
  background: radial-gradient(circle at 30% 25%, #fff 0 10%, #b9e6e1 14%, #589f9c 54%, #1d494b 92%);
}

.p1 .chip {
  background: radial-gradient(circle at 30% 25%, #fff 0 10%, #ffc9aa 14%, #c16646 54%, #63301f 92%);
}

.turn-summary {
  align-self: center;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 3px;
  block-size: 56px;
  max-width: min(35vw, 170px);
  min-width: 64px;
  text-align: center;
}

.arena-name {
  margin: 0;
  color: var(--gold);
  font-size: clamp(.53rem, 2vw, .66rem);
  line-height: 1.08;
  font-weight: 780;
  letter-spacing: .055em;
  text-transform: uppercase;
}

.turn {
  margin: 0;
  align-self: center;
  text-align: center;
  font-size: clamp(.64rem, 2.55vw, .82rem);
  line-height: 1.22;
  font-weight: 700;
  color: #f4e5c7;
}

.board {
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
  min-height: 0;
  padding-inline: 6px;
}

#duel-canvas {
  display: block;
  touch-action: none;
  background: var(--arena-ground) var(--arena-art) center / cover no-repeat;
  border-radius: 10px;
  outline: 1px solid rgba(250, 226, 177, .44);
  box-shadow: 0 0 0 4px #11221a, 0 0 0 5px #c4a48655, 0 12px 32px #070f0bd9;
}

.controls {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 12px 9px 8px;
}

.round, .spin {
  background: linear-gradient(165deg, #293c30, #17291f);
  color: var(--chalk);
  border: 1px solid var(--line);
  box-shadow: 0 2px 5px #07110d70, inset 0 1px #fff1;
}

.round {
  width: 48px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 11px;
}

.round svg {
  width: 21px;
  height: 21px;
  color: var(--gold);
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
}

.hint {
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-size: .75rem;
  line-height: 1.35;
}

.spin {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 46px;
  min-width: 84px;
  padding: 4px 10px 4px 5px;
  border-radius: 11px;
  font-size: .79rem;
  font-weight: 700;
}

.spin:disabled { opacity: .5; cursor: default; }
.spin canvas { width: 34px; height: 34px; flex: none; }

dialog.sheet {
  width: min(440px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: 22px;
  overflow-y: auto;
  color-scheme: light;
  color: var(--ink);
  border: 1px solid #e5d5b8;
  border-radius: 17px;
  background: var(--paper);
  box-shadow: 0 8px 18px #040c0870, 0 30px 100px #040c08bd;
  scrollbar-width: thin;
}

dialog.sheet::backdrop {
  background: #091b14ba;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.sheet h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  text-wrap: balance;
  font-size: clamp(2.3rem, 7vw, 3.1rem);
  letter-spacing: -.055em;
  line-height: .99;
}

.eyebrow {
  margin: 0 0 8px;
  color: #775325;
  font-size: .69rem;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.rules {
  margin: 12px 0 17px;
  color: var(--paper-muted);
  font-size: .84rem;
  line-height: 1.55;
}

#menu { padding: 0; }

#menu .menu-intro {
  display: flex;
  position: relative;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 186px;
  padding: 23px 20px 18px;
  color: var(--chalk);
  background-color: #725135;
  background-image:
    linear-gradient(0deg, #1c160f 1%, rgba(28, 22, 15, .92) 18%, rgba(28, 22, 17, .2) 73%, transparent),
    url("assets/sokak-kapak.webp"),
    url("assets/kuyu.webp");
  background-position: center, 70% center, center 30%;
  background-size: cover;
  background-repeat: no-repeat;
}

.mode-brand {
  margin: 0 0 7px;
  color: #ffdb97;
  font-size: .75rem;
  font-weight: 750;
  line-height: 1.2;
}
.menu-intro #menu-title { max-width: min(100%, 13ch); overflow-wrap: anywhere; }
html:lang(de) .menu-intro #menu-title {
  max-width: 100%;
  font-size: clamp(2.05rem, 5.5vw, 3.45rem);
  hyphens: auto;
}
.menu-intro .eyebrow { color: var(--gold); }
.menu-intro .rules { margin-bottom: 0; color: #f0dfc2; }

.campaign { padding: 18px 17px 0; }

.campaign-progress {
  display: grid;
  grid-template-columns: auto minmax(32px, 1fr) auto;
  align-items: center;
  gap: 9px;
  font-size: .74rem;
  font-weight: 750;
  color: #344c39;
  margin: 0 0 11px;
}
.campaign-progress progress {
  appearance: none;
  width: 100%;
  height: 5px;
  border: 0;
  border-radius: 10px;
  background: #ded1b8;
  color: #536d49;
}
.campaign-progress progress::-webkit-progress-bar { border-radius: 10px; background: #ded1b8; }
.campaign-progress progress::-webkit-progress-value { border-radius: 10px; background: #536d49; }
.campaign-progress progress::-moz-progress-bar { border-radius: 10px; background: #536d49; }
.campaign-progress strong { font-variant-numeric: tabular-nums; }
.cup-notice { margin: 0 0 10px; color: #762e2c; font-size: .75rem; line-height: 1.4; }

.campaign-list {
  display: grid;
  gap: 7px;
}

.campaign-stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 78px;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid #58473590;
  border-radius: 10px;
  background: var(--stage-fallback);
  color: #fff5df;
  text-align: left;
  box-shadow: 0 1px 3px #634c2435;
  transition: filter .18s, border-color .18s;
}

.campaign-stage[data-stage="avlu"] {
  --stage-art: url("assets/kupa-arsa.webp");
  --stage-fallback: #69432b;
  --stage-wash: rgba(56, 32, 22, .92);
  --stage-position: right 58%;
}

.campaign-stage[data-stage="cini"] {
  --stage-art: url("assets/kupa-sokak.webp");
  --stage-fallback: #4b4735;
  --stage-wash: rgba(35, 42, 34, .94);
  --stage-position: right 58%;
}

.campaign-stage[data-stage="aksam"] {
  --stage-art: url("assets/kupa-final.webp");
  --stage-fallback: #64412e;
  --stage-wash: rgba(58, 32, 28, .94);
  --stage-position: right 45%;
}

.campaign-stage::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background:
    linear-gradient(90deg, var(--stage-wash), var(--stage-wash) 18%, rgba(28, 26, 19, .63) 58%, rgba(18, 21, 18, .16)),
    var(--stage-art) var(--stage-position) / cover;
  transition: filter .18s;
}

.campaign-stage:disabled, .campaign-stage[aria-disabled="true"] {
  cursor: default;
  color: #eee2d0;
}

.campaign-stage:disabled::before, .campaign-stage[aria-disabled="true"]::before {
  filter: saturate(.66);
}

.campaign-stage:not(:disabled):not([aria-disabled="true"]) {
  border-color: #edc983;
  box-shadow: 0 0 0 1px #a56e3c, 0 2px 4px #614b2650;
}

.stage-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.stage-name {
  font-family: var(--display);
  font-size: clamp(1rem, 4.7vw, 1.23rem);
  letter-spacing: -.025em;
  line-height: 1.02;
  font-weight: 700;
}
.stage-name, .stage-rival, .stage-objective, .stage-status { overflow-wrap: anywhere; }

.stage-rival {
  font-size: .71rem;
  color: #ffe1a8;
  line-height: 1.3;
  font-weight: 750;
}
.stage-objective { color: #fcefd7; font-size: .68rem; line-height: 1.25; }

.stage-status {
  max-width: 88px;
  padding: 4px 6px;
  border-radius: 4px;
  background: #241f1999;
  font-size: .63rem;
  font-weight: 750;
  line-height: 1.15;
  text-align: center;
}

.campaign-stage:not(:disabled):not([aria-disabled="true"]) .stage-status {
  color: #302618;
  background: #f5d595;
}

.campaign-stage[data-state="complete"] {
  border-color: #b9c7a2;
  box-shadow: 0 1px 3px #634c2435;
}

.campaign-stage[data-state="complete"] .stage-status {
  color: #233d2a;
  background: #d7e7bb;
}

.menu-secondary { padding: 10px 17px 11px; }
body[data-entry=classic] .campaign, body[data-entry=classic] .classic-rules { display: none; }

.classic-matches {
  border-block: 1px solid var(--paper-line);
  color: #334737;
}

.classic-matches summary {
  min-height: 44px;
  padding-block: 12px;
  cursor: pointer;
  line-height: 20px;
  font-size: .81rem;
  font-weight: 740;
}

.classic-matches summary::marker { color: #596f57; }
.classic-matches .choices { margin: 0 0 9px; }
.classic-rules { margin: 0 0 10px; color: var(--paper-muted); font-size: .76rem; line-height: 1.45; }

.choices, .actions { display: grid; gap: 7px; }

.choice {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  width: 100%;
  padding: 7px 12px;
  border: 1px solid #daceb7;
  border-radius: 8px;
  background: #fbf2e1;
  color: #273c2f;
  text-align: left;
}

.choice b { font-size: .88rem; }
.choice span { font-size: .73rem; color: #565c4b; }
.choice.primary { color: #fff1d8; background: #294936; border-color: #294936; }
.choice.primary span { color: #f4d58e; }
.choice:disabled { opacity: .5; cursor: default; }

.menu-intro #resume { margin-top: 15px; background: #f0cd89; color: #382a1a; border-color: #f0cd89; }
.menu-intro #resume span { color: #382a1a; }

.toggles {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0 12px;
  margin: 4px 0 0;
}

.toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 2px 0;
  color: #394b39;
  background: none;
  border: 0;
  font-size: .71rem;
  font-weight: 640;
  text-align: left;
}

.toggle i {
  width: 29px;
  height: 17px;
  flex: none;
  position: relative;
  border-radius: 9px;
  background: #7a7668;
  transition: background .18s;
}

.toggle i::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff5e6;
  transition: transform .18s;
}

.toggle[aria-pressed="true"] i { background: #456c49; }
.toggle[aria-pressed="true"] i::after { transform: translateX(12px); }

.stats {
  color: var(--paper-muted);
  margin: 4px 0 1px;
  font-size: .72rem;
  line-height: 1.3;
}

.quick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  color: #315943;
  font-size: .78rem;
  font-weight: 750;
  text-underline-offset: 3px;
}
.menu-navigation { display: flex; flex-wrap: wrap; gap: 0 16px; }

#result { background: linear-gradient(158deg, #fcf1dc, var(--paper) 78%); }

#final-arrival { padding: 0; }
.final-hero, #result[data-cup-won=true] .result-header {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: start;
  justify-content: end;
  padding: 19px 22px;
  color: #fff2d7;
  background:
    linear-gradient(0deg, #211611e8, #34231848 54%, #2b201013),
    url("assets/kupa-final.webp") center 57% / cover #754831;
}
.final-hero .eyebrow, #result[data-cup-won=true] .result-header .eyebrow { color: #ffce81; letter-spacing: .09em; }
.arrival-body { padding: 16px 20px 10px; }
.arrival-speech { margin: 0 0 9px; font: 1.14rem/1.4 var(--display); color: #6d3d26; }
.arrival-goal { margin: 0 0 15px; color: var(--paper-muted); font-size: .82rem; }
.arrival-back { min-height: 44px; margin-top: 5px; padding: 0 3px; border: 0; background: none; color: #315943; font-size: .78rem; font-weight: 740; text-decoration: underline; text-underline-offset: 3px; }
#result[data-cup-won=true] .result-header { margin: -22px -22px 12px; }
#result[data-cup-won=true] .result-header h1 { max-width: min(100%, 15ch); overflow-wrap: anywhere; }
#to-menu.primary { order: -1; background: #7b332a; border-color: #6c2b24; }

.result-caption {
  margin: 9px 0 0;
  color: var(--paper-muted);
  font-size: .87rem;
  line-height: 1.4;
}

.result-lines {
  display: grid;
  gap: 8px;
  margin: 15px 0;
  padding: 12px 0;
  border-block: 1px solid var(--paper-line);
}

.result-lines div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: .91rem; }
.result-lines b { font-variant-numeric: tabular-nums; }
.result-lines small { color: var(--paper-muted); font-size: .75rem; }

@media (min-width: 690px) {
  .hud { padding: 11px 13px 13px; gap: 12px; }
  .player { padding-inline: 11px; }
  .chip { width: 18px; height: 18px; }
  .controls { padding: 15px 14px 10px; gap: 12px; }
  .hint { font-size: .81rem; }
  #duel-canvas { border-radius: 14px; }

  #menu {
    width: min(850px, calc(100% - 36px));
    grid-template:
      "intro campaign" auto
      "intro secondary" 1fr / minmax(0, .94fr) minmax(0, 1.06fr);
  }

  #menu[open] { display: grid; }
  body[data-entry=classic] #menu { grid-template-areas: "intro secondary" "intro secondary"; }

  #menu .menu-intro {
    grid-area: intro;
    min-height: 476px;
    padding: 28px;
    background-image:
      linear-gradient(0deg, #1c160f 17%, rgba(28, 22, 15, .96) 29%, rgba(26, 22, 16, .31) 59%, rgba(14, 18, 14, .05)),
      url("assets/sokak-kapak.webp"),
      url("assets/kuyu.webp");
    background-position: center, 73% top, 52% 40%;
    background-size: cover, auto 77%, cover;
  }

  .menu-intro #menu-title { font-size: clamp(3.5rem, 7.8vw, 5.35rem); }
  .menu-intro .rules { max-width: 32ch; font-size: .88rem; }

  .campaign { grid-area: campaign; padding: 24px 23px 0; }
  .campaign-list { gap: 9px; }
  .campaign-stage { min-height: 90px; padding-inline: 12px; gap: 10px; }
  .stage-status { min-width: 48px; padding: 5px 7px; }
  .menu-secondary { grid-area: secondary; padding: 12px 23px 10px; }
  .toggles { grid-template-columns: .8fr 1fr 1.5fr; gap: 9px; }
}

@media (max-width: 350px) {
  .player { gap: 4px; padding: 5px; }
  .chip { width: 11px; height: 11px; }
  .campaign-stage { padding-inline: 8px; gap: 6px; }
  .stage-status { max-width: 69px; padding-inline: 4px; }
}

@media (hover: hover) {
  .campaign-stage:not(:disabled):not([aria-disabled="true"]):hover { filter: brightness(1.15); }
  .choice:not(:disabled):hover { filter: brightness(.96); }
  .round:hover, .spin:not(:disabled):hover { border-color: #f4cd82a0; }
}

@media (prefers-reduced-motion: reduce) {
  .player, .toggle i, .toggle i::after, .campaign-stage, .campaign-stage::before { transition: none; }
}
