:root {
  --bg: #0b1220;
  --panel: rgba(18, 28, 48, 0.92);
  --line: rgba(120, 160, 220, 0.22);
  --text: #e8eef8;
  --muted: #8fa0b8;
  --accent: #2ec4b6;
  --accent-2: #ff8a3d;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --font: "Segoe UI", "Trebuchet MS", "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(46, 196, 182, 0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 100%, rgba(255, 138, 61, 0.12), transparent 50%),
    linear-gradient(180deg, #0a101c, var(--bg) 40%, #091018);
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

#app {
  width: min(100vw, 520px);
  height: 100%;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 14, 24, 0.55);
  backdrop-filter: blur(8px);
  flex-shrink: 0;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
  color: var(--accent);
}

.hud {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
}

.hud span {
  white-space: nowrap;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 10px;
  width: 34px;
  height: 34px;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.screen {
  display: none;
  flex: 1;
  min-height: 0;
  padding: 14px;
  overflow: auto;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#screen-game.active {
  justify-content: flex-start;
  padding: 6px 10px 12px;
  overflow: hidden;
}

.menu-panel,
.panel {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 18px;
  text-align: center;
}

.wide-panel {
  max-width: 480px;
}

.logo {
  margin: 0 0 8px;
  font-size: clamp(1.8rem, 8vw, 2.6rem);
  letter-spacing: 0.12em;
  background: linear-gradient(90deg, var(--accent), #7de2d1 45%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.menu-actions {
  display: grid;
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 14px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(46, 196, 182, 0.45);
  color: var(--text);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, #1aa896, var(--accent));
  border-color: transparent;
  color: #06221f;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #17b7a2, #48d6c8);
  border-color: transparent;
  color: #06221f;
}

.btn-primary:active {
  color: #06221f;
}

.btn-ghost {
  background: transparent;
}

.btn-sm {
  padding: 7px 10px;
  font-size: 0.85rem;
}

.player-line {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.api-status {
  font-size: 0.8rem;
}

.api-status.online {
  color: var(--accent);
}

.howto-list {
  text-align: left;
  margin: 0 0 18px;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.55;
}

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

.live-board {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  min-height: 34px;
}

.live-top3 {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow: hidden;
  font-size: 0.72rem;
  color: var(--muted);
}

.live-chip {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-chip strong {
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}

.live-compact {
  flex: 1;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  width: 100%;
  height: auto;
  max-height: calc(100dvh - 120px);
  display: block;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #07101c;
  box-shadow: var(--shadow);
  touch-action: none;
  cursor: none;
  outline: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  border-radius: 14px;
  background: rgba(5, 10, 18, 0.78);
  text-align: center;
}

.overlay.hidden {
  display: none;
  pointer-events: none;
}

#overlay-text {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

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

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.tab {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 10px;
  font: inherit;
  cursor: pointer;
}

.tab.active {
  color: #06221f;
  background: var(--accent);
  border-color: transparent;
  font-weight: 700;
}

.leaders-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  text-align: left;
  max-height: 42vh;
  overflow: auto;
}

.leaders-list li {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}

.leaders-list .rank {
  color: var(--accent);
  font-weight: 700;
}

.leaders-list .score {
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.muted {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.result-score {
  margin: 8px 0 4px;
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--accent);
}

.name-field {
  display: grid;
  gap: 6px;
  text-align: left;
  margin: 14px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.name-field input,
.editor-name {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}

h2,
h3 {
  margin: 0;
  font-size: 1.3rem;
}

/* Sheet */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet.hidden {
  display: none !important;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.sheet-panel {
  position: relative;
  width: min(100vw, 520px);
  max-height: 55dvh;
  background: #121c30;
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 8px 14px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  touch-action: none;
}

.sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.25);
  margin: 4px auto 10px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.sheet-list {
  max-height: none;
  flex: 1;
  min-height: 0;
}

.rate-box {
  margin: 10px 0;
}

.stars {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.stars button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  cursor: pointer;
  padding: 4px;
}

.stars button.on {
  color: var(--accent-2);
}

.catalog-list,
.shop-list {
  display: grid;
  gap: 8px;
  text-align: left;
  max-height: 48vh;
  overflow: auto;
  margin-bottom: 12px;
}

.catalog-card,
.shop-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.2);
  display: grid;
  gap: 6px;
}

.catalog-card-head,
.shop-card-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.badge {
  font-size: 0.75rem;
  color: #06221f;
  background: var(--accent-2);
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 700;
}

.catalog-meta {
  font-size: 0.82rem;
  color: var(--muted);
}

.catalog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.slots-line {
  margin: 8px 0 12px;
  font-size: 0.88rem;
}

.editor-root {
  text-align: left;
  margin-bottom: 12px;
}

.editor-toolbar {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.editor-brushes {
  display: flex;
  gap: 6px;
}

.brush {
  width: 40px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.brush.active {
  outline: 2px solid var(--accent);
}

.brush-1 { background: #1a9e93; }
.brush-2 { background: #d96b22; }
.brush-3 { background: #c93d4c; }

.editor-speed {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.editor-speed input {
  flex: 1;
}

.editor-grid {
  display: grid;
  gap: 3px;
  user-select: none;
  touch-action: none;
}

.editor-cell {
  aspect-ratio: 1.8;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.03);
  padding: 0;
  cursor: crosshair;
}

.editor-cell.hp-1 { background: #1a9e93; }
.editor-cell.hp-2 { background: #d96b22; }
.editor-cell.hp-3 { background: #c93d4c; }

.shop-note {
  font-size: 0.8rem;
  margin: 0 0 12px;
}

@media (max-height: 700px) {
  .menu-panel,
  .panel {
    padding: 16px 14px;
  }

  .logo {
    font-size: 1.8rem;
  }

  #game {
    max-height: calc(100dvh - 108px);
  }
}

@media (max-width: 380px), (max-height: 620px) {
  .live-top3 .live-chip:nth-child(n + 2) {
    display: none;
  }
}
