* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #0a0a12;
  color: #e8e8f0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}
body {
  display: flex;
  flex-direction: column;
  max-height: 100dvh;
}

#topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  padding: 10px 12px;
  background: linear-gradient(180deg, #141428 0%, #0e0e1a 100%);
  border-bottom: 1px solid #00ff8822;
  font-size: 13px;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 10px;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.5px;
  color: #0a0a12;
  background: linear-gradient(135deg, #00ff88, #00e5ff);
  box-shadow: 0 0 16px #00ff8866;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 14px; }
.muted { color: #8a8aa0; font-size: 12px; }
.stats-chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: #1a1a30;
  border: 1px solid #00e5ff33;
  color: #9ef;
  font-size: 11px;
  white-space: nowrap;
}
#status { color: #aaa; flex: 1; min-width: 100px; }
#status.err { color: #ff6b8a; }
#status.ok { color: #00ff88; }
.cooldown {
  font-variant-numeric: tabular-nums;
  color: #ffd166;
  font-weight: 600;
  min-width: 48px;
  text-align: right;
}

#canvas-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 30% 20%, #00ff8808, transparent 50%),
    radial-gradient(ellipse at 70% 80%, #00e5ff08, transparent 45%),
    #0b0b14;
  min-height: 0;
}
canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 1px solid #2a2a44;
  border-radius: 4px;
  touch-action: none;
  max-width: 100%;
  max-height: 100%;
  cursor: crosshair;
  box-shadow: 0 8px 40px #000a;
}
.coord-hint {
  position: absolute;
  left: 10px; bottom: 10px;
  padding: 4px 8px;
  background: #000c;
  border: 1px solid #333;
  border-radius: 6px;
  font-size: 11px;
  font-family: ui-monospace, monospace;
  color: #9ef;
  pointer-events: none;
}
.coord-hint.hidden { display: none; }

#toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: #10101c;
  border-top: 1px solid #00ff8822;
}
.palette { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 140px; }
.swatch {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.swatch.active {
  border-color: #fff;
  box-shadow: 0 0 10px #00ff88aa;
  transform: scale(1.08);
}
#color-input {
  width: 36px; height: 30px;
  border: none; background: none; padding: 0;
  cursor: pointer;
}
.btn {
  background: #162a2a;
  color: #7ff;
  border: 1px solid #00e5ff44;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.btn:active { opacity: 0.85; transform: scale(0.98); }
.btn-icon {
  background: transparent;
  border: none;
  color: #aaa;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}

.modal {
  position: fixed; inset: 0;
  background: #000a;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 12px;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(480px, 100%);
  max-height: min(70vh, 560px);
  background: #141428;
  border: 1px solid #00ff8844;
  border-radius: 16px 16px 12px 12px;
  box-shadow: 0 12px 48px #000c;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #222244;
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-tabs {
  display: flex; gap: 6px;
  padding: 10px 12px 0;
}
.tab {
  flex: 1;
  background: #1a1a30;
  border: 1px solid #333;
  color: #ccc;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
}
.tab.active {
  border-color: #00ff88;
  color: #00ff88;
  background: #0a2a1a;
}
.modal-body {
  padding: 12px 14px;
  overflow: auto;
  font-size: 14px;
  line-height: 1.45;
  flex: 1;
}
.lb-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #1e1e32;
}
.lb-rank { width: 28px; color: #ffd166; font-weight: 700; }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-px { color: #00ff88; font-variant-numeric: tabular-nums; }
.recent-feed {
  border-top: 1px solid #222244;
  padding: 8px 14px 12px;
  font-size: 12px;
  color: #9a9ab0;
  max-height: 100px;
  overflow: auto;
}
.recent-item { display: flex; gap: 8px; align-items: center; margin: 3px 0; }
.dot {
  width: 10px; height: 10px; border-radius: 2px;
  border: 1px solid #333;
  flex-shrink: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: #1a1a30ee;
  border: 1px solid #00ff8866;
  color: #e8e8f0;
  padding: 10px 16px;
  border-radius: 12px;
  z-index: 60;
  font-size: 13px;
  max-width: 90vw;
  box-shadow: 0 8px 24px #0008;
}
.toast.hidden { display: none; }
.toast.err { border-color: #ff6b8a; }

.demo-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  background: #ffd16633;
  color: #ffd166;
  vertical-align: middle;
}

.reg-card .modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.reg-card p { margin: 0; color: #c8c8d8; line-height: 1.45; }
.reg-btn {
  display: block;
  text-align: center;
  text-decoration: none;
  background: linear-gradient(135deg, #00ff88, #00e5ff);
  color: #06140e !important;
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 700;
  margin-top: 4px;
}
.btn-later {
  width: 100%;
  background: #1a1a30;
  color: #aaa;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
}
