:root {
  color-scheme: dark;
  --bg: #091316;
  --panel: rgba(12, 30, 33, 0.86);
  --panel-strong: rgba(15, 39, 42, 0.94);
  --line: #e7c77f;
  --text: #f4edd4;
  --muted: #b9c3b8;
  --accent: #f2c94c;
  --warn: #eb6a4e;
  --chip: #1e484d;
  --chip-hover: #2b656b;
  --shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(56, 122, 104, 0.24), transparent 32%),
    linear-gradient(180deg, #0b1719 0%, #081012 100%);
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
}

.app-shell {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.toggle-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chip,
.primary,
.secondary {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  color: var(--text);
  background: var(--chip);
  box-shadow: var(--shadow);
}

.primary {
  background: linear-gradient(180deg, #f2c94c 0%, #d7a83e 100%);
  color: #132025;
  font-weight: 700;
}

.secondary {
  background: rgba(32, 71, 76, 0.9);
}

.hud-panel {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  background: var(--panel);
  border: 1px solid rgba(231, 199, 127, 0.26);
  border-radius: 18px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.stat strong {
  font-size: clamp(1.1rem, 3vw, 1.5rem);
}

.play-surface {
  position: relative;
  border-radius: 28px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(20, 49, 42, 0.75), rgba(11, 24, 26, 0.94));
  border: 1px solid rgba(231, 199, 127, 0.2);
  box-shadow: var(--shadow);
  min-height: 68vh;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: min(72vh, 78vw);
  min-height: 480px;
  touch-action: none;
}

.message-banner {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 16px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(13, 28, 31, 0.82);
  border: 1px solid rgba(231, 199, 127, 0.2);
  color: var(--text);
  font-size: 0.95rem;
  backdrop-filter: blur(6px);
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(4, 8, 10, 0.62);
  backdrop-filter: blur(8px);
}

.overlay.visible {
  display: flex;
}

.card {
  width: min(100%, 460px);
  background: var(--panel-strong);
  border: 1px solid rgba(231, 199, 127, 0.3);
  border-radius: 24px;
  padding: 26px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 2rem;
}

.card p {
  color: var(--muted);
  line-height: 1.45;
}

.stack {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.summary {
  display: grid;
  gap: 8px;
  color: var(--text);
  margin-top: 14px;
}

@media (hover: hover) {
  .chip:hover,
  .secondary:hover {
    background: var(--chip-hover);
    cursor: pointer;
  }

  .primary:hover {
    filter: brightness(1.06);
    cursor: pointer;
  }
}

@media (max-width: 900px) {
  .topbar {
    flex-direction: column;
  }

  .toggle-group {
    justify-content: flex-start;
  }

  .hud-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #gameCanvas {
    height: min(70vh, 122vw);
    min-height: 420px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 10px;
  }

  .hud-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat:last-child {
    grid-column: 1 / -1;
  }

  .chip,
  .primary,
  .secondary {
    width: 100%;
  }

  #gameCanvas {
    min-height: 360px;
  }

  .message-banner {
    font-size: 0.88rem;
  }
}