:root {
  --panel-bg: #161616;
  --cell-bg: #1d1d1d;
  --cell-bg-bottom: #121212;
  --text: #f0ede0;
  --shadow: rgba(0,0,0,.8);
  --radius: 6px;
  --cellH: 68px;
  --gap: 4px;

  --halfShift: calc(var(--cellH) / 4);
  --glyphNudge: 0px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: #0a0a0a;
  color: #e0e0e0;
}

/* ─── Layout ──────────────────────────────────────────── */

.wrap {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Left control panel */
.panel {
  width: 290px;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--panel-bg);
  border-right: 1px solid rgba(255,255,255,.08);
  padding: 18px 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.12) transparent;
}

/* Right display area — dark room effect */
.display-frame {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background:
    radial-gradient(ellipse 100% 80% at 50% 50%, #161616 0%, #070707 100%);
  overflow: hidden;
  position: relative;
}

/* Vignette overlay */
.display-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 85% 70% at 50% 50%,
    transparent 50%, rgba(0,0,0,.55) 100%);
  pointer-events: none;
  z-index: 0;
}

/* ─── The board ───────────────────────────────────────── */

.grid {
  display: grid;
  gap: var(--gap);
  row-gap: 6px;
  width: fit-content;
  padding: 20px 18px;
  background: #0b0b0b;
  border-radius: 12px;
  border: 2px solid #252525;
  box-shadow:
    2px 6px 16px rgba(0,0,0,.03),
    inset 0 1px 0 rgba(255,255,255,.04);
  position: relative;
  z-index: 1;
}

/* ─── Flap cells ──────────────────────────────────────── */

.cell {
  height: var(--cellH);
  min-width: 0;
  border-radius: var(--radius);
  /*
   * Seam is baked into the cell background as a sharp dark valley at 50%.
   * The halves are transparent, so the cell bg shows through everywhere.
   * Glyph text renders on top, covering the seam where letter strokes exist.
   */
  background: linear-gradient(
    180deg,
    #303030 0%,
    #242424 40%,
    #0e0e0e 48%,
    #020202 50%,
    #0e0e0e 52%,
    #1c1c1c 60%,
    #111111 100%
  );
  border: 1px solid rgba(255,255,255,.07);
  position: relative;
  overflow: hidden;
  user-select: none;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.09),
    inset 0 -1px 0 rgba(0,0,0,.4),
    0 4px 10px rgba(0,0,0,.6);
  transform: translateZ(0);
}

.glyph {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;

  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-weight: 900;
  font-size: calc(var(--cellH) * 0.54);
  letter-spacing: 0;
  color: var(--text);
  text-shadow:
    0 0 12px rgba(255,240,200,.18),
    0 1px 3px rgba(0,0,0,.8);
  backface-visibility: hidden;
  line-height: 1;
}

.topHalf, .bottomHalf {
  position: absolute;
  left: 0; right: 0;
  overflow: hidden;
}

/* Transparent so the cell background (incl. seam) shows through */
.topHalf  { top: 0;    height: 50%; background: transparent; }
.bottomHalf { bottom: 0; height: 50%; background: transparent; }

/* Seam line — thin dark stripe at the midpoint, always visible */
.cell::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: 1px;
  background: rgba(0,0,0,.65);
  pointer-events: none;
  z-index: 2;
}

/* shift each half so both halves form one full letter */
.topHalf .glyph {
  transform: translateY(calc(var(--halfShift) + var(--glyphNudge)));
}
.bottomHalf .glyph {
  transform: translateY(calc(-1 * var(--halfShift) + var(--glyphNudge)));
}

/* ─── Flip animation ──────────────────────────────────── */

.cell.flipping .topHalf {
  animation: flipTop var(--flipDur) ease-in forwards;
  transform-origin: 50% 100%;
}
.cell.flipping .bottomHalf {
  animation: flipBottom var(--flipDur) ease-out forwards;
  transform-origin: 50% 0%;
}

@keyframes flipTop {
  0%   { transform: rotateX(0deg);   filter: brightness(1); }
  100% { transform: rotateX(-90deg); filter: brightness(.5); }
}
@keyframes flipBottom {
  0%   { transform: rotateX(90deg);  filter: brightness(.5); }
  100% { transform: rotateX(0deg);   filter: brightness(1); }
}

/* ─── Panel controls ──────────────────────────────────── */

h1 {
  margin: 0 0 14px 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .2px;
  color: #fff;
}

label {
  display: block;
  font-size: 12px;
  color: #999;
  margin: 10px 0 5px;
}

textarea {
  width: 100%;
  min-height: 100px;
  background: #0d0d0d;
  color: #f0f0f0;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 9px;
  padding: 9px 10px;
  resize: vertical;
  outline: none;
  font-size: 13px;
  font-family: ui-monospace, monospace;
}

textarea:focus { border-color: rgba(255,255,255,.24); }

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

input[type="number"], select {
  width: 100%;
  background: #0d0d0d;
  color: #f0f0f0;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 9px;
  padding: 8px 10px;
  outline: none;
  font-size: 13px;
}

input[type="range"] {
  width: 100%;
  accent-color: #d9d9d9;
  margin-top: 4px;
}

.slider-val {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: #888;
  margin-left: 4px;
  font-weight: 400;
}

.volreadout {
  margin-top: 4px;
  font-size: 11px;
  color: #777;
}

/* ─── Personalisatie ──────────────────────────────────── */

.personalize {
  display: flex;
  gap: 18px;
  margin-top: 12px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.pers-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.pers-label {
  font-size: 12px;
  color: #999;
}

.swatches {
  display: flex;
  gap: 6px;
  align-items: center;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  transition: transform .1s, border-color .15s;
  flex-shrink: 0;
}
.swatch:hover { transform: scale(1.2); }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 1px rgba(255,255,255,.3); }

/* Color picker styled as swatch */
input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.2);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  background: transparent;
  flex-shrink: 0;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }
input[type="color"]::-moz-color-swatch  { border: none; border-radius: 50%; }
input[type="color"]:hover { border-color: rgba(255,255,255,.5); }

.size-btns {
  display: flex;
  gap: 4px;
}

.size-btn {
  width: 32px;
  height: 26px;
  padding: 0;
  font-size: 12px;
  font-weight: 700;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.size-btn.active {
  background: rgba(255,255,255,.16);
  border-color: rgba(255,255,255,.28);
}

/* ─────────────────────────────────────────────────────── */

.btns {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

button {
  appearance: none;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06);
  color: #fff;
  padding: 9px 13px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: background .15s, border-color .15s;
}

button:hover {
  background: rgba(255,255,255,.11);
  border-color: rgba(255,255,255,.22);
}

button:active { transform: translateY(1px); }

.hint {
  font-size: 11px;
  color: #666;
  line-height: 1.5;
  margin-top: 12px;
}

.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;
}

/* ─── Export modal ────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.72);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }

.modal-box {
  background: #1c1c1c;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 16px;
  padding: 22px 24px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 32px 80px rgba(0,0,0,.9);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.12) transparent;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
}

.modal-close {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #999;
}
.modal-close:hover { color: #fff; }

.export-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #ccc;
  margin-bottom: 14px;
  cursor: pointer;
  user-select: none;
}
.export-opt input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: #d9d9d9;
  cursor: pointer;
}

.section-lbl {
  font-size: 12px;
  color: #777;
  margin: 0 0 6px;
}

.export-code {
  width: 100%;
  height: 170px;
  background: #0d0d0d;
  color: #88c888;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  padding: 10px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  line-height: 1.5;
  resize: vertical;
}

.modal-btns {
  display: flex;
  gap: 8px;
  margin: 10px 0 18px;
}

/* Instructions accordion */
.export-howto {
  border-top: 1px solid rgba(255,255,255,.08);
  padding-top: 14px;
}
.export-howto > summary {
  cursor: pointer;
  font-size: 13px;
  color: #999;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.export-howto > summary::before {
  content: "▶";
  font-size: 10px;
  transition: transform .15s;
}
.export-howto[open] > summary::before { transform: rotate(90deg); }
.export-howto > summary:hover { color: #ddd; }

.howto-body {
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.65;
  color: #bbb;
}
.howto-body p { margin: 10px 0 5px; }
.howto-body p:first-child { margin-top: 0; }
.howto-body strong { color: #eee; }
.howto-body ol { margin: 5px 0; padding-left: 20px; }
.howto-body ol li { margin-bottom: 4px; }
.howto-body code {
  background: #111;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: #88c888;
}

.code-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 8px 0 14px;
}
.snippet {
  flex: 1;
  display: block;
  background: #0d0d0d;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: #88c888;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}
.copy-sm {
  flex-shrink: 0;
  padding: 7px 11px;
  font-size: 12px;
  border-radius: 8px;
}

/* ─── Character counter ───────────────────────────────── */

.char-counter {
  font-size: 11px;
  font-family: ui-monospace, monospace;
  color: #444;
  margin: 4px 0 0;
  min-height: 15px;
  line-height: 1;
}
.char-counter .cc      { color: #555; }
.char-counter .cc-warn { color: #b07828; }
.char-counter .cc-over { color: #c04040; }
.char-counter .cc-sep  { color: #2e2e2e; }

/* ─── Display-frame background variants ───────────────── */

.display-frame.bg-black {
  background: #000;
}
.display-frame.bg-dim {
  background: radial-gradient(ellipse 100% 80% at 50% 50%, #2a2828 0%, #131313 100%);
}
.display-frame.bg-midnight {
  background: radial-gradient(ellipse 100% 80% at 50% 50%, #060a18 0%, #010308 100%);
}
.display-frame.bg-warm {
  background: radial-gradient(ellipse 100% 80% at 50% 50%, #140800 0%, #040100 100%);
}
.display-frame.bg-paper {
  background: #cfc9b8;
}

/* ─── Board style: Minimal ────────────────────────────── */

.grid.s-minimal {
  background: #101010;
  border: 1px solid rgba(255,255,255,.07);
  box-shadow: 0 10px 40px rgba(0,0,0,.7);
  padding: 14px 12px;
  row-gap: 4px;
}

.grid.s-minimal .cell {
  background: #1a1a1a;
  border: 1px solid rgba(255,255,255,.09);
  box-shadow: none;
  border-radius: 4px;
}

.grid.s-minimal .glyph {
  text-shadow: none;
  font-weight: 700;
}

/* ─── Board style: Neon glow ──────────────────────────── */

.grid.s-neon {
  background: #020202;
  border: 1px solid rgba(255,255,255,.04);
  box-shadow:
    0 0 80px rgba(0,0,0,1),
    0 0 0 1px rgba(255,255,255,.02);
  padding: 20px 18px;
}

.grid.s-neon .cell {
  background: #030303;
  border: 1px solid rgba(255,255,255,.04);
  box-shadow: none;
  border-radius: var(--radius);
}

.grid.s-neon .glyph {
  text-shadow:
    0 0 4px var(--text),
    0 0 14px var(--text),
    0 0 36px var(--text),
    0 0 70px var(--text);
}

/* ─── Narrow screens / mobile ─────────────────────────── */
/*
 * The desktop layout is a fixed-height flex row with overflow:hidden.
 * Below 900px that leaves almost no room for the board, so we stack:
 * panel on top at full width, board underneath, page scrolls normally.
 */

@media (max-width: 900px) {
  html, body {
    height: auto;
    overflow: visible;
  }

  .wrap {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .panel {
    width: 100%;
    height: auto;
    overflow-y: visible;
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,.08);
    padding: 18px 18px 22px;
  }

  /*
   * The board has a fixed pixel width (cols × cellH), so on a phone it will
   * be wider than the viewport. Let it pan sideways instead of clipping.
   * justify-content stays flex-start and .grid gets margin:0 auto — with
   * justify-content:center the left overflow becomes unreachable.
   */
  .display-frame {
    flex: none;
    min-height: 55vh;
    padding: 26px 18px;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .grid {
    margin: 0 auto;
    flex-shrink: 0;
  }

  /* inset:0 would only cover the visible scroll window, not the board */
  .display-frame::before { display: none; }

  /* iOS Safari zooms the page when focusing inputs under 16px */
  textarea,
  select,
  input[type="number"] {
    font-size: 16px;
  }
}
