/* Evokar — page shell + loading screen. In-game UI lives in hud.css. */

:root {
  --parchment: #e9dfc9;
  --parchment-light: #f2ead8;
  --parchment-deep: #d9ccb1;
  --sumi: #1c1b19;
  --charcoal: #52504c;
  --ink-wash: #a8a39a;
  --vermilion: #c45443;
  --umber: #8b7768;
  --font-ink: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", Georgia, "Times New Roman", serif;
  /* the screen's own safe insets: the notch, the home indicator, the rounded corners */
  --inset-t: env(safe-area-inset-top, 0px);
  --inset-r: env(safe-area-inset-right, 0px);
  --inset-b: env(safe-area-inset-bottom, 0px);
  --inset-l: env(safe-area-inset-left, 0px);
  /* what the HUD keeps clear of: those and the player's own margins on top (--dz-*, set on <html> by
     js/core/Viewport.js from Settings → Picture → Screen edges: a phone case's lip, a corner hard to
     reach), so everything that keeps to the safe area keeps to them too */
  --safe-t: calc(var(--inset-t) + var(--dz-t, 0px));
  --safe-r: calc(var(--inset-r) + var(--dz-r, 0px));
  --safe-b: calc(var(--inset-b) + var(--dz-b, 0px));
  --safe-l: calc(var(--inset-l) + var(--dz-l, 0px));
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;          /* no rubber band, no pull to refresh (Chrome reads it off html) */
  background: var(--parchment);
  color: var(--sumi);
  font-family: var(--font-ink);
}

body {
  position: fixed;
  inset: 0;
  touch-action: none;                 /* we handle every gesture ourselves */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;        /* no iOS long-press callout */
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* The screen: the canvas and every full-screen layer fill the fixed containing block (the visible
   viewport, kept current by the browser through toolbars, turns and full screen), all the same box,
   so the crosshair (#hud-root's centre) stays on the camera's (the canvas's). Not 100vh (taller than
   a phone's visible area while its toolbars are out) nor 100dvh (some iOS 26 releases leave a strip
   at the foot with it). --app-h: the measured height where that block falls short of the screen (an
   iPhone Home Screen app; the visible viewport left taller than it after a turn: js/core/Viewport.js,
   which also keeps the page from staying scrolled after the keyboard), and the player's own reach on
   past its foot (Settings → Picture → Screen edges). The canvas still draws under
   the home indicator and the notch (viewport-fit=cover); the HUD keeps clear of them with the
   --safe-* insets. */
#game-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;                        /* (a canvas doesn't stretch to its insets: sized outright) */
  height: var(--app-h, 100%);
  display: block;
  touch-action: none;
  outline: none;
  background: var(--parchment);
}
/* Under the opaque loading screen and the title (game/LoadingScreen.js _up) the canvas is left out of
   the picture: at opacity 0 the compositor skips it, where it would otherwise blend a whole screen of
   it into every frame of the menu (unlike visibility, it stays a target for pointer lock). Never while
   Play's book lifts the live canvas into its frame (ui/PlayTransition.js, body.pt-on). */
body.ls-up:not(.pt-on) #game-canvas { opacity: 0; }

#hud-root {
  position: fixed;
  inset: 0;
  pointer-events: none;               /* HUD children opt back in with pointer-events: auto */
  z-index: 10;
}
/* (with --app-h, top: 0 and this height win over bottom: 0; without it, auto stretches to the insets) */
#hud-root, #loading-screen, .sbook.da-root, .sbook.lb-root, .fd-root, .qr-overlay, .pt-root, .pt-top, .lx-board {
  height: var(--app-h, auto);
}

/* ---------------------------------------------------------------------------------------------
   Loading screen
   --------------------------------------------------------------------------------------------- */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  padding: calc(20px + var(--safe-t)) calc(20px + var(--safe-r)) calc(20px + var(--safe-b)) calc(20px + var(--safe-l));
  background: radial-gradient(ellipse at 50% 42%, var(--parchment-light) 0%, var(--parchment) 55%, var(--parchment-deep) 100%);
  transition: opacity 0.9s ease, visibility 0.9s;
}
#loading-screen.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.ink-title { display: flex; flex-direction: column; align-items: center; text-align: center; }

.enso { width: min(34vmin, 200px); height: auto; overflow: visible; }
.enso-stroke {
  fill: none;
  stroke: var(--sumi);
  stroke-width: 13;
  stroke-linecap: round;
  stroke-dasharray: 400;
  stroke-dashoffset: 400;
  animation: ink-paint 1.8s cubic-bezier(0.6, 0.05, 0.3, 1) 0.2s forwards;
}
.enso-sun { fill: var(--vermilion); opacity: 0; animation: ink-fade 1s ease 1.3s forwards; }

/* ---------------------------------------------------------------------------------------------
   Title card: EVOKAR, its seal, and the name's etymology as the subtitle.
   Shippori Mincho has no true italic (browsers would fake-slant it), so the etymology is set in a
   real italic serif, which also gives it the feel of an engraved title page.
   --------------------------------------------------------------------------------------------- */
:root { --font-italic: "Cormorant Garamond", "Iowan Old Style", Georgia, "Times New Roman", serif; }

#loading-screen h1.title {
  position: relative;
  margin: 0.5rem 0 0;
  font-weight: 800;
  font-size: clamp(2.2rem, 8.5vmin, 4.2rem);
  line-height: 1.05;
  letter-spacing: 0.5em;
  padding-left: 0.5em;               /* balances the trailing letter-spacing */
}

/* The hanko: a painter's red seal stamped after the title, 喚 = "to summon". Sized in em of the
   title so it scales with it; it sits in the space the trailing letter-spacing leaves. */
.hanko {
  position: absolute;
  left: 100%;
  top: 50%;
  width: 1.55em;
  height: 1.55em;
  display: grid;
  place-items: center;
  font-size: 0.32em;
  letter-spacing: 0;
  line-height: 1;
  border-radius: 0.12em;
  background: var(--vermilion);
  color: var(--parchment-light);
  box-shadow: inset 0 0 0 0.09em rgba(242, 234, 216, 0.55);
  transform: translate(-0.6em, -50%) rotate(-4deg);
  opacity: 0;
  animation: ink-fade 0.6s ease 1.9s forwards; /* stamped after the ensō finishes painting */
}

.etymology {
  position: relative;
  margin: 1rem 0 0;
  padding-top: 1rem;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  text-align: center;
}
/* a short vermilion brush rule between the title and its etymology */
.etymology::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 3.2rem;
  height: 2px;
  transform: translateX(-50%);
  border-radius: 2px;
  background: var(--vermilion);
  opacity: 0.85;
}
.ety-main {
  font-family: var(--font-italic);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(1.3rem, 4vmin, 2.1rem);
  line-height: 1.15;
  letter-spacing: 0.02em;
  color: var(--sumi);
  text-wrap: balance;
}
/* the Latin root is the one word in colour: the "voice" the whole game is about */
.ety-main i { color: var(--vermilion); }
.ety-roots {
  font-family: var(--font-italic);
  font-style: italic;
  font-size: clamp(0.95rem, 2.6vmin, 1.25rem);
  letter-spacing: 0.05em;
  color: var(--umber);
  text-wrap: balance;
}
.ety-roots i { color: var(--charcoal); }
.ety-dot { color: var(--vermilion); font-style: normal; padding: 0 0.4em; }

/* Short screens (phones in landscape): keep the title card compact so Begin never needs scrolling. */
@media (max-height: 560px) {
  .enso { width: min(20vmin, 110px); }
  #loading-screen { gap: 0.55rem; }
  #loading-screen h1.title { margin-top: 0.1rem; font-size: clamp(1.9rem, 9vmin, 3rem); }
  .etymology { margin-top: 0.45rem; padding-top: 0.6rem; gap: 0.15rem; }
  .ety-main { font-size: clamp(1.05rem, 4.8vmin, 1.45rem); }
  .ety-roots { font-size: clamp(0.8rem, 3.4vmin, 1rem); }
}

.load-progress {
  width: min(56vw, 320px);
  height: 4px;
  background: rgba(28, 27, 25, 0.12);
  border-radius: 2px;
  overflow: hidden;
}
.load-bar {
  height: 100%;
  width: 0%;
  background: var(--sumi);
  border-radius: 2px;
  transition: width 0.25s ease;
}
.load-status {
  margin: 0;
  min-height: 1.4em;
  font-size: 0.95rem;
  color: var(--charcoal);
  letter-spacing: 0.06em;
}

.begin-btn {
  font: inherit;
  font-size: 1.1rem;
  letter-spacing: 0.3em;
  padding: 0.8em 2.1em 0.8em 2.4em;
  min-height: 48px;
  color: var(--parchment);
  background: var(--sumi);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--parchment), 0 0 0 4px var(--sumi);
  transition: transform 0.15s ease, background 0.2s ease;
}
.begin-btn:hover, .begin-btn:focus-visible { background: var(--vermilion); outline: none; }
.begin-btn:active { transform: scale(0.97); }

.load-error {
  max-width: 34em;
  margin: 0;
  text-align: center;
  color: var(--vermilion);
  line-height: 1.5;
}

/* `hidden` must always win here too (the picker below sets display:flex). */
#loading-screen [hidden] { display: none !important; }

.load-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

/* ---------------------------------------------------------------------------------------------
   Scarf colour picker: ten hand-dropped ink dots. The chosen one gets a sumi ring; colours other
   painters already wear carry a tiny black dot (still selectable — they just become "Blue 2").
   --------------------------------------------------------------------------------------------- */
.scarf-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  --scarf: var(--vermilion);
}
.scarf-label {
  margin: 0;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.15em 0.45em;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  color: var(--charcoal);
}
.scarf-name {
  font-family: var(--font-italic);
  font-style: italic;
  font-size: 1.35em;
  color: var(--sumi);
  letter-spacing: 0.02em;
  border-bottom: 2px solid var(--scarf);
  line-height: 1.1;
}
.scarf-kanji { color: var(--scarf); font-weight: 800; font-size: 1.05em; }
.scarf-note { flex-basis: 100%; text-align: center; font-size: 0.78rem; color: var(--umber); min-height: 0; }
.scarf-note:empty { display: none; }

.scarf-swatches {
  display: grid;
  grid-template-columns: repeat(5, 44px);
  gap: 0.5rem 0.6rem;
}
.swatch {
  position: relative;
  width: 44px;
  height: 44px; /* 44 px: the minimum comfortable touch target */
  padding: 0;
  border: none;
  border-radius: var(--r, 50%);
  background: var(--c);
  cursor: pointer;
  box-shadow: inset 0 0 0 1.5px rgba(28, 27, 25, 0.28), inset 0 -5px 8px rgba(28, 27, 25, 0.12);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.swatch:hover { transform: scale(1.06); }
.swatch:focus-visible { outline: 2px dashed var(--sumi); outline-offset: 4px; }
.swatch[aria-checked="true"] {
  transform: scale(1.1);
  box-shadow: inset 0 0 0 1.5px rgba(28, 27, 25, 0.28), 0 0 0 3px var(--parchment), 0 0 0 5.5px var(--sumi);
}
.swatch.is-worn::after {
  content: "";
  position: absolute;
  right: -3px;
  top: -3px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--sumi);
  box-shadow: 0 0 0 2px var(--parchment);
}

/* Short landscape phones (iPhone mini sideways ≈ 375 px tall): title card left, picker + Begin
   right, so nothing ever needs scrolling. */
@media (max-height: 560px) and (min-width: 600px) and (orientation: landscape) {
  #loading-screen { flex-direction: row; gap: clamp(1.25rem, 5vw, 4.5rem); }
  .ink-title { flex: 0 1 auto; min-width: 0; }
  .load-side { flex: 0 0 auto; gap: 0.7rem; }
  .scarf-swatches { gap: 0.4rem 0.5rem; }
  .begin-btn { min-height: 44px; padding: 0.65em 1.9em 0.65em 2.2em; }
  .load-progress { width: min(34vw, 260px); }
}
/* Tiny landscape windows (narrow AND short): one compact column, the ensō and roots line go. */
@media (max-height: 560px) and (max-width: 599px) {
  .enso, .ety-roots { display: none; }
  #loading-screen { gap: 0.4rem; }
  .load-side { gap: 0.45rem; }
  .scarf-swatches { grid-template-columns: repeat(5, 36px); gap: 0.3rem 0.4rem; }
  .swatch { width: 36px; height: 36px; }
  .begin-btn { min-height: 40px; padding: 0.5em 1.6em 0.5em 1.9em; }
}

@keyframes ink-paint { to { stroke-dashoffset: 0; } }
@keyframes ink-fade { to { opacity: 0.92; } }

/* ---------------------------------------------------------------------------------------------
   Portrait hint (phones). Non-blocking: portrait still works.
   --------------------------------------------------------------------------------------------- */
#rotate-hint {
  display: none;
  position: fixed;
  left: 50%;
  top: calc(112px + var(--safe-t)); /* below the top row and the toast row (touch HUD) */
  transform: translateX(-50%);
  z-index: 50;
  padding: 0.45em 1em;
  border-radius: 999px;
  background: rgba(28, 27, 25, 0.82);
  color: var(--parchment);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  pointer-events: none;
  animation: ink-fade 0.6s ease 1s both, hint-out 0.8s ease 7s forwards;
}
@media (orientation: portrait) and (max-width: 700px) {
  #rotate-hint { display: block; }
}
@keyframes hint-out { to { opacity: 0; visibility: hidden; } }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; }

/* The summon slip owns the top of the screen while it is open. */
.summon-open #rotate-hint { display: none !important; }

/* ---------------------------------------------------------------------------------------------
   Screen edges, shown for a moment while one of their controls moves (js/ui/ScreenEdges.js): a thin
   vermilion line round the game's box, where its drawing ends (the canvas and every layer: --app-h),
   and a dashed one where the HUD keeps inside (--safe-*), the band between them faintly washed. Over
   everything, the open book included; it never takes a touch.
   --------------------------------------------------------------------------------------------- */
.edge-guide {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--app-h, 100%);
  z-index: 999;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
}
.edge-guide.is-on { opacity: 1; transition-duration: 0.12s; }
.edge-guide::before {
  content: "";
  position: absolute;
  top: var(--safe-t);
  right: var(--safe-r);
  bottom: var(--safe-b);
  left: var(--safe-l);
  border: 1.5px dashed var(--vermilion);
  border-radius: 6px;
  box-shadow: 0 0 0 100vmax rgba(196, 84, 67, 0.14);
}
.edge-guide::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 2px var(--vermilion);
}
