:root {
  --bg: #050607;
  --bg-secondary: #13181f;
  --card: rgba(14, 18, 23, 0.84);
  --border: rgba(107, 114, 128, 0.38);
  --text: #f8fafc;
  --muted: #cbd5e1;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.24);
  --accent-ring: rgba(56, 189, 248, 0.95);
  --glow-primary: rgba(56, 189, 248, 0.2);
  --glow-secondary: rgba(14, 116, 144, 0.16);
  --status-connected-bg: rgba(56, 189, 248, 0.24);
  --status-connected-text: #e2f3ff;
  --status-disconnected-bg: rgba(239, 68, 68, 0.22);
  --status-disconnected-text: #fecaca;
  --mono: 'Iosevka', 'JetBrains Mono', 'Fira Code', monospace;
  --sans: 'Manrope', 'Avenir Next', 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100svh;
  color: var(--text);
  font-family: var(--sans);
  background:
    radial-gradient(1000px 480px at 20% 0%, var(--glow-primary), transparent),
    radial-gradient(900px 420px at 90% 10%, var(--glow-secondary), transparent),
    linear-gradient(140deg, var(--bg), var(--bg-secondary));
}

#app {
  height: 100%;
}

.layout {
  position: relative;
  height: 100%;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-bottom: 0;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.2rem 0.2rem 0.45rem;
}

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2rem);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.card {
  border: 1px solid var(--border);
  background: var(--card);
  backdrop-filter: blur(8px);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 20px 38px rgba(2, 6, 23, 0.5);
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  margin-bottom: 120px;
}

.turn-tracker {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  border: 1px solid var(--border);
  border-bottom: none;
  background: var(--card);
  border-radius: 14px 14px 0 0;
  padding: 0.6rem 0.7rem;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.turn-tracker-content {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.turn-tracker-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-width: 0;
}

.turn-tracker-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.turn-tracker-head strong {
  color: var(--text);
}

.turn-tracker-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.turn-control {
  padding: 0;
  border-radius: 8px;
  font-size: 1rem;
  line-height: 1;
  width: 2.5rem;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.turn-tracker-strip {
  min-height: 88px;
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 0.5rem;
}

.turn-tracker-strip.is-spinning {
  animation: none;
}

.turn-card {
  width: min(170px, 22vw);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 0.55rem;
  padding: 0.42rem;
  align-items: center;
  min-width: 0;
}

.turn-card.is-current-turn {
  border-color: var(--accent-ring);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.turn-portrait {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: linear-gradient(150deg, var(--bg), var(--bg-secondary));
  background-size: cover;
  background-position: center;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-weight: 800;
  font-size: 0.88rem;
}

.turn-labels {
  min-width: 0;
  display: grid;
  gap: 0.1rem;
}

.turn-labels strong {
  font-size: 0.84rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.turn-labels span {
  font-size: 0.74rem;
  color: var(--muted);
}

@keyframes turnSpin {
  0% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }

  45% {
    transform: translateX(-18px) scale(0.98);
    opacity: 0.85;
  }

  100% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
}

#arena-canvas {
  width: 100%;
  height: 100%;
  display: block;
  border: 1px solid var(--border);
  border-radius: 16px;
}

label {
  font-size: 0.88rem;
  color: var(--muted);
}

input,
button {
  font: inherit;
}

input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(7, 16, 39, 0.74);
  color: var(--text);
  padding: 0.65rem 0.75rem;
}

button {
  border: none;
  border-radius: 10px;
  padding: 0.65rem 0.95rem;
  background: var(--accent);
  color: #0c0f14;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.row {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
}

.status {
  font-weight: 700;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.85rem;
}

.status.connected {
  background: var(--status-connected-bg);
  color: var(--status-connected-text);
}

.status.disconnected {
  background: var(--status-disconnected-bg);
  color: var(--status-disconnected-text);
}

/* console/log styles removed */

.auth-modal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(1, 4, 12, 0.72);
  backdrop-filter: blur(4px);
  z-index: 3;
}

.auth-modal.hidden {
  display: none;
}

.auth-card {
  width: min(540px, calc(100% - 2rem));
  display: grid;
  gap: 0.6rem;
}

h2 {
  margin: 0;
  font-size: 1.35rem;
}

.auth-card p {
  margin: 0;
  color: var(--muted);
}

.auth-message {
  min-height: 1.4rem;
}

.sheet-modal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(1, 4, 12, 0.58);
  backdrop-filter: blur(2px);
  z-index: 2;
}

.sheet-modal.hidden {
  display: none;
}

.sheet-card {
  width: min(620px, calc(100% - 2rem));
  max-height: calc(100% - 2rem);
  overflow: auto;
  display: grid;
  gap: 0.8rem;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.sheet-close {
  padding: 0.45rem 0.75rem;
}

.sheet-body {
  display: grid;
  gap: 0.7rem;
}

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.sheet-metric {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: rgba(7, 16, 39, 0.62);
  display: grid;
  gap: 0.15rem;
}

.sheet-path {
  grid-column: 1 / -1;
}

.sheet-label {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sheet-body h3 {
  margin: 0;
  font-size: 1rem;
}

.sheet-body pre {
  margin: 0;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  max-height: 240px;
  overflow: auto;
  background: rgba(7, 16, 39, 0.74);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
}

@media (max-width: 720px) {
  .row {
    flex-wrap: wrap;
  }

  .layout {
    padding: 0.6rem;
  }

  .turn-tracker-head {
    align-items: center;
    flex-direction: row;
  }

  .turn-control {
    width: 2rem;
    font-size: 0.9rem;
  }

  .turn-card {
    width: min(148px, 32vw);
  }

  .sheet-grid {
    grid-template-columns: 1fr;
  }

}
