:root {
  --bg-0: #06131e;
  --bg-1: #0c2232;
  --bg-2: #215269;
  --panel: rgba(9, 18, 30, 0.8);
  --panel-border: rgba(255, 218, 167, 0.24);
  --text: #f8f2e6;
  --muted: #c9d1c4;
  --accent: #ffbf69;
  --accent-strong: #ff8f3d;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(255, 193, 110, 0.18), transparent 28%),
    linear-gradient(180deg, var(--bg-2), var(--bg-0));
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI Variable", sans-serif;
}

body {
  overflow-x: hidden;
}

body.mobile-panel-open {
  overflow: hidden;
}

button,
summary {
  font: inherit;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  padding: 24px;
  overflow: hidden;
}

.backdrop-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(20px);
  opacity: 0.5;
  pointer-events: none;
}

.orb-a {
  inset: 4% auto auto 6%;
  width: 280px;
  height: 280px;
  background: rgba(32, 178, 170, 0.22);
}

.orb-b {
  inset: auto 10% 4% auto;
  width: 320px;
  height: 320px;
  background: rgba(255, 122, 61, 0.18);
}

.game-frame {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 20px;
  align-items: start;
  grid-template-columns: minmax(0, 860px) minmax(280px, 340px);
  width: min(1280px, 100%);
  margin: 0 auto;
}

.canvas-shell,
.panel {
  position: relative;
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: 0 26px 60px var(--shadow);
  backdrop-filter: blur(18px);
}

.canvas-shell {
  padding: 14px;
}

.mobile-toolbar,
.mobile-panel-header,
.mobile-panel-scrim {
  display: none;
}

.stage {
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 24%),
    url("./assets/ui/background.png") center / cover no-repeat,
    radial-gradient(circle at top, rgba(255, 233, 190, 0.12), transparent 34%),
    #09111a;
  min-height: 720px;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 720 / 1180;
  touch-action: none;
}

.hud {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(8, 13, 20, 0.4)),
    url("./assets/ui/board-panel.png") center / cover no-repeat;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.hud.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.hud-cluster,
.hud-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.hud-chip,
.chain-chip {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(5, 10, 16, 0.5);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.score-chip strong {
  font-size: 1.3rem;
}

.energy-shell {
  display: grid;
  gap: 8px;
}

.energy-copy {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.timer-copy {
  color: var(--text);
  font-weight: 700;
  text-shadow: 0 0 10px rgba(255, 213, 132, 0.2);
}

.energy-bar {
  position: relative;
  height: 40px;
}

.energy-layer,
.energy-fill-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

.energy-fill-mask {
  position: absolute;
  inset: 0;
  overflow: hidden;
  transform-origin: left center;
}

.energy-fill-image {
  filter: saturate(1.1) brightness(1.06);
}

.chain-chip {
  min-width: 118px;
  grid-template-columns: 44px 1fr;
  align-items: center;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.chain-chip.active {
  background: rgba(26, 71, 87, 0.78);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 0 18px rgba(111, 226, 255, 0.22);
  transform: translateY(-1px);
}

.chain-chip img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.eyebrow {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
}

.subtle {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}

.hud strong,
.best-card strong,
.mode-name,
.modal-score strong,
.info-panel h1,
.hero-panel h2,
.hero-title {
  font-family: "Palatino Linotype", "Book Antiqua", serif;
  font-weight: 700;
}

.icon-button,
.action-button,
.mode-card {
  border: 0;
  cursor: pointer;
  transition: transform 160ms ease, filter 160ms ease, background 160ms ease;
}

.icon-button:hover,
.action-button:hover,
.mode-card:hover {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 180, 92, 0.28), rgba(255, 109, 58, 0.28)),
    url("./assets/ui/button.png") center / cover no-repeat;
  box-shadow: 0 12px 18px rgba(0, 0, 0, 0.18);
}

.icon-button img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.overlay-screen {
  position: absolute;
  inset: 0;
  display: none;
  padding: 26px;
  align-items: center;
  justify-content: center;
  background: rgba(3, 8, 14, 0.58);
}

.overlay-screen.active {
  display: flex;
}

.hero-panel,
.modal-panel {
  width: min(100%, 610px);
  padding: 26px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(8, 13, 20, 0.62)),
    url("./assets/ui/board-panel.png") center / cover no-repeat;
}

.hero-panel {
  display: grid;
  gap: 20px;
}

.hero-title {
  display: grid;
  justify-items: center;
  margin: 0;
  color: #fff1ca;
  font-size: clamp(3rem, 8vw, 5.4rem);
  line-height: 0.75;
  letter-spacing: -0.07em;
  text-transform: uppercase;
  text-shadow: 0 8px 28px rgba(0, 0, 0, 0.55), 0 0 30px rgba(255, 185, 92, 0.2);
}

.hero-title strong {
  color: var(--accent);
  font-size: 0.62em;
  letter-spacing: 0.16em;
  transform: translateX(0.08em);
}

.hero-copy {
  margin: 0;
  text-align: center;
  color: var(--muted);
  line-height: 1.55;
}

.mode-grid {
  display: grid;
  gap: 12px;
}

.mode-card {
  display: grid;
  gap: 6px;
  padding: 18px 20px;
  text-align: left;
  border-radius: 18px;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 195, 113, 0.18), rgba(26, 41, 59, 0.84)),
    url("./assets/ui/button.png") center / cover no-repeat;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    0 16px 22px rgba(0, 0, 0, 0.15);
}

.mode-name {
  font-size: 1.28rem;
}

.mode-copy {
  color: var(--muted);
  line-height: 1.45;
}

.best-scores {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.best-card {
  display: grid;
  gap: 6px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
  text-align: center;
}

.modal-panel {
  text-align: center;
}

.modal-panel h2 {
  margin: 8px 0 14px;
  font-size: clamp(1.8rem, 3.8vw, 2.5rem);
}

.modal-score {
  margin: 8px 0;
  color: var(--muted);
  font-size: 1.02rem;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap;
}

.action-button {
  min-width: 164px;
  padding: 14px 18px;
  border-radius: 999px;
  color: #071019;
  background:
    linear-gradient(180deg, var(--accent), var(--accent-strong)),
    url("./assets/ui/button.png") center / cover no-repeat;
  box-shadow: 0 14px 20px rgba(0, 0, 0, 0.18);
}

.action-button.secondary {
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04)),
    url("./assets/ui/button.png") center / cover no-repeat;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.action-button.compact {
  min-width: 0;
  padding-inline: 16px;
}

.side-panel {
  display: grid;
  gap: 18px;
}

.policy-links {
  display: flex;
  gap: 14px;
  justify-content: center;
  padding: 0 8px 12px;
  flex-wrap: wrap;
}

.policy-links a {
  color: var(--muted);
  font-size: 0.82rem;
  text-underline-offset: 4px;
}

.board-panel {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(8, 13, 20, 0.72)),
    url("./assets/ui/board-panel.png") center / cover no-repeat;
}

.info-panel {
  padding: 22px;
}

.info-panel h1 {
  margin: 8px 0 10px;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
}

.info-panel h2 {
  margin: 8px 0 0;
  font-size: 1.2rem;
  font-family: "Palatino Linotype", "Book Antiqua", serif;
}

.info-panel p,
.control-list {
  margin: 0;
  line-height: 1.6;
  color: var(--muted);
}

.panel-inline {
  display: flex;
  gap: 14px;
  justify-content: space-between;
  align-items: start;
}

.player-panel,
.leaderboard-panel {
  display: grid;
  gap: 18px;
}

.player-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
}

.player-avatar,
.leaderboard-avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 196, 113, 0.56), rgba(35, 81, 105, 0.92));
  color: #071019;
  font-weight: 700;
}

.player-avatar {
  width: 64px;
  height: 64px;
  object-fit: cover;
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.18);
}

.leaderboard-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.auth-actions,
.leaderboard-tabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.text-button {
  border: 0;
  padding: 8px 4px;
  color: var(--muted);
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.text-button.danger {
  color: #ffb1a8;
}

.state-pill,
.leaderboard-tab,
.status-banner {
  border-radius: 999px;
  font-size: 0.82rem;
}

.state-pill {
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-weight: 700;
}

.leaderboard-tab {
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 10px 14px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.leaderboard-tab.active {
  color: #071019;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
}

.leaderboard-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
}

.leaderboard-row.current-user {
  background: rgba(255, 191, 105, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 191, 105, 0.25);
}

.leaderboard-rank,
.leaderboard-score {
  font-weight: 700;
  color: var(--text);
}

.leaderboard-player {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.leaderboard-copy {
  display: grid;
  min-width: 0;
}

.leaderboard-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-copy span {
  color: var(--muted);
  font-size: 0.82rem;
}

.leaderboard-empty {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
}

.status-banner {
  margin: 14px auto 0;
  max-width: 420px;
  padding: 12px 16px;
  line-height: 1.45;
  background: rgba(255, 255, 255, 0.06);
}

[data-tone="success"] {
  background: rgba(115, 232, 172, 0.18);
  color: #dff8e9;
}

[data-tone="warning"] {
  background: rgba(255, 191, 105, 0.16);
  color: #fff0d9;
}

[data-tone="error"] {
  background: rgba(255, 111, 97, 0.18);
  color: #ffe6e2;
}

[data-tone="info"] {
  background: rgba(102, 199, 255, 0.16);
  color: #e4f7ff;
}

.help-panel summary {
  cursor: pointer;
  list-style: none;
  font-weight: 700;
}

.help-panel summary::-webkit-details-marker {
  display: none;
}

.control-list {
  margin-top: 12px;
  padding-left: 18px;
}

.control-list li + li {
  margin-top: 8px;
}

@media (max-width: 1080px) {
  .game-frame {
    grid-template-columns: 1fr;
  }

  .mobile-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 10px;
    padding: 2px 4px;
  }

  .mobile-brand {
    display: flex;
    align-items: baseline;
    gap: 7px;
    color: var(--text);
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }

  .mobile-brand span {
    color: #fff1ca;
    font-family: "Palatino Linotype", "Book Antiqua", serif;
    font-size: 1.18rem;
  }

  .mobile-brand strong {
    color: var(--accent);
    font-size: 0.7rem;
    letter-spacing: 0.18em;
  }

  .mobile-panel-button,
  .mobile-close-button {
    border: 1px solid rgba(255, 191, 105, 0.3);
    border-radius: 999px;
    padding: 10px 15px;
    color: #071019;
    background: linear-gradient(180deg, var(--accent), var(--accent-strong));
    font-weight: 700;
    cursor: pointer;
  }

  .side-panel {
    position: fixed;
    z-index: 30;
    inset: 0 0 0 auto;
    display: none;
    width: min(92vw, 430px);
    padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
    overflow-y: auto;
    background: linear-gradient(180deg, #102c3d, #06131e 72%);
    box-shadow: -26px 0 70px rgba(0, 0, 0, 0.55);
  }

  .side-panel.mobile-open {
    display: grid;
    align-content: start;
    animation: panel-in 180ms ease-out both;
  }

  .mobile-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 4px 2px;
  }

  .mobile-panel-header > div {
    display: grid;
    gap: 4px;
  }

  .mobile-close-button {
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
  }

  .mobile-panel-scrim.active {
    position: fixed;
    z-index: 29;
    inset: 0;
    display: block;
    border: 0;
    background: rgba(1, 5, 9, 0.72);
  }

  @keyframes panel-in {
    from { transform: translateX(28px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
  }
}

@media (max-width: 860px) {
  .hud {
    grid-template-columns: 1fr;
  }

  .hud-actions {
    justify-content: space-between;
  }

  .panel-inline {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  }

  .canvas-shell {
    padding: 8px;
    border-radius: 22px;
  }

  body.game-active .mobile-toolbar {
    display: none;
  }

  .hud {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px 9px;
    margin-bottom: 8px;
    padding: 8px;
    border-radius: 16px;
  }

  .hud-cluster {
    grid-column: 1;
    grid-row: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px;
  }

  .hud-actions {
    grid-column: 2;
    grid-row: 1;
    gap: 7px;
  }

  .energy-shell {
    grid-column: 1 / -1;
    grid-row: 2;
    gap: 3px;
  }

  .hud-chip,
  .chain-chip {
    padding: 7px 9px;
    border-radius: 13px;
  }

  .hud-chip .subtle {
    display: none;
  }

  .score-chip strong {
    font-size: 1.05rem;
  }

  .energy-copy {
    padding: 0 3px;
  }

  .energy-bar {
    height: 27px;
  }

  .chain-chip {
    min-width: 70px;
    grid-template-columns: 22px 1fr;
  }

  .chain-chip img {
    width: 20px;
    height: 20px;
  }

  .icon-button {
    width: 42px;
    height: 42px;
    border-radius: 13px;
  }

  .icon-button img {
    width: 22px;
    height: 22px;
  }

  .stage {
    min-height: 0;
    border-radius: 18px;
  }

  .hud-cluster {
    flex-direction: column;
    align-items: stretch;
  }

  .overlay-screen {
    align-items: flex-start;
    padding: 10px;
    overflow-y: auto;
  }

  .player-card,
  .leaderboard-row {
    grid-template-columns: 1fr;
    text-align: left;
  }

  .hero-panel,
  .modal-panel,
  .info-panel {
    padding: 16px;
  }

  .hero-panel {
    gap: 12px;
    margin: auto 0;
  }

  .hero-title {
    font-size: clamp(2.5rem, 14vw, 4rem);
  }

  .hero-copy {
    font-size: 0.87rem;
    line-height: 1.4;
  }

  .mode-grid {
    gap: 8px;
  }

  .mode-card {
    grid-template-columns: minmax(94px, auto) 1fr;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 15px;
  }

  .mode-name {
    font-size: 1.08rem;
  }

  .mode-copy {
    font-size: 0.78rem;
    line-height: 1.3;
  }

  .best-scores {
    gap: 6px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .best-card {
    gap: 3px;
    padding: 9px 5px;
    border-radius: 13px;
  }

  .best-card .eyebrow {
    font-size: 0.54rem;
    letter-spacing: 0.08em;
  }

  .modal-actions {
    flex-direction: column;
  }

  .auth-actions,
  .leaderboard-tabs {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  .icon-button,
  .action-button,
  .mode-card,
  .chain-chip {
    transition: none;
  }
}
