/* Ouija board — aged-wood surface, engraved glyphs, glass planchette.
 *
 * Mobile first: the base rules below describe a portrait phone and involve no
 * media query at all. There is one enhancement at the end of the file, keyed on
 * the viewport's aspect ratio rather than a width — see the comment there. */

* { box-sizing: border-box; }

:root {
  /* Everything stacked above and below the board on a phone, used to cap how tall
   * the fluid board may grow: stage padding (14 + 14), two control rows and their
   * gap (48 + 8 + 48), plus the stage's own gap (12). Deliberately a constant so
   * the board never resizes when the question panel replaces the summon button.
   * Keep in step with .stage/.controls. */
  --board-chrome: 144px;
  --board-slack: 10px;
}

html {
  height: 100%;
  /* stop iOS inflating type when a phone turns landscape */
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: radial-gradient(120% 100% at 50% 0%, #14121a 0%, #08070a 60%, #060508 100%);
  color: #e8dcc6;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

/* ---------------------------------------------------------------- layout */

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 14px;
  /* clear notches and the home indicator */
  padding-top: max(14px, env(safe-area-inset-top));
  padding-right: max(14px, env(safe-area-inset-right));
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  padding-left: max(14px, env(safe-area-inset-left));
}

/* The input claims a full row of its own and the three buttons wrap onto the
 * next one — no order juggling needed, the DOM order already reads that way. */
.controls {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
}

.board-wrap {
  position: relative;
  flex: 0 0 auto;
  /* Fluid: fill the width, but never grow so tall that the board no longer fits
   * the screen. The second declaration is the height-aware one; the first is the
   * fallback for browsers without dvh. */
  width: min(100%, 520px);
  width: min(100%, calc((100dvh - var(--board-chrome) - var(--board-slack)) * 5 / 7));
  max-width: 100%;
  aspect-ratio: 5 / 7;
  overflow: hidden;
  border-radius: 14px;
  background-color: #452a15;
  background-image:
    /* lit sheen across the top */
    radial-gradient(115% 68% at 50% 3%, rgba(255, 224, 170, .24), transparent 58%),
    /* weighted shade at the base */
    radial-gradient(105% 62% at 50% 107%, rgba(0, 0, 0, .55), transparent 62%),
    /* uneven ageing blotches */
    radial-gradient(45% 26% at 21% 25%, rgba(158, 94, 36, .28), transparent 72%),
    radial-gradient(40% 24% at 81% 54%, rgba(60, 30, 10, .32), transparent 74%),
    radial-gradient(38% 20% at 33% 83%, rgba(126, 70, 26, .24), transparent 76%),
    /* grain */
    repeating-linear-gradient(91deg,
      rgba(28, 13, 4, .16) 0 1.5px,
      rgba(255, 234, 196, .055) 1.5px 3.5px,
      rgba(0, 0, 0, 0) 3.5px 9px,
      rgba(22, 9, 2, .13) 9px 11px,
      rgba(255, 234, 196, .03) 11px 13px),
    linear-gradient(168deg, #67411f, #3b2211 52%, #513016);
  box-shadow:
    0 34px 80px rgba(0, 0, 0, .7),
    0 0 0 1px rgba(255, 214, 158, .12),
    inset 0 0 0 1px rgba(255, 226, 178, .14),
    inset 0 0 110px rgba(0, 0, 0, .5);
}

/* Fine grain over the whole board, planchette included. */
.board-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .2;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
}

.board {
  display: block;
  width: 100%;
  height: 100%;
}

/* --------------------------------------------------------------- controls
 * Thumb-sized first: every control clears 48px in both axes. */

.controls__input {
  flex: 1 1 100%;
  min-width: 0;
  min-height: 48px;
  padding: 12px 16px;
  font: inherit;
  /* the 1rem floor matters: iOS zooms the page in when a focused field is smaller */
  font-size: clamp(1rem, 2.4vw, 1.35rem);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #f2e7d3;
  background: rgba(255, 245, 225, .06);
  border: 1px solid rgba(255, 230, 190, .22);
  border-radius: 12px;
  outline: none;
  appearance: none;
  transition: border-color .18s ease, background .18s ease;
}

.controls__input::placeholder {
  color: rgba(232, 220, 198, .35);
  letter-spacing: .06em;
}

.controls__input:focus {
  border-color: rgba(255, 230, 190, .5);
  background: rgba(255, 245, 225, .09);
}

.controls__input:disabled { opacity: .5; }

.controls__btn {
  flex: 0 0 auto;
  min-height: 48px;
  padding: 12px 16px;
  font: inherit;
  font-size: clamp(1rem, 2vw, 1.15rem);
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #f6ecd8;
  border-radius: 12px;
  cursor: pointer;
  /* drop the double-tap-zoom wait and the grey iOS tap flash */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease, box-shadow .18s ease, opacity .18s ease;
}

/* The summon button is a sentence, not a label, so it keeps sentence case. */
.controls__btn--start {
  flex: 1 1 auto;
  background: linear-gradient(180deg, #7d2b2b, #4d1616);
  border: 1px solid rgba(255, 190, 160, .35);
  box-shadow: 0 8px 22px rgba(120, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .12);
  text-transform: none;
  letter-spacing: .03em;
}

.controls__btn--ask {
  background: linear-gradient(180deg, #6a4d1e, #3d2a10);
  border: 1px solid rgba(255, 220, 150, .38);
  box-shadow: 0 8px 22px rgba(90, 55, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .1);
  text-transform: none;
  letter-spacing: .04em;
}

/* ------------------------------------------------ question panel
 * Revealed only once the board has answered YES. The controls bar is a single
 * row either way, so the board does not resize when the panel swaps in. */

.controls [hidden] { display: none; }

.question {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.question__prompt {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1rem, 2.2vw, 1.25rem);
  color: #f2e7d3;
  white-space: nowrap;
}

/* Share the input look, but sit inline beside the prompt rather than owning a row. */
.question .controls__input { flex: 1 1 140px; }

/* Icon-only toggle: one constant accessible name, with state carried by
 * aria-pressed, which is how a toggle button is meant to work. */
.controls__btn--sound {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  padding: 12px;
  color: rgba(246, 236, 216, .68);
  background: linear-gradient(180deg, #2c2a38, #1a1922);
  border: 1px solid rgba(255, 230, 190, .18);
}

.controls__btn--sound[aria-pressed="true"] {
  color: #f6ecd8;
  border-color: rgba(255, 230, 190, .45);
  box-shadow: inset 0 0 18px rgba(255, 210, 150, .18);
}

.controls__btn:hover:not(:disabled) { transform: translateY(-1px); }
.controls__btn:active:not(:disabled) { transform: translateY(1px); }
.controls__btn:disabled { opacity: .38; cursor: default; box-shadow: none; }

/* ------------------------------------------------------------------ icons */

.btn-icon {
  display: block;
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.btn-icon__line {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* Muted is the default state, so the crossed-out speaker shows first. */
.btn-icon--on { display: none; }

.controls__btn--sound[aria-pressed="true"] .btn-icon--on { display: block; }
.controls__btn--sound[aria-pressed="true"] .btn-icon--off { display: none; }

/* ------------------------------------------------------------ board parts */

/* ------------------------------------------------------- board furniture */

.frame-outer {
  fill: none;
  stroke: rgba(84, 48, 20, .9);
  stroke-width: 7;
}

.frame-inner {
  fill: none;
  stroke: rgba(255, 228, 184, .3);
  stroke-width: 2;
}

.ornament,
.star,
.moon {
  fill: rgba(247, 232, 200, .84);
}

.sun-rays { fill: rgba(247, 232, 200, .55); }
.sun-face { fill: rgba(247, 232, 200, .92); }
.sun-eye { fill: rgba(64, 34, 12, .92); }

.sun-mouth {
  fill: none;
  stroke: rgba(64, 34, 12, .85);
  stroke-width: 3;
  stroke-linecap: round;
}

.rule {
  fill: none;
  stroke: rgba(247, 232, 200, .4);
  stroke-width: 2.5;
  stroke-linecap: round;
}

/* ----------------------------------------------------------------- glyphs */

.glyph {
  fill: #f0e4c8;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  stroke: rgba(46, 22, 6, .55);
  stroke-width: 1.4;
  paint-order: stroke fill;
}

.glyph--word {
  fill: #f5ebd0;
  font-weight: 700;
  stroke-width: 1.7;
}

.glyph--title {
  fill: #faf1d8;
  font-family: Didot, "Bodoni MT", "Baskerville Old Face", Palatino, Georgia, serif;
  font-weight: 500;
  stroke: rgba(46, 22, 6, .5);
  stroke-width: 2.2;
}

/* ------------------------------------------------------------ planchette */

.planchette {
  will-change: transform;
  filter: drop-shadow(0 16px 22px rgba(0, 0, 0, .6));
}

.planchette__body {
  stroke: rgba(255, 248, 228, .6);
  stroke-width: 3;
}

/* Faint inner outline, reads as a bevelled edge. */
.planchette__inner {
  fill: none;
  stroke: rgba(255, 240, 214, .22);
  stroke-width: 3;
}

.planchette__ring {
  fill: none;
  stroke: rgba(112, 72, 34, .5);
  stroke-width: 5;
}

/* The window is cut out of the body, so this is only its rim. */
.planchette__window {
  fill: none;
  stroke: rgba(255, 240, 210, .7);
  stroke-width: 2.5;
}

.debug-mark {
  fill: none;
  stroke: #46d6ff;
  stroke-width: 2;
}

/* Enhancement.
 *
 * Keyed on aspect ratio, not a width breakpoint: the layout below fills the
 * height, and that only fits when the viewport is wider than the board's own
 * 5:7 shape. A tall tablet at 700px wide has no room for it, a short laptop at
 * 700px wide does. */
@media (min-aspect-ratio: 5 / 7) {
  body { overflow: hidden; }

  .stage {
    height: 100dvh;
    min-height: 0;
    gap: 14px;
    padding: 16px;
  }

  .controls {
    flex-wrap: nowrap;
    gap: 10px;
  }

  .controls__input {
    flex: 1 1 auto;
    max-width: 520px;
  }

  .controls__btn--start { flex: 0 0 auto; padding: 13px 28px; }
  .controls__btn--ask { padding: 13px 24px; }

  .board-wrap {
    flex: 1 1 auto;
    min-height: 0;
    width: auto;
    max-width: 100%;
  }
}

/* ------------------------------------------------------------------- 404 ---
 * Shares the palette above, so the error page does not look like a different
 * site. Linked from .htaccess via ErrorDocument. */

.lost {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
  text-align: center;
}

.lost__panel { max-width: 30rem; }

.lost__code {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3rem, 12vw, 5rem);
  letter-spacing: .12em;
  color: rgba(247, 232, 200, .32);
}

.lost__title {
  margin: .2em 0 .5em;
  font-family: Didot, "Bodoni MT", "Baskerville Old Face", Palatino, Georgia, serif;
  font-size: clamp(1.3rem, 4vw, 2rem);
  font-weight: 500;
  color: #f2e7d3;
}

.lost__text {
  margin: 0 0 1.6em;
  color: rgba(232, 220, 198, .7);
}

.lost__link {
  display: inline-block;
  padding: 14px 30px;
  font-size: 1rem;
  letter-spacing: .04em;
  color: #f6ecd8;
  text-decoration: none;
  background: linear-gradient(180deg, #7d2b2b, #4d1616);
  border: 1px solid rgba(255, 190, 160, .35);
  border-radius: 12px;
  box-shadow: 0 8px 22px rgba(120, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .12);
  transition: transform .12s ease;
}

.lost__link:hover { transform: translateY(-1px); }
