:root {
  color-scheme: dark;
  --bg: #12161e;
  --panel: #1c2430;
  --hex-fill: #222c3c;
  --hex-alt: #2d3a4f;
  --hex-selected: #38bdf8;
  --hex-stroke: #60708c;
  --text: #e2e8f0;
  --muted: #94a3b8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #2a3444;
  background: var(--panel);
}

.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-actions {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.user-chip button {
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0f131a;
  color: var(--text);
  padding: 0.4rem 0.75rem;
  font: inherit;
  cursor: pointer;
}

.user-chip button:hover {
  border-color: #38bdf8;
}

/* Security key (WebAuthn) login gate */
.login-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, #1e3a5f 0%, transparent 55%),
    var(--bg);
}

.login-card {
  width: min(440px, 100%);
  border-radius: 16px;
  border: 1px solid #2a3444;
  background: var(--panel);
  padding: 2rem 1.75rem;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}

.login-kicker {
  margin: 0 0 0.75rem;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #38bdf8;
}

.login-title {
  margin: 0 0 1rem;
  font-size: 1.15rem;
  line-height: 1.45;
  font-weight: 600;
  color: var(--text);
}

.login-sub {
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--muted);
}

.login-sub code {
  font-size: 0.8em;
  color: #cbd5e1;
  background: #0f131a;
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.login-status {
  min-height: 1.25rem;
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: #fbbf24;
}

.login-btn {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 0.85rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  color: #0f172a;
  background: linear-gradient(180deg, #7dd3fc 0%, #38bdf8 100%);
}

.login-btn:hover:not(:disabled) {
  filter: brightness(1.06);
}

.login-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.login-btn-secondary {
  margin-top: 0.65rem;
  color: #e2e8f0;
  background: linear-gradient(180deg, #334155 0%, #1e293b 100%);
  border: 1px solid #475569;
}

.login-btn-secondary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0 0 0.85rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.login-field input {
  border: 1px solid #2a3444;
  border-radius: 8px;
  background: #0f131a;
  color: var(--text);
  padding: 0.65rem 0.75rem;
  font: inherit;
}

.login-field input:focus {
  outline: 1px solid #38bdf8;
  border-color: #38bdf8;
}

.login-actions {
  display: flex;
  flex-direction: column;
}

.login-footnote {
  margin: 1rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

[hidden] {
  display: none !important;
}

h1 {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
}

#status {
  margin: 0;
  color: var(--muted);
}

.api-key-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
  min-width: 200px;
}

.api-key-field input {
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0f131a;
  color: var(--text);
  padding: 0.5rem 0.65rem;
  font: inherit;
  min-width: 220px;
}

.workspace {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  min-height: calc(100vh - 96px);
}

#properties-panel,
#level-panel {
  width: 260px;
  flex-shrink: 0;
}

.properties-card {
  height: calc(100vh - 128px);
  min-height: 520px;
  border-radius: 12px;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid #2a3444;
  display: flex;
  flex-direction: column;
}

.properties-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #dbeafe;
}

.selection-summary {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.properties-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1;
}

.properties-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.properties-form input {
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0f131a;
  color: var(--text);
  padding: 0.55rem 0.65rem;
  font: inherit;
}

.properties-form input:disabled {
  opacity: 0.55;
}

.properties-form input[readonly] {
  background: #1a2230;
  color: #94a3b8;
}

.properties-form input.mixed {
  color: #64748b;
  border-style: dashed;
  font-style: italic;
}

#save-properties {
  margin-top: auto;
  border-radius: 10px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.12);
  color: #dbeafe;
  padding: 0.7rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

#save-properties:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Maps selector — simple panel matching Properties */
.jukebox-cabinet {
  height: calc(100vh - 128px);
  min-height: 520px;
  border-radius: 12px;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid #2a3444;
  display: flex;
  flex-direction: column;
}

.jukebox-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  letter-spacing: 0.08em;
  font-weight: 700;
  text-transform: uppercase;
  color: #dbeafe;
  text-align: left;
}

.jukebox-window {
  position: relative;
  flex: 1 1 auto;
  min-height: 280px;
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: none;
  border-radius: 8px;
  background: #0f131a;
  border: 1px solid #334155;
}

/* Center selection bar */
.jukebox-highlight {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 50%;
  height: 44px;
  transform: translateY(-50%);
  border-radius: 8px;
  border: 1px solid rgba(56, 189, 248, 0.4);
  background: rgba(56, 189, 248, 0.1);
  pointer-events: none;
  z-index: 2;
}

/* Fixed origin at center; slots stack around the selection */
.jukebox-drum {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 0;
  transform: translateY(-50%);
  pointer-events: none;
}

.level-slot {
  position: absolute;
  left: 12px;
  right: 12px;
  width: auto;
  height: 40px;
  margin: 0;
  margin-top: -20px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  transition:
    top 200ms ease,
    opacity 160ms ease,
    color 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

.level-slot:hover {
  color: var(--text);
  background: rgba(148, 163, 184, 0.08);
}

.level-slot span {
  position: relative;
  z-index: 1;
}

.level-slot.active {
  color: #e0f2fe;
  background: transparent;
  border-color: transparent;
  font-weight: 700;
}

.level-slot.dim {
  opacity: 0.5;
}

.jukebox-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.jukebox-footer button {
  width: 40px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0f131a;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
}

.jukebox-footer button:hover {
  color: var(--text);
  border-color: rgba(56, 189, 248, 0.45);
}

#level-up {
  justify-self: start;
}

#level-down {
  justify-self: end;
}

#level-readout {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}

.grid-view {
  flex: 1;
  min-width: 0;
}

#grid-container {
  overflow: auto;
  height: calc(100vh - 128px);
  min-height: 520px;
  border: 1px solid #2a3444;
  border-radius: 8px;
  background: #0f131a;
}

svg {
  display: block;
}

.hexagon {
  fill: var(--hex-fill);
  stroke: var(--hex-stroke);
  stroke-width: 1.2;
  cursor: pointer;
  transition: fill 120ms ease;
}

.hexagon.alt {
  fill: var(--hex-alt);
}

.hexagon.selected {
  fill: var(--hex-selected);
}

.hexagon:hover {
  filter: brightness(1.15);
}

@media (max-width: 1100px) {
  .workspace {
    flex-direction: column;
  }

  #properties-panel,
  #level-panel {
    width: 100%;
  }

  .properties-card,
  .jukebox-cabinet,
  #grid-container {
    height: auto;
    min-height: 320px;
  }
}