:root {
  --bg-panel: rgba(252, 250, 245, 0.9);
  --bg-subtle: rgba(235, 231, 222, 0.72);
  --border: rgba(36, 54, 72, 0.14);
  --ink: #1d2b3a;
  --muted: #5a6b7c;
  --accent: #0e7490;
  --accent-soft: rgba(14, 116, 144, 0.14);
  --shadow: 0 8px 28px rgba(15, 32, 48, 0.14);
  --radius: 14px;
}

body.night-ui {
  --bg-panel: rgba(15, 24, 38, 0.88);
  --bg-subtle: rgba(28, 42, 62, 0.75);
  --border: rgba(148, 184, 218, 0.2);
  --ink: #e8f1fa;
  --muted: #93acc4;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.18);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.48);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #79aec2;
  color: var(--ink);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Pretendard", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}
canvas.clickable {
  cursor: pointer;
}
canvas.dragging {
  cursor: grabbing;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.panel {
  position: fixed;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background 0.35s ease, color 0.35s ease, border-color 0.35s ease;
}

/* Loading cover */
.loading-cover {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 42%, rgba(235, 244, 248, 0.96), rgba(164, 200, 214, 0.96));
  transition: opacity 0.55s ease;
}
.loading-cover.fade-out {
  opacity: 0;
  pointer-events: none;
}
.loading-card {
  text-align: center;
  color: #1e2d3b;
}
.loading-icon {
  font-size: 40px;
  margin-bottom: 8px;
}
.loading-card h1 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
}
.loading-card p {
  margin: 0;
  font-size: 13px;
  color: #4f6475;
}

/* Left Panel */
.panel-left {
  top: 14px;
  left: 14px;
  width: 312px;
  max-height: calc(100vh - 90px);
  padding: 14px 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
}

.brand-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.brand-eyebrow {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.scene-title {
  margin: 2px 0 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.scene-sub {
  margin: -4px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}

.live-badge {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--muted);
}
.live-badge.is-live {
  background: rgba(16, 185, 129, 0.18);
  color: #059669;
}
body.night-ui .live-badge.is-live {
  color: #34d399;
}

.meta-strip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 9px;
  border-radius: 9px;
  background: var(--bg-subtle);
  font-size: 11.5px;
}
.weather-pill {
  color: var(--muted);
  font-weight: 600;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.stat-box {
  background: var(--bg-subtle);
  border-radius: 9px;
  padding: 6px 8px;
  text-align: center;
}
.stat-val {
  display: block;
  font-size: 16px;
  font-weight: 800;
}
.stat-val.accent {
  color: var(--accent);
}
.stat-lbl {
  display: block;
  font-size: 10.5px;
  color: var(--muted);
}

.action-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill-btn {
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--ink);
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: transform 0.12s ease, background 0.15s ease;
}
.pill-btn:hover {
  background: var(--accent-soft);
}
.pill-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}
.pill-btn.full-width {
  width: 100%;
  justify-content: center;
}

.count-chip {
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.1);
}

.log-details {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.log-details summary {
  cursor: pointer;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  user-select: none;
}
.log-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  max-height: 195px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.log-item {
  display: flex;
  gap: 7px;
  font-size: 11.5px;
  padding: 5px 7px;
  border-radius: 7px;
  background: var(--bg-subtle);
}
.log-item.clickable {
  cursor: pointer;
}
.log-item.clickable:hover {
  background: var(--accent-soft);
}
.log-time {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 10.5px;
  color: var(--muted);
  flex-shrink: 0;
}
.log-empty {
  color: var(--muted);
  font-size: 11.5px;
  padding: 6px 2px;
}

/* Top-right controls */
.top-right-stack {
  position: fixed;
  top: 14px;
  right: 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 10;
}
.compact-bar {
  position: static;
  padding: 4px;
  display: inline-flex;
  gap: 3px;
  border-radius: 11px;
}
.zoom-bar {
  position: static;
  padding: 4px;
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
  border-radius: 11px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn:hover {
  color: var(--ink);
  background: var(--bg-subtle);
}
.seg-btn.active {
  background: var(--accent);
  color: #ffffff;
}
.icon-btn {
  width: 30px;
  height: 28px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--bg-subtle);
}

/* Selected Vessel Card */
.vessel-card {
  right: 14px;
  bottom: 72px;
  width: 286px;
  padding: 14px;
  z-index: 12;
}
.vc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}
.vc-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.vc-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}
.flag-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
}
.vc-sub {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}
.close-btn {
  border: none;
  background: var(--bg-subtle);
  color: var(--ink);
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.vc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  margin: 0 0 12px;
}
.vc-grid dt {
  font-size: 10.5px;
  color: var(--muted);
}
.vc-grid dd {
  margin: 1px 0 0;
  font-size: 12px;
  font-weight: 600;
}

/* Bottom Time Bar */
.bottom-bar {
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 11;
  max-width: calc(100vw - 24px);
}
.mode-switch {
  display: inline-flex;
  gap: 3px;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: 9px;
}
.replay-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.replay-controls input[type="range"] {
  width: 170px;
  accent-color: var(--accent);
}
.replay-controls select {
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--ink);
  border-radius: 7px;
  padding: 4px 6px;
  font-size: 11.5px;
  font-weight: 600;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(8, 18, 28, 0.45);
  backdrop-filter: blur(4px);
  padding: 16px;
}
.modal-backdrop[hidden] {
  display: none;
}
.modal-card {
  width: min(560px, 100%);
  max-height: 82vh;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.modal-header h2 {
  margin: 0;
  font-size: 17px;
}
.modal-sub {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--muted);
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.collection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 8px;
  overflow-y: auto;
  padding-right: 4px;
}
.collection-item {
  text-align: left;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--ink);
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
}
.collection-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.ci-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.ci-name {
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ci-flag {
  font-size: 10px;
  color: var(--muted);
  font-weight: 700;
}
.ci-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.modal-body {
  overflow-y: auto;
  font-size: 13px;
}
.modal-body h3 {
  margin: 14px 0 6px;
  font-size: 13px;
}
.credit-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.note-box {
  background: var(--bg-subtle);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 12px;
  color: var(--muted);
}
.next-scene {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}
.repo-link {
  color: var(--accent);
  text-decoration: none;
}
.repo-link:hover {
  text-decoration: underline;
}

@media (max-width: 720px) {
  .panel-left {
    width: calc(100vw - 24px);
    left: 12px;
    top: 12px;
    padding: 11px 12px;
  }
  .log-details {
    display: none;
  }
  .top-right-stack {
    top: auto;
    bottom: 72px;
    right: 12px;
  }
  .vessel-card {
    left: 12px;
    right: 12px;
    width: auto;
    bottom: 68px;
  }
  .replay-controls input[type="range"] {
    width: 100px;
  }
}
