.popup {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
}
.popup > .backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 14, 0.65);
  backdrop-filter: blur(3px);
  animation: popup-fade 0.15s ease-out;
}
.popup > .main {
  position: relative;
  width: min(440px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 20px 24px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: popup-in 0.18s ease-out;
}
.popup > .main > h2 {
  margin: 0 40px 16px 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.popup > .main > .close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--muted);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
}
.popup > .main > .close:hover {
  background: var(--surface-2);
  color: var(--text);
}
.popup.cannot-close > .main > .close {
  display: none;
}
.popup:not(.cannot-close) > .backdrop {
  cursor: pointer;
}

.popup .content h1 {
  margin: 0 0 16px;
  font-family: var(--font-title);
  font-size: 1.5rem;
  line-height: 1.2;
  color: var(--text);
}
.popup .content p {
  margin: 0 0 12px;
}
.popup .content input + .btn,
.popup .content > .btn {
  display: flex;
  width: 100%;
  margin-top: 16px;
}
.popup .content .error {
  margin-top: 8px;
  color: var(--danger);
  font-size: 0.9rem;
}

@keyframes popup-fade {
  from {
    opacity: 0;
  }
}
@keyframes popup-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}
@media (prefers-reduced-motion: reduce) {
  .popup > .backdrop,
  .popup > .main {
    animation: none;
  }
}
.game-bar {
  position: relative;
  display: flex;
  height: 32px;
  margin: 8px 0 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
  user-select: none;
}
.game-bar > .gray-zone,
.game-bar > .green-zone,
.game-bar > .gold-zone {
  flex: 0 0 auto;
  height: 100%;
}
.game-bar > .gray-zone:nth-child(1 of .gray-zone, .green-zone, .gold-zone),
.game-bar > .green-zone:nth-child(1 of .gray-zone, .green-zone, .gold-zone),
.game-bar > .gold-zone:nth-child(1 of .gray-zone, .green-zone, .gold-zone) {
  border-top-left-radius: 7px;
  border-bottom-left-radius: 7px;
}
.game-bar > .gray-zone:nth-last-child(1 of .gray-zone, .green-zone, .gold-zone),
.game-bar > .green-zone:nth-last-child(1 of .gray-zone, .green-zone, .gold-zone),
.game-bar > .gold-zone:nth-last-child(1 of .gray-zone, .green-zone, .gold-zone) {
  border-top-right-radius: 7px;
  border-bottom-right-radius: 7px;
}
.game-bar > .gray-zone {
  background: repeating-linear-gradient(-45deg, var(--surface-2) 0 6px, var(--surface) 6px 12px);
}
.game-bar > .green-zone {
  background: linear-gradient(to bottom, #5cc97a, #2f8a4a);
  box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.25), inset -1px 0 0 rgba(0, 0, 0, 0.3);
}
.game-bar > .gold-zone {
  background: linear-gradient(110deg, #b8862b 20%, #ffe08a 45%, #e2b04a 55%, #b8862b 80%);
  background-size: 250% 100%;
  box-shadow: 0 0 10px rgba(226, 176, 74, 0.6);
  animation: gather-gold-shine 1.6s linear infinite;
}
.game-bar > .game-cursor {
  position: absolute;
  top: -6px;
  bottom: -6px;
  left: calc(var(--pos, 0) * 100%);
  width: 4px;
  margin-left: -2px;
  border-radius: 2px;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 0 8px rgba(255, 255, 255, 0.8);
  pointer-events: none;
}
.game-bar > .game-cursor::before {
  content: "";
  position: absolute;
  top: -7px;
  left: 50%;
  margin-left: -6px;
  border: 6px solid transparent;
  border-top-color: #ffffff;
  border-bottom: 0;
}
.game-bar.result-gray > .game-cursor {
  background: var(--muted);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
}
.game-bar.result-gray > .game-cursor::before {
  border-top-color: var(--muted);
}
.game-bar.result-green {
  animation: gather-flash-green 0.5s ease-out;
}
.game-bar.result-gold {
  animation: gather-flash-gold 0.9s ease-out;
}

@keyframes gather-gold-shine {
  from {
    background-position: 166.667% 0;
  }
  to {
    background-position: 0% 0;
  }
}
@keyframes gather-flash-green {
  30% {
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 0 3px rgba(92, 201, 122, 0.6), 0 0 18px rgba(92, 201, 122, 0.5);
  }
}
@keyframes gather-flash-gold {
  25%, 60% {
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 0 3px rgba(255, 224, 138, 0.8), 0 0 28px rgba(226, 176, 74, 0.8);
  }
}
.game-bar.result-green ~ .btn {
  background: linear-gradient(to bottom, #5cc97a, #2f8a4a);
  color: #06210f;
  box-shadow: 0 0 14px rgba(92, 201, 122, 0.45);
}
.game-bar.result-green ~ .btn:hover {
  background: linear-gradient(to bottom, #6fd88c, #379a54);
  color: #06210f;
}
.game-bar.result-green ~ .btn:focus-visible {
  outline-color: #6fd88c;
}

.game-bar.result-gold ~ .btn {
  background: linear-gradient(110deg, #b8862b 20%, #ffe08a 45%, #e2b04a 55%, #b8862b 80%);
  background-size: 250% 100%;
  color: var(--accent-ink);
  box-shadow: 0 0 18px rgba(226, 176, 74, 0.6);
  animation: gather-gold-shine 1.6s linear infinite;
}
.game-bar.result-gold ~ .btn:hover {
  color: var(--accent-ink);
  filter: brightness(1.08);
}

@media (prefers-reduced-motion: reduce) {
  .game-bar > .gold-zone,
  .game-bar.result-green,
  .game-bar.result-gold,
  .game-bar.result-gold ~ .btn {
    animation: none;
  }
}
:root {
  --bg: #14171d;
  --surface: #1f242d;
  --surface-2: #282e39;
  --border: #343b48;
  --text: #e9e6df;
  --muted: #9aa3b2;
  --accent: #e2b04a;
  --accent-hover: #edc265;
  --accent-ink: #1d1606;
  --danger: #e5604f;
  --radius: 10px;
  --shadow: 0 18px 48px rgb(0 0 0 / 0.45);
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  --font-title: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body > h1,
body > h2 {
  grid-row: 1;
  display: flex;
  align-items: center;
  min-height: 52px;
  margin: 0;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

body > h1 {
  grid-column: 1;
  font-family: var(--font-title);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
  line-height: 1;
  padding-top: 6px;
}

body > h2 {
  grid-column: 2;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: normal;
  color: var(--muted);
  white-space: nowrap;
}

.client {
  grid-column: 1/-1;
  grid-row: 2;
  position: relative;
  min-height: 0;
  overflow: hidden;
}
.client canvas {
  display: block;
}

a,
a:visited {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

body > a, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s, transform 0.05s;
}
body > a:visited, .btn:visited {
  color: var(--accent-ink);
}
body > a:hover, .btn:hover {
  background: var(--accent-hover);
  color: var(--accent-ink);
  text-decoration: none;
}
body > a:active, .btn:active {
  transform: translateY(1px);
}
body > a:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent-hover);
  outline-offset: 2px;
}
body > a:disabled, .btn:disabled, body > a.disabled, .disabled.btn {
  background: var(--surface-2);
  color: var(--muted);
  box-shadow: none;
  filter: none;
  animation: none;
  cursor: not-allowed;
}
body > a:disabled:hover, .btn:disabled:hover, body > a.disabled:hover, .disabled.btn:hover {
  background: var(--surface-2);
  color: var(--muted);
  text-decoration: none;
}
body > a:disabled:active, .btn:disabled:active, body > a.disabled:active, .disabled.btn:active {
  transform: none;
}
body > a.disabled, .disabled.btn {
  pointer-events: none;
}

body > a {
  grid-column: 1/-1;
  grid-row: 2;
  place-self: center;
  padding: 14px 28px;
  font-size: 1.05rem;
}

label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

input[type=text],
input:not([type]) {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type=text]::placeholder,
input:not([type])::placeholder {
  color: var(--muted);
  opacity: 0.7;
}
input[type=text]:focus,
input:not([type]):focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(226, 176, 74, 0.25);
}

span.resource {
  mask-size: contain;
  mask-repeat: no-repeat;
  width: 20px;
  height: 20px;
  background: var(--accent-ink);
}
span.resource.wood {
  mask-image: url("/assets/wood.svg");
}
span.resource.stone {
  mask-image: url("/assets/stone.svg");
}
span.resource.iron {
  mask-image: url("/assets/iron.svg");
}
span.resource.gold {
  mask-image: url("/assets/gold.svg");
}

@media (max-width: 480px) {
  body > h1 {
    font-size: 1.2rem;
  }
  body > h2 {
    padding-left: 8px;
    font-size: 0.8rem;
  }
}
