:root {
  --bg: #0a0a0a;
  --panel: #111;
  --fg: #ffb000;        /* amber */
  --fg-dim: #7a5500;
  --edge: #222;
  --seam: #000;
  --danger: #ff5040;
  --flip-ms: 150ms;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-top:    max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  padding-left:   max(16px, env(safe-area-inset-left));
  padding-right:  max(16px, env(safe-area-inset-right));
}

#app { min-height: 100%; display: flex; align-items: center; justify-content: center; }

.view { width: 100%; max-width: 460px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.hidden { display: none !important; }

.logo { font-size: 2rem; letter-spacing: .18em; margin: 0 0 8px; color: var(--fg); }

/* ---- forms ---- */
form { width: 100%; display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
input, select {
  background: var(--panel); color: var(--fg);
  border: 1px solid var(--edge); border-radius: 4px;
  padding: 12px 14px; font: inherit; width: 100%;
}
input::placeholder { color: var(--fg-dim); }
input:focus, select:focus { outline: none; border-color: var(--fg); }

button {
  background: transparent; color: var(--fg);
  border: 1px solid var(--fg); border-radius: 4px;
  padding: 12px 16px; font: inherit; letter-spacing: .1em;
  cursor: pointer; transition: background .15s, color .15s;
}
button:hover:not(:disabled) { background: var(--fg); color: var(--bg); }
button:disabled { opacity: .35; cursor: default; }

.help, .muted { color: var(--fg-dim); font-size: .85rem; text-align: center; line-height: 1.5; }
.help a, .toggle a { color: var(--fg); }
.toggle { font-size: .85rem; color: var(--fg-dim); text-align: center; }
.error { color: var(--danger); font-size: .85rem; min-height: 1.2em; text-align: center; }

/* ---- board view ---- */
#board-view { position: relative; }
.gear {
  position: absolute; top: -6px; right: -6px;
  border: none; font-size: 1.4rem; padding: 6px 10px;
}
.gear:hover { background: transparent; color: #fff; }

.horizon-nav { display: flex; align-items: center; gap: 14px; }
.chev { border: none; font-size: 1.6rem; padding: 2px 10px; line-height: 1; }
.chev:hover:not(:disabled) { background: transparent; color: #fff; }
.horizon-label { letter-spacing: .18em; font-size: .95rem; color: var(--fg); min-width: 9ch; text-align: center; }

/* split-flap board */
.board { display: flex; gap: 4px; justify-content: center; margin: 6px 0; }
.cell {
  position: relative;
  width: .72em; height: 1.15em;
  /* shrink as the number gets more characters so the board always fits */
  font-size: clamp(34px, min(15vw, calc(80vw / var(--n, 3))), 92px);
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 4px;
  perspective: 280px;
  box-shadow: inset 0 0 8px rgba(0,0,0,.7);
}
/* separators (comma, dot, minus) get a slim, frame-less cell */
.cell.sep { width: .34em; background: transparent; border: none; box-shadow: none; }
.cell.sep::after { display: none; }
/* center seam */
.cell::after {
  content: ''; position: absolute; left: 0; right: 0; top: 50%;
  height: 1px; background: var(--seam); z-index: 5; transform: translateY(-.5px);
}
.half { position: absolute; left: 0; width: 100%; height: 50%; overflow: hidden; }
/* The glyph is a full-cell-height box (200% of a half) with the digit centered;
   each half is a window onto it — the top half shows the digit's upper half, the
   bottom half is shifted up by one half-height to reveal its lower half. */
.half .glyph {
  display: flex; align-items: center; justify-content: center;
  height: 200%; width: 100%;
  color: var(--fg); font-weight: 600;
}
.top, .fold-top { top: 0; }
.bottom, .fold-bottom { bottom: 0; }
.bottom .glyph, .fold-bottom .glyph { transform: translateY(-50%); }

/* fold pieces hidden at rest; revealed only while flipping */
.fold-top, .fold-bottom { display: none; z-index: 4; backface-visibility: hidden; }
.fold-top { transform-origin: bottom center; }
.fold-bottom { transform-origin: top center; transform: rotateX(90deg); }

.cell.flipping .fold-top {
  display: block;
  animation: flap-top var(--flip-ms) ease-in forwards;
  animation-delay: var(--d, 0s);
}
.cell.flipping .fold-bottom {
  display: block;
  animation: flap-bottom var(--flip-ms) ease-out forwards;
  animation-delay: calc(var(--d, 0s) + var(--flip-ms));
}
@keyframes flap-top    { from { transform: rotateX(0deg);  } to { transform: rotateX(-90deg); } }
@keyframes flap-bottom { from { transform: rotateX(90deg); } to { transform: rotateX(0deg);   } }

.currency { letter-spacing: .25em; font-size: 1.1rem; color: var(--fg); }

.annunciators { display: flex; gap: 10px; min-height: 1.4em; }
.ann {
  font-size: .7rem; letter-spacing: .15em; padding: 2px 8px;
  border: 1px solid var(--danger); color: var(--danger); border-radius: 3px;
}
#ann-extended { border-color: var(--fg); color: var(--fg); }

.subline { color: var(--fg-dim); font-size: .9rem; letter-spacing: .05em; cursor: pointer; transition: filter .15s; }
.subline.spoiler { filter: blur(7px); }
.subline.spoiler:hover { filter: blur(4px); }
.refresh { margin-top: 8px; min-width: 160px; }

/* ---- drawer ---- */
.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; justify-content: flex-end; z-index: 20; }
.drawer-panel {
  width: min(360px, 90vw); height: 100%; background: var(--bg);
  border-left: 1px solid var(--edge);
  padding: max(24px, env(safe-area-inset-top)) 22px 22px;
  display: flex; flex-direction: column; gap: 14px; overflow-y: auto;
}
.drawer-panel h2 { letter-spacing: .2em; font-size: 1rem; margin: 0 0 6px; }
.drawer .field { font-size: .8rem; color: var(--fg-dim); letter-spacing: .1em; }
.drawer-panel .danger { border-color: var(--danger); color: var(--danger); margin-top: auto; }
.drawer-panel .danger:hover { background: var(--danger); color: var(--bg); }
.drawer-panel .ghost { border-color: var(--edge); color: var(--fg-dim); }
