:root {
  color-scheme: dark;
  --ink: #fff7e8;
  --muted: #b6c4bd;
  --panel: rgba(16, 24, 28, 0.78);
  --panel-strong: rgba(12, 17, 20, 0.92);
  --line: rgba(255, 247, 232, 0.16);
  --gold: #f7c948;
  --cyan: #2ec4b6;
  --leaf: #4caf50;
  --coral: #ef476f;
  --pepper: #d62828;
  --night: #10140f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 8%, rgba(239, 71, 111, 0.18), transparent 26rem),
    radial-gradient(circle at 82% 14%, rgba(46, 196, 182, 0.2), transparent 28rem),
    linear-gradient(135deg, #0d1510 0%, #183322 48%, #211610 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 44px;
  padding: 0 18px;
  background: var(--gold);
  color: #17110a;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(255, 209, 102, 0.2);
}

button.secondary {
  background: rgba(255, 247, 232, 0.1);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: none;
}

.shell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  width: 100%;
  min-height: 100svh;
  padding: 8px;
}

.playfield {
  position: relative;
  width: 100%;
  height: min(78svh, 720px);
  min-height: 560px;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #090e10;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  pointer-events: none;
}

body[data-screen="title"] .hud {
  opacity: 0;
}

.player-card,
.meters,
.panel,
.board {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.32);
}

.player-card {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 64px;
  border-radius: 8px;
  padding: 8px;
  pointer-events: auto;
}

.player-card img {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--cyan), var(--gold));
  object-fit: cover;
}

.player-copy {
  min-width: 0;
}

.player-copy b,
.player-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-copy b {
  font-size: 15px;
}

.player-copy span {
  color: var(--muted);
  font-size: 12px;
}

#signin {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.meters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  width: 100%;
  overflow: hidden;
  border-radius: 8px;
}

.meters div {
  padding: 8px 10px;
  background: rgba(255, 247, 232, 0.04);
}

.meters span,
.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.meters strong {
  display: block;
  margin-top: 2px;
  font-size: 19px;
  line-height: 1;
}

.panel {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: auto;
  bottom: 14px;
  width: min(520px, calc(100% - 24px));
  max-height: calc(100% - 28px);
  overflow: auto;
  transform: translateX(-50%);
  border-radius: 8px;
  padding: clamp(16px, 5vw, 24px);
  background: var(--panel-strong);
  text-align: center;
}

.over-panel {
  top: 50%;
  bottom: auto;
  transform: translate(-50%, -50%);
}

.panel h1,
.panel h2,
.board h2 {
  margin: 4px 0 10px;
  font-size: clamp(30px, 11vw, 44px);
  line-height: 0.95;
}

.panel h2,
.board h2 {
  font-size: clamp(22px, 3vw, 34px);
}

.panel p {
  margin: 0 auto 18px;
  max-width: 18rem;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: break-word;
}

.actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.market-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 18px;
}

.market-option {
  min-height: 38px;
  min-width: 0;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: rgba(255, 247, 232, 0.08);
  color: var(--ink);
  box-shadow: none;
  font-size: 12px;
}

.market-option.active {
  background: var(--leaf);
  color: #081108;
  border-color: transparent;
}

.avatar-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 0 0 18px;
}

.avatar-option {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  justify-items: start;
  gap: 5px;
  min-height: 58px;
  padding: 7px 4px;
  border: 1px solid var(--line);
  background: rgba(255, 247, 232, 0.08);
  color: var(--ink);
  box-shadow: none;
  font-size: 11px;
}

.avatar-option img {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  object-fit: cover;
  background: #173322;
}

.avatar-option.active {
  background: rgba(247, 201, 72, 0.18);
  border-color: rgba(247, 201, 72, 0.72);
}

.save-status {
  min-height: 24px;
}

.board {
  width: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: 8px;
  padding: 16px;
  overflow: auto;
}

.board-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.board h2 {
  margin: 3px 0 0;
}

.board-head button {
  width: 42px;
  min-height: 42px;
  padding: 0;
  background: rgba(255, 247, 232, 0.1);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: none;
  font-size: 20px;
}

ol {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
}

li {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 52px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 247, 232, 0.06);
  border: 1px solid rgba(255, 247, 232, 0.08);
}

li .rank {
  color: var(--gold);
  font-weight: 900;
}

li .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

li .meta,
li .stats {
  color: var(--muted);
  font-size: 12px;
}

li .stats {
  text-align: right;
}

li.muted {
  display: block;
  color: var(--muted);
  line-height: 1.45;
}

[hidden] {
  display: none !important;
}

@media (min-width: 700px) {
  .playfield {
    height: min(74svh, 760px);
    min-height: 620px;
  }

  .panel {
    top: 50%;
    bottom: auto;
    transform: translate(-50%, -50%);
    padding: clamp(22px, 4vw, 34px);
  }

  .panel h1,
  .panel h2,
  .board h2 {
    font-size: clamp(34px, 6vw, 54px);
  }

  .panel p {
    max-width: 34rem;
  }

  .market-picker,
  .avatar-picker {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .market-option {
    font-size: 13px;
  }

  .avatar-option {
    grid-template-columns: 1fr;
    justify-items: center;
    min-height: 76px;
    padding: 8px 6px;
    font-size: 12px;
  }

  .avatar-option img {
    width: 38px;
    height: 38px;
  }
}

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

  .shell {
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 14px;
    height: 100vh;
    min-height: 0;
    padding: 14px;
  }

  .playfield {
    height: auto;
    min-height: 0;
  }

  .hud {
    top: 14px;
    left: 14px;
    right: 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
  }

  .player-card {
    width: min(360px, 48vw);
  }

  .meters {
    grid-template-columns: repeat(3, 94px);
    width: auto;
  }

  .meters div {
    padding: 10px 12px;
  }

  .meters strong {
    font-size: 22px;
  }
}
