@font-face {
  font-family: 'Press Start 2P';
  src: url('../assets/PressStart2P.ttf') format('truetype');
}

:root {
  --panel: rgba(12, 12, 34, 0.86);
  --panel-solid: #0c0c22;
  --edge: #4466aa;
  --edge-soft: #2c3c66;
  --ink: #c9d4ee;
  --ink-dim: #6c7aa6;
  --gold: #ffdd66;
  --gold-deep: #221100;
  --hover: #1c2650;
  --tool: 40px;
  --icon: 24px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: linear-gradient(180deg, #0d0a1f 0%, #1a0d2e 40%, #0a1a2a 70%, #060d18 100%);
  min-height: 100vh;
  overflow: hidden;
  font-family: 'Press Start 2P', monospace;
  color: var(--ink);
  image-rendering: pixelated;
  -webkit-tap-highlight-color: transparent;
}

#canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: block;
  z-index: 1;
}

/* Visually hidden, still in the DOM for the state schema and keyboard focus */
.vh {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  opacity: 0;
}

/* ── Pixel frame: notched corners, 2px edge ── */
.frame {
  background: var(--panel);
  border: 2px solid var(--edge);
  clip-path: polygon(4px 0, calc(100% - 4px) 0, 100% 4px, 100% calc(100% - 4px),
                     calc(100% - 4px) 100%, 4px 100%, 0 calc(100% - 4px), 0 4px);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.35);
}

[data-icon] {
  display: inline-block;
  width: var(--icon);
  height: var(--icon);
  line-height: 0;
}
[data-icon] svg { width: 100%; height: 100%; display: block; }

/* ── Title card ── */
#title-card {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: tc-in 1.2s ease-out both;
  transition: opacity 0.9s ease-in;
}
#title-card[hidden] { display: none; }

#fade {
  position: fixed;
  inset: 0;
  z-index: 39;
  background: #060d18;
  pointer-events: none;
  transition: opacity 1.4s ease-out;
}
#fade.gone { opacity: 0; }
#title-card.gone { opacity: 0; }

.tc-title {
  font-size: clamp(22px, 6vw, 56px);
  color: var(--gold);
  letter-spacing: 0.08em;
  text-shadow: 4px 4px 0 var(--gold-deep), 0 0 24px rgba(255, 200, 90, 0.25);
}

@keyframes tc-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── Day/night dial ── */
#dial {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 10;
  width: 76px;
  height: 42px;
  overflow: hidden;
  border-bottom-width: 4px;
  pointer-events: none;
  transition: opacity 0.6s;
}
#dial-wheel {
  position: absolute;
  left: 50%;
  top: 36px;
  width: 60px;
  height: 60px;
  margin: -30px 0 0 -30px;
  will-change: transform;
}
#dial-wheel [data-icon] {
  position: absolute;
  left: 50%;
  width: 20px;
  height: 20px;
  margin-left: -10px;
}
.dial-sun  { top: 0;    color: var(--gold); }
.dial-moon { bottom: 0; color: #dfe6ff; transform: rotate(180deg); }

/* ── HUD ── */
#hud {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100vw - 24px);
  transition: opacity 0.6s;
}

#dock {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
#dock::-webkit-scrollbar { display: none; }

.sep {
  flex: none;
  width: 2px;
  height: 24px;
  margin: 0 6px;
  background: var(--edge-soft);
}

.tool {
  flex: none;
  width: var(--tool);
  height: var(--tool);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  color: var(--ink-dim);
  cursor: pointer;
  font: inherit;
  transition: color 0.15s, background-color 0.15s, transform 0.1s;
}
.tool:hover { color: var(--ink); background: var(--hover); }
.tool:active { transform: translateY(1px); }
.tool:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }

/* On: lit gold. Buttons (pause, cycles, popover) count as on. */
button.tool { color: var(--ink); }
.tool:has(> input:checked) { color: var(--gold); }
.tool:has(> input:disabled) { opacity: 0.3; cursor: default; }
.tool.open { color: var(--gold); background: var(--hover); }

/* Day-of-year track */
.season {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px;
  color: var(--ink-dim);
}
.season [data-icon] { width: 16px; height: 16px; }
.season [data-icon]:first-child { color: var(--gold); }
.season [data-icon]:last-child  { color: #bfe3ff; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 96px;
  height: 20px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: var(--edge-soft);
  border: 2px solid #1a2244;
}
input[type="range"]::-moz-range-track {
  height: 6px;
  background: var(--edge-soft);
  border: 2px solid #1a2244;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 16px;
  margin-top: -7px;
  background: var(--gold);
  border: 2px solid var(--gold-deep);
  border-radius: 0;
}
input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 16px;
  background: var(--gold);
  border: 2px solid var(--gold-deep);
  border-radius: 0;
}

/* ── Popovers ── */
.pop {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: pop-in 0.14s ease-out;
}
.pop[hidden] { display: none; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.pop .grid {
  display: grid;
  grid-template-columns: repeat(4, var(--tool));
  gap: 2px;
}
.pop .grid + .grid {
  padding-top: 4px;
  border-top: 2px solid var(--edge-soft);
}
.pop .row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-top: 4px;
  border-top: 2px solid var(--edge-soft);
}
.pop .row .dim { width: 16px; height: 16px; margin-left: 8px; color: var(--ink-dim); }
.pop .row input[type="range"] { flex: 1; width: 72px; }

#pop-alm .grid { grid-template-columns: repeat(5, var(--tool)); }
.preset-btn[data-tone="blood"] { color: #ff7a5c; }

/* Info card */
.info { width: 248px; padding: 12px; gap: 10px; }
.info-title {
  font-size: 10px;
  color: var(--gold);
  text-shadow: 2px 2px 0 var(--gold-deep);
}
.info p {
  font-size: 8px;
  line-height: 1.9;
  color: var(--ink);
}
.info .row { justify-content: space-between; padding-top: 8px; }
.info-link {
  font-size: 8px;
  color: #8fd0ff;
  text-decoration: none;
}
.info-link:hover { color: var(--gold); text-decoration: underline; }

/* ── Hover label ── */
#tip {
  position: fixed;
  z-index: 60;
  padding: 6px 8px;
  font-size: 8px;
  color: var(--ink);
  background: var(--panel-solid);
  border: 2px solid var(--edge);
  white-space: nowrap;
  pointer-events: none;
}
#tip[hidden] { display: none; }

/* ── Idle and hidden HUD ── */
body.idle #hud:not(:hover):not(:focus-within) { opacity: 0.22; }
body.idle #dial { opacity: 0.5; }
body.hud-off #hud,
body.hud-off #dial,
body.hud-off #tip { opacity: 0 !important; pointer-events: none; }

/* ── Photo mode ── */
#photo-bar {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 50;
  display: none;
  gap: 2px;
  padding: 4px;
}
.photo-mode #photo-bar { display: flex; }
.photo-mode #hud,
.photo-mode #dial,
.photo-mode #tip,
.photo-mode #title-card { display: none; }

/* ── Small screens and touch ── */
@media (max-width: 640px), (pointer: coarse) {
  :root { --tool: 44px; --icon: 24px; }
  #hud { bottom: 10px; width: calc(100vw - 16px); max-width: 420px; }
  #dock { flex-wrap: wrap; justify-content: center; row-gap: 2px; }
  #dock .sep { display: none; }
  .season input[type="range"] { width: 72px; }
  #tip { display: none !important; }
  #dial { top: 10px; left: 10px; }
}
