:root {
  color-scheme: dark;
  --bg: #102b21;
  --bg-deep: #071711;
  --paper: #f3e6bd;
  --paper-dim: #cdbf8b;
  --ink: #2c1f11;
  --wood: #7b512b;
  --wood-dark: #382414;
  --rope: #b58a4b;
  --bamboo: #caa45a;
  --bamboo-light: #efd080;
  --gold: #ffd45d;
  --leaf: #4f8e54;
  --red: #c94f38;
  --shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  height: 100%;
  margin: 0;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  color: var(--paper);
  background:
    linear-gradient(90deg, rgba(202, 164, 90, 0.08) 0 2px, transparent 2px 58px),
    radial-gradient(circle at 22% 0%, rgba(189, 160, 83, 0.16), transparent 28%),
    linear-gradient(155deg, #071711 0%, #15372a 48%, #081913 100%);
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(243, 230, 189, 0.08), transparent 30%),
    radial-gradient(circle at 50% 100%, rgba(6, 12, 8, 0.34), transparent 50%);
  content: "";
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(7, 23, 17, 0.94), rgba(14, 46, 34, 0.96)),
    var(--bg-deep);
}

.loading-panel {
  width: min(310px, 86vw);
  padding: 18px 18px 16px;
  border: 1px solid rgba(239, 208, 128, 0.34);
  border-radius: 8px;
  color: #fff4cd;
  background:
    linear-gradient(180deg, rgba(122, 80, 38, 0.9), rgba(45, 31, 18, 0.94));
  box-shadow:
    inset 0 0 0 1px rgba(42, 27, 13, 0.5),
    0 18px 42px rgba(0, 0, 0, 0.36);
}

.loading-kicker {
  display: block;
  color: var(--paper-dim);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0;
}

.loading-panel strong {
  display: block;
  margin-top: 4px;
  font-size: 23px;
  line-height: 1.05;
}

.loading-progress {
  margin: 14px 0 8px;
  color: #ead7a2;
  font-size: 13px;
  font-weight: 820;
}

.loading-track {
  height: 9px;
  overflow: hidden;
  border: 1px solid rgba(239, 208, 128, 0.25);
  border-radius: 999px;
  background: rgba(22, 18, 12, 0.58);
}

.loading-bar {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #9c6b2e, #f0cf76 72%, #fff1a8);
  transition: width 180ms ease;
}

.archery-page {
  position: relative;
  z-index: 1;
  width: min(1040px, calc(100vw - 14px));
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 7px;
  margin: 0 auto;
  overflow: hidden;
  padding: max(7px, env(safe-area-inset-top)) 0 max(7px, env(safe-area-inset-bottom));
}

.game-topbar,
.range-shell,
.control-panel,
.status-strip,
.result-panel {
  min-width: 0;
  border: 1px solid rgba(181, 138, 75, 0.42);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.game-topbar {
  min-height: 50px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background:
    linear-gradient(180deg, rgba(136, 91, 43, 0.9), rgba(61, 39, 21, 0.9)),
    var(--wood-dark);
}

.home-link {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  overflow: hidden;
  border: 1px solid rgba(239, 208, 128, 0.25);
  border-radius: 7px;
  background: #1b2f22;
}

.home-link img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.title-block,
.balance-pill,
.status-strip div {
  min-width: 0;
}

.title-block span,
.status-strip span,
.result-panel span,
.stake-label {
  display: block;
  color: var(--paper-dim);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0;
}

h1 {
  margin: 2px 0 0;
  overflow: hidden;
  color: #fff4cd;
  font-size: clamp(18px, 4.8vw, 27px);
  line-height: 1.02;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.balance-pill {
  min-width: 78px;
  padding: 6px 9px;
  border: 1px solid rgba(239, 208, 128, 0.25);
  border-radius: 7px;
  background:
    linear-gradient(180deg, rgba(66, 42, 21, 0.72), rgba(33, 25, 15, 0.68));
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: end;
  gap: 4px;
}

.balance-pill strong {
  display: block;
  color: var(--gold);
  font-size: clamp(16px, 4.2vw, 23px);
  line-height: 1;
}

.coin-icon,
.wind-icon {
  display: block;
  flex: 0 0 auto;
  object-fit: contain;
}

.coin-icon {
  width: 18px;
  height: 18px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.wind-icon {
  width: 20px;
  height: 20px;
  opacity: 0.94;
}

.range-shell {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(243, 230, 189, 0.08), transparent 34%),
    rgba(5, 19, 13, 0.56);
}

.status-strip {
  position: absolute;
  left: 7px;
  right: 7px;
  top: 7px;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(94, 61, 31, 0.88), rgba(42, 30, 18, 0.82));
}

.status-strip div {
  padding: 5px 7px 6px;
  border-left: 1px solid rgba(181, 138, 75, 0.22);
}

.status-strip div:first-child {
  border-left: 0;
}

.status-strip strong {
  display: block;
  margin-top: 1px;
  color: #fff4cd;
  font-size: clamp(15px, 4vw, 22px);
  line-height: 1.02;
}

.range-hud {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 51px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  pointer-events: none;
}

.hud-left {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.wind-chip,
.remaining-arrows,
.hint-chip {
  min-width: 0;
  border: 1px solid rgba(181, 138, 75, 0.34);
  border-radius: 7px;
  background:
    linear-gradient(180deg, rgba(55, 37, 22, 0.72), rgba(24, 24, 15, 0.52));
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18);
}

.wind-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  color: var(--gold);
}

.wind-chip span {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: rgba(239, 208, 128, 0.18);
  font-weight: 950;
}

.wind-chip strong {
  min-width: 10px;
  font-size: 15px;
  line-height: 1;
}

.remaining-arrows {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 96px;
  min-height: 32px;
  padding: 4px 7px;
}

.remaining-arrow-icon {
  display: block;
  width: 13px;
  height: 24px;
  object-fit: contain;
}

.hint-chip {
  max-width: min(50vw, 360px);
  overflow: hidden;
  padding: 6px 8px;
  color: #fff0bd;
  font-size: 11px;
  font-weight: 780;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#archeryCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: none;
}

.control-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(108px, 0.42fr);
  grid-template-areas:
    "result result"
    "label label"
    "tiers action"
    "supply supply";
  gap: 6px;
  align-items: center;
  padding: 7px;
  background:
    linear-gradient(180deg, rgba(105, 70, 35, 0.92), rgba(43, 31, 19, 0.94)),
    var(--wood-dark);
}

.stake-label {
  grid-area: label;
  color: #ead7a2;
  line-height: 1;
}

.tier-row {
  grid-area: tiers;
  display: flex;
  min-width: 0;
  gap: 6px;
}

.tier-button,
.primary-action,
.supply-action {
  min-height: 46px;
  border: 1px solid rgba(239, 208, 128, 0.22);
  border-radius: 7px;
  font-weight: 900;
}

.tier-button {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  padding: 3px 4px;
  color: #f5e7b5;
  background:
    linear-gradient(180deg, rgba(55, 37, 22, 0.84), rgba(31, 24, 16, 0.82));
  box-shadow: inset 0 0 0 1px rgba(15, 10, 5, 0.22);
}

.tier-button strong {
  color: #fff4cf;
  font-size: clamp(17px, 4.6vw, 24px);
  line-height: 1;
}

.tier-button .coin-unit {
  display: grid;
  place-items: center;
  width: 18px;
  height: 14px;
}

.tier-button .coin-unit .coin-icon {
  width: 15px;
  height: 15px;
}

.tier-button[aria-checked="true"] {
  color: var(--ink);
  background:
    linear-gradient(180deg, #f6d987, #c99d45 58%, #9c6b2e);
  box-shadow:
    inset 0 0 0 1px rgba(255, 245, 190, 0.36),
    0 5px 12px rgba(0, 0, 0, 0.18);
}

.tier-button[aria-checked="true"] strong {
  color: #25190c;
}

.primary-action,
.supply-action {
  padding: 0 10px;
  color: #201409;
  background:
    linear-gradient(180deg, #f1d27a, #c9963f 56%, #865626);
  box-shadow: 0 7px 14px rgba(0, 0, 0, 0.22);
}

.primary-action {
  grid-area: action;
  min-width: 0;
  height: 100%;
}

.primary-action:disabled {
  color: rgba(243, 230, 189, 0.52);
  background: rgba(48, 35, 22, 0.7);
  box-shadow: none;
  cursor: not-allowed;
}

.supply-action {
  grid-area: supply;
  color: #fff4cd;
  background:
    linear-gradient(180deg, rgba(72, 116, 61, 0.9), rgba(39, 74, 43, 0.88));
}

.result-panel {
  grid-area: result;
  min-height: 0;
}

.result-panel:not([hidden]) {
  display: block;
}

.compact-result {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 5px 8px;
  border: 1px solid rgba(181, 138, 75, 0.42);
  border-radius: 7px;
  background:
    linear-gradient(180deg, rgba(45, 32, 19, 0.86), rgba(20, 26, 15, 0.76));
}

.result-panel[data-mode="score"] .compact-result {
  display: none;
}

.compact-result strong {
  min-width: 0;
  overflow: hidden;
  color: var(--gold);
  font-size: clamp(16px, 4.8vw, 24px);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-result p {
  margin: 0;
  color: #fff2bc;
  font-size: clamp(13px, 3.6vw, 17px);
  font-weight: 860;
  line-height: 1.1;
  text-align: right;
  white-space: nowrap;
}

.coin-line {
  display: inline-flex !important;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.coin-line span {
  display: inline;
  color: inherit;
  font: inherit;
  line-height: inherit;
}

.coin-line .coin-icon {
  width: 16px;
  height: 16px;
}

.score-card {
  position: relative;
  height: clamp(120px, 34vw, 150px);
  overflow: hidden;
  border-radius: 8px;
  color: #2c1f11;
}

.score-scroll-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.score-card-content {
  position: absolute;
  inset: 13% 16% 12%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "label value"
    "grade value"
    "rings coins"
    "comment comment";
  column-gap: 7px;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid rgba(117, 67, 24, 0.22);
  border-radius: 7px;
  background: rgba(255, 244, 205, 0.72);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.42) inset;
  text-shadow: 0 1px 0 rgba(255, 250, 220, 0.82);
}

.score-label {
  grid-area: label;
  color: rgba(61, 34, 12, 0.88);
  font-size: 10px;
  font-weight: 950;
  line-height: 1;
}

.score-main {
  display: contents;
}

.score-main strong {
  grid-area: grade;
  color: #8f2012;
  font-size: clamp(24px, 7vw, 36px);
  line-height: 0.95;
  white-space: nowrap;
}

.score-main span {
  grid-area: value;
  align-self: center;
  color: #2e1b0b;
  font-size: clamp(20px, 5.8vw, 30px);
  font-weight: 950;
  line-height: 1;
  white-space: nowrap;
}

.score-card p,
.score-card em {
  margin: 0;
  color: rgba(34, 21, 8, 0.98);
  font-size: clamp(10px, 3vw, 13px);
  font-style: normal;
  font-weight: 900;
  line-height: 1.05;
  white-space: nowrap;
}

#scoreRings {
  grid-area: rings;
}

#scoreCoins {
  grid-area: coins;
  justify-self: end;
  color: #8f2012;
}

#scoreCoins.coin-line {
  justify-content: flex-end;
}

#scoreComment {
  grid-area: comment;
  overflow: hidden;
  color: rgba(34, 21, 8, 0.9);
  text-overflow: ellipsis;
}

@media (min-width: 860px) {
  body {
    overflow: hidden;
  }

  .archery-page {
    grid-template-columns: minmax(0, 1fr) 240px;
    grid-template-rows: auto minmax(0, 1fr);
    align-content: center;
    gap: 10px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .game-topbar {
    grid-column: 1 / -1;
  }

  .range-shell {
    grid-column: 1;
    grid-row: 2;
  }

  .control-panel {
    grid-column: 2;
    grid-row: 2;
    align-self: start;
    grid-template-columns: 1fr;
    grid-template-areas:
      "result"
      "label"
      "tiers"
      "action"
      "supply";
    gap: 8px;
    padding: 9px;
  }

  .tier-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .tier-button {
    min-height: 50px;
  }

  .primary-action {
    min-height: 52px;
  }

  .compact-result {
    grid-template-columns: 1fr;
    align-items: start;
    min-height: 74px;
  }

  .compact-result p {
    text-align: left;
  }

  .score-card-content {
    inset: 14% 18% 12%;
    grid-template-columns: 1fr;
    grid-template-areas:
      "label"
      "grade"
      "value"
      "rings"
      "coins"
      "comment";
    align-content: center;
    row-gap: 1px;
  }

  .score-main strong {
    font-size: 28px;
  }

  .score-main span {
    font-size: 22px;
  }

  .score-card p,
  .score-card em {
    font-size: 10px;
  }

  #scoreCoins {
    justify-self: start;
  }
}

@media (max-width: 520px) {
  .archery-page {
    width: calc(100vw - 10px);
    gap: 6px;
  }

  .game-topbar {
    min-height: 48px;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 6px;
    padding: 5px 6px;
  }

  .home-link {
    width: 34px;
    height: 34px;
  }

  .balance-pill {
    min-width: 68px;
    padding: 5px 7px;
  }

  .status-strip {
    left: 6px;
    right: 6px;
    top: 6px;
  }

  .status-strip div {
    padding: 4px 6px 5px;
  }

  .range-hud {
    left: 7px;
    right: 7px;
    top: 47px;
    gap: 5px;
  }

  .hud-left {
    gap: 4px;
  }

  .hint-chip {
    max-width: 34vw;
  }

  .remaining-arrows {
    width: 82px;
    min-height: 30px;
    padding: 4px 5px;
  }

  .remaining-arrow-icon {
    width: 11px;
    height: 22px;
  }

  .control-panel {
    grid-template-columns: minmax(0, 1fr) minmax(98px, 0.38fr);
    gap: 5px;
    padding: 6px;
  }

  .tier-row {
    gap: 5px;
  }

  .tier-button,
  .primary-action,
  .supply-action {
    min-height: 43px;
  }

  .result-panel {
    min-height: 34px;
    padding: 4px 7px;
  }
}
