:root {
  --bg: #070708;
  --fg: #f4f4f5;
  --muted: #71717a;
  --lived: #2a2a2e;
  --gold: #eab308;
  --bonus: #22c55e;

  --surface: rgba(14, 14, 17, 0.82);
  --surface-strong: rgba(18, 18, 22, 0.94);
  --surface-hover: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);

  --gold-soft: rgba(234, 179, 8, 0.14);
  --gold-border: rgba(234, 179, 8, 0.42);
  --gold-glow: rgba(234, 179, 8, 0.22);

  --bonus-soft: rgba(34, 197, 94, 0.14);
  --bonus-border: rgba(34, 197, 94, 0.46);
  --bonus-glow: rgba(34, 197, 94, 0.22);

  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --danger-border: rgba(239, 68, 68, 0.4);

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto,
    sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --shadow-dock: 0 14px 40px rgba(0, 0, 0, 0.62), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --shadow-tooltip: 0 10px 28px rgba(0, 0, 0, 0.68);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color-scheme: dark;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- App Shell ---------- */

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(60% 34% at 12% 0%, rgba(234, 179, 8, 0.055), transparent 72%),
    radial-gradient(50% 30% at 88% 0%, rgba(255, 255, 255, 0.03), transparent 70%),
    var(--bg);
}

/* ---------- Hero Header ---------- */

.hero-header {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  padding: clamp(0.95rem, 2.2vh, 1.55rem) clamp(1rem, 2.8vw, 2.25rem)
    clamp(0.85rem, 1.9vh, 1.35rem);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(14, 14, 17, 0.72) 0%, rgba(7, 7, 8, 0.45) 100%);
  position: relative;
  z-index: 5;
}

.hero-brand {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}

.hero-title {
  margin: 0;
  font-size: clamp(1.9rem, 3.8vw, 3.3rem);
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: 0.96;
  background: linear-gradient(108deg, #ffffff 0%, #f4f4f5 52%, #f4d26a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-wrap: balance;
}

.hero-subtitle {
  margin: 0;
  font-size: clamp(0.88rem, 1.25vw, 1.04rem);
  font-weight: 450;
  letter-spacing: 0.005em;
  color: #a1a1aa;
  line-height: 1.25;
}

/* ---------- Live Readout ---------- */

.hero-readout {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  text-align: right;
  flex-shrink: 0;
}

.readout-primary {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.48rem 0.62rem;
}

.readout-number {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.7rem, 3.3vw, 2.85rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 0.95;
  color: var(--gold);
  text-shadow: 0 0 28px var(--gold-glow);
  transition: color 180ms ease, text-shadow 180ms ease;
}

.readout-total {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(1rem, 1.7vw, 1.45rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--muted);
}

.readout-total[hidden] {
  display: none;
}

.readout-unit {
  font-size: clamp(0.85rem, 1.15vw, 1rem);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: #d4d4d8;
}

.readout-bonus {
  display: inline-flex;
  align-items: center;
  padding: 0.24rem 0.68rem;
  border-radius: 999px;
  background: var(--bonus-soft);
  border: 1px solid var(--bonus-border);
  color: var(--bonus);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(0.8rem, 1.1vw, 0.94rem);
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.2;
  box-shadow: 0 0 22px var(--bonus-glow);
  align-self: center;
}

.readout-bonus[hidden] {
  display: none;
}

.hero-readout.is-bonus .readout-number {
  color: #a1a1aa;
  text-shadow: none;
}

.hero-readout.is-bonus .readout-unit {
  color: var(--muted);
}

.readout-meta {
  margin: 0;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
  letter-spacing: 0.01em;
  color: var(--muted);
  line-height: 1.3;
}

/* ---------- Full-Viewport Canvas Stage ---------- */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

.life-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.life-canvas.is-dragging {
  cursor: grabbing;
}

/* ---------- Synchronized Decade Column Labels ---------- */

.decade-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 2;
}

.decade-label {
  position: absolute;
  top: 0;
  left: 0;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  line-height: 1;
  color: var(--muted);
  white-space: nowrap;
  user-select: none;
  will-change: transform;
}

/* ---------- Hover Cell Tooltip ---------- */

.cell-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 20;
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 0.44rem 0.72rem;
  border-radius: 9px;
  background: var(--surface-strong);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-tooltip);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  line-height: 1.3;
  color: var(--fg);
  overflow-wrap: anywhere;
  will-change: transform;
}

.cell-tooltip[hidden] {
  display: none;
}

.tooltip-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--muted);
}

.cell-tooltip.is-lived {
  border-color: rgba(255, 255, 255, 0.14);
}

.cell-tooltip.is-lived .tooltip-dot {
  background: #52525b;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.cell-tooltip.is-remaining {
  border-color: var(--gold-border);
}

.cell-tooltip.is-remaining .tooltip-dot {
  background: var(--gold);
  box-shadow: 0 0 10px var(--gold-glow);
}

.cell-tooltip.is-bonus {
  border-color: var(--bonus-border);
}

.cell-tooltip.is-bonus .tooltip-dot {
  background: var(--bonus);
  box-shadow: 0 0 10px var(--bonus-glow);
}

/* ---------- Graceful Error Banner ---------- */

.error-banner {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  max-width: min(92vw, 560px);
  padding: 0.62rem 0.95rem;
  border-radius: 12px;
  background: rgba(22, 12, 13, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--danger-border);
  color: #fecaca;
  font-size: 0.84rem;
  line-height: 1.35;
  box-shadow: var(--shadow-tooltip);
}

.error-banner[hidden] {
  display: none;
}

.error-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--danger);
}

/* ---------- Bottom Stage HUD (Legend · Floating Dock · Zoom) ---------- */

.stage-bottom-bar {
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 0.75rem;
  pointer-events: none;
}

/* Ultra-minimal legend & interaction hint */

.stage-legend {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.36rem 0.65rem;
  border-radius: 999px;
  background: rgba(7, 7, 8, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
}

.legend-swatch {
  width: 7px;
  height: 7px;
  border-radius: 2px;
  display: inline-block;
}

.swatch-lived {
  background: var(--lived);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.swatch-remaining {
  background: var(--gold);
}

.swatch-bonus {
  background: var(--bonus);
}

.legend-sep {
  opacity: 0.45;
}

.legend-hint {
  opacity: 0.8;
}

/* ---------- Floating Bottom Pill Dock ---------- */

.control-dock {
  justify-self: center;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.42rem 0.52rem 0.42rem 0.85rem;
  border-radius: 999px;
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-dock);
  max-width: 100%;
}

.dock-field {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  min-width: 0;
}

.dock-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  user-select: none;
}

.dock-control {
  appearance: none;
  -webkit-appearance: none;
  height: 2rem;
  padding: 0 0.55rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--fg);
  font-size: 0.82rem;
  font-weight: 500;
  outline: none;
  transition: background-color 140ms ease, border-color 140ms ease;
}

.dock-control:hover {
  background: var(--surface-hover);
  border-color: rgba(255, 255, 255, 0.08);
}

.dock-control:focus-visible {
  border-color: var(--gold-border);
  background: rgba(255, 255, 255, 0.08);
}

.dock-date {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  padding: 0 0.62rem;
  cursor: pointer;
}

.dock-date::-webkit-calendar-picker-indicator {
  filter: invert(0.84);
  opacity: 0.72;
  cursor: pointer;
}

.dock-date::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}

.dock-select {
  max-width: 14.5rem;
  padding-right: 1.75rem;
  text-overflow: ellipsis;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%23a1a1aa' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
}

.dock-select option {
  background: #111114;
  color: var(--fg);
}

.dock-divider {
  width: 1px;
  height: 1.25rem;
  background: var(--border);
  flex-shrink: 0;
}

/* Segmented Day / Hour / Min Control */

.unit-segmented {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.unit-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: #a1a1aa;
  height: 1.75rem;
  padding: 0 0.72rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}

.unit-btn:hover {
  color: var(--fg);
}

.unit-btn:focus-visible {
  outline: none;
  border-color: var(--gold-border);
}

.unit-btn.is-active,
.unit-btn[aria-pressed="true"] {
  background: var(--gold-soft);
  border-color: var(--gold-border);
  color: var(--gold);
}

/* ---------- Compact Zoom Controls ---------- */

.zoom-controls {
  justify-self: end;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 0.3rem 0.35rem;
  border-radius: 999px;
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-dock);
}

.zoom-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: #d4d4d8;
  min-width: 1.85rem;
  height: 1.85rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}

.zoom-btn:hover {
  background: var(--surface-hover);
  color: #ffffff;
}

.zoom-btn:active {
  background: rgba(255, 255, 255, 0.12);
}

.zoom-btn:focus-visible {
  outline: none;
  border-color: var(--gold-border);
}

.zoom-btn-fit {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0 0.62rem;
  color: #a1a1aa;
}

.zoom-level {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  min-width: 3.1rem;
  text-align: center;
  user-select: none;
}

.zoom-divider {
  width: 1px;
  height: 1.05rem;
  background: var(--border);
  margin: 0 0.15rem;
}

/* ---------- Responsive Breakpoints ---------- */

@media (max-width: 1180px) {
  .legend-sep,
  .legend-hint {
    display: none;
  }
}

@media (max-width: 980px) {
  .stage-legend {
    display: none;
  }

  .stage-bottom-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
  }

  .dock-select {
    max-width: 11.5rem;
  }
}

@media (max-width: 720px) {
  .hero-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.85rem 1rem 0.75rem;
  }

  .hero-readout {
    align-items: flex-start;
    text-align: left;
    width: 100%;
  }

  .readout-primary {
    justify-content: flex-start;
  }

  .stage-bottom-bar {
    left: 0.65rem;
    right: 0.65rem;
    bottom: max(0.65rem, env(safe-area-inset-bottom));
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .zoom-controls {
    align-self: flex-end;
    order: 1;
  }

  .control-dock {
    order: 2;
    width: 100%;
    border-radius: 18px;
    padding: 0.55rem 0.65rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.45rem;
  }

  .dock-divider {
    display: none;
  }

  .dock-field {
    width: 100%;
  }

  .dock-label {
    display: none;
  }

  .dock-control {
    width: 100%;
    max-width: none;
    border-radius: 10px;
  }

  .unit-segmented {
    grid-column: 1 / -1;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border-radius: 11px;
  }

  .unit-btn {
    width: 100%;
    border-radius: 9px;
  }

  .cell-tooltip {
    white-space: normal;
    max-width: calc(100vw - 1.5rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
