/*
 * Tsumiki — page chrome and the heads-up display.
 *
 * Two visual languages, on purpose, and they meet in the middle.
 *
 * The menus are a Japanese stationery drawer: washi paper, warm cream and
 * fibrous, with sumi-ink text on it and torii vermilion for anything that wants
 * to be pressed. Corners are softened rather than hard, edges are one hairline
 * of ink rather than a carved bevel, and a button sits on a three-pixel shadow
 * so it reads as a wooden block resting on the page — which is what a つみき is.
 * The name of the game is the design brief.
 *
 * The in-world HUD is the other language: lantern light on a dark ground. Over
 * a lit 3D world, paper loses and ink-on-black wins, so the panels out there are
 * near-black with a paper hairline, and the words themselves glow warm. English
 * on screen should always be the brightest thing in the room. The bloom in the
 * shader is the other half of the same idea.
 *
 * The paper fibre is one inline SVG turbulence, so the whole game is still a
 * folder of text files with nothing to fetch.
 */

:root {
  /* Paper and ink — the menu language. */
  --paper:    #f4ecdc;     /* washi, warm cream */
  --paper-dk: #e5d8bf;     /* a button face, one shade down */
  --paper-ed: #c3b090;     /* the shadow a block casts on the page */
  --ink:      #241f1a;     /* sumi */
  --ink-2:    #554c42;     /* secondary text */
  --hair:     rgba(36, 31, 26, 0.30);   /* the one-hairline border */

  /* The three colours that carry meaning. */
  --shu:      #cf4630;     /* vermilion: torii, primary action, the seal */
  --shu-dk:   #9b2e1c;
  --ai:       #2d4a6b;     /* indigo: the second action, Japanese lines */
  --kin:      #b8912f;     /* gold leaf: rewards, labels, stars */
  --sakura:   #e78ba6;

  /* Lantern light — the HUD language. */
  --night:    rgba(18, 15, 12, 0.80);   /* panel ground over the world */
  --glow:     #ffd9a0;     /* the warm glow on live text */
  --ink-lt:   #f6efe2;     /* text on night */
  --rose:     #ffc7d5;     /* Japanese lines on night, so the eye separates */

  --slot:     rgba(28, 24, 20, 0.9);    /* inventory-slot interior */

  /* Washi fibre. Greyscale turbulence, laid over the cream at low opacity. */
  --washi: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23f)' opacity='0.5'/%3E%3C/svg%3E");

  --shadow: 0 2px 0 rgba(0, 0, 0, 0.55);
  --lift:   0 6px 18px rgba(0, 0, 0, 0.30);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  overflow: hidden;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN",
               system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink-lt);
}

#stage {
  display: block;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
  /* chunky is the point — never let the browser smooth the upscale */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.hidden { display: none !important; }

/* ---------------------------------------------------------------- crosshair */

/*
 * A ring with four ticks pointing into it, rather than a plus sign. Bigger than
 * most games draw it on purpose: eight-year-old eyes on a laptop lose a small
 * mark against grass, and a player who cannot see where she is aiming reads that
 * as the game being broken. The ring is what makes the aim point legible over
 * both a bright sky and a dark cave.
 */
#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -50%);
  opacity: 0.9;
}
#crosshair::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(0, 0, 0, 0.5);
}
#crosshair span {
  position: absolute;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
}
/* Two ticks across the middle, with a gap in the centre so the block underneath
 * is never hidden by the thing pointing at it. */
#crosshair span:nth-child(1) { left: 13px; top: -5px;  width: 2px; height: 8px; }
#crosshair span:nth-child(2) { left: 13px; top: 25px;  width: 2px; height: 8px; }
body.big-aim #crosshair { width: 42px; height: 42px; }
body.big-aim #crosshair::after { border-width: 3px; }
body.big-aim #crosshair span:nth-child(1) { left: 19px; top: -7px; width: 3px; height: 11px; }
body.big-aim #crosshair span:nth-child(2) { left: 19px; top: 38px; width: 3px; height: 11px; }

/* ------------------------------------------------------------- world HUD */

/*
 * Everything that floats over the world shares one shape: a soft-cornered slab
 * of night with a single paper hairline around it. No bevel, no keyline stack —
 * one border and one shadow is enough to lift it off a moving background.
 */
.panel {
  background: var(--night);
  border: 1px solid rgba(244, 236, 220, 0.22);
  border-radius: 10px;
  box-shadow: var(--lift);
  padding: 10px 18px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#look {
  position: absolute;
  left: 50%;
  top: calc(50% + 46px);
  transform: translateX(-50%);
  text-align: center;
  min-width: 190px;
}
#look .en {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0.10em;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7), 0 0 14px var(--glow),
               0 0 32px rgba(255, 217, 160, 0.45);
}
/* The Japanese is only a little smaller than the English, not half its size.
 * It is the line she can already read, and it is what makes the English above
 * it mean anything. */
#look .ja {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-top: 4px;
  color: var(--rose);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7), 0 0 16px rgba(231, 139, 166, 0.7);
}
#look .hint {
  font-size: 11px;
  margin-top: 5px;
  opacity: 0.45;
  letter-spacing: 0.1em;
}

/* --------------------------------------------------------------- hotbar */

/*
 * Nine separate tiles with air between them, not one bar with slots cut into it
 * — the palette reads as a row of blocks laid on a shelf, which is the object
 * the game is about. The selected one lifts and takes a vermilion ring.
 */
#hotbar {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 0;
  background: none;
  pointer-events: auto;
}
.slot {
  position: relative;
  width: 62px;
  height: 62px;
  background: var(--slot);
  border: 1px solid rgba(244, 236, 220, 0.18);
  border-radius: 9px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.08s ease;
}
.slot canvas {
  position: absolute;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  image-rendering: pixelated;
}
.slot .lab {
  position: relative;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding-bottom: 3px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
  overflow: hidden;
  max-width: 60px;
}
.slot .key {
  position: absolute;
  left: 5px;
  top: 3px;
  font-size: 10px;
  color: #fff;
  opacity: 0.4;
}
.slot.on {
  transform: translateY(-6px);
  border-color: var(--shu);
  box-shadow: 0 0 0 2px var(--shu), 0 6px 16px rgba(0, 0, 0, 0.5),
              0 0 22px rgba(207, 70, 48, 0.5);
  z-index: 2;
}

/* ----------------------------------------------------------- word flash */

/*
 * The big one. When a block is named, the word is thrown across the middle of
 * the screen — English enormous, Japanese enormous underneath it — held for
 * about a second and then let go.
 *
 * It is deliberately the largest thing in the game. Text that shares the screen
 * politely with the scenery gets read as scenery; text that takes the screen
 * gets read. Both lines are sized in vw so they fill a laptop and a big monitor
 * the same way, and both carry the lantern glow, so the word is also the
 * brightest object in the frame for as long as it is up.
 */
#flash {
  position: fixed;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  text-align: center;
  width: 96%;
  pointer-events: none;
  z-index: 40;              /* above the overlays — see the note in index.html */
}
.fl-tag {
  font-size: clamp(12px, 1.5vw, 20px);
  letter-spacing: 0.34em;
  font-weight: 800;
  color: var(--glow);
  margin-bottom: 6px;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.8), 0 0 22px rgba(255, 217, 160, 0.7);
}
.fl-en {
  font-size: clamp(54px, 10vw, 148px);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.02;
  color: #fff;
  text-shadow:
    0 4px 10px rgba(0, 0, 0, 0.6),
    0 0 18px rgba(255, 255, 255, 0.5),
    0 0 46px var(--glow),
    0 0 96px rgba(255, 217, 160, 0.5);
}
.fl-ja {
  font-size: clamp(32px, 5.6vw, 82px);
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1.25;
  margin-top: 6px;
  color: var(--rose);
  text-shadow:
    0 3px 8px rgba(0, 0, 0, 0.6),
    0 0 16px rgba(231, 139, 166, 0.85),
    0 0 54px rgba(231, 139, 166, 0.6);
}
.fl-s {
  font-size: clamp(14px, 1.8vw, 24px);
  margin-top: 12px;
  color: #fff6e6;
  opacity: 0.92;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.75), 0 0 20px rgba(255, 217, 160, 0.5);
}

/* Vermilion treatment for a word she has never met before. */
.flash.gold .fl-en {
  text-shadow: 0 4px 10px rgba(0, 0, 0, 0.6),
               0 0 20px rgba(255, 255, 255, 0.6),
               0 0 52px var(--shu),
               0 0 115px rgba(207, 70, 48, 0.65);
}

/*
 * Overshoot, settle, hold, lift away. The hold is done by the element's own
 * lifetime rather than by the keyframes, so the same animation serves a
 * one-second glance at DIRT and a two-and-a-half second fanfare for a new word.
 */
.flash {
  animation: flashIn 0.34s cubic-bezier(0.16, 1.4, 0.4, 1) both;
}
.flash.out { animation: flashOut 0.42s ease-in both; }

@keyframes flashIn {
  from { opacity: 0; transform: scale(0.62) translateY(26px); filter: blur(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); filter: blur(0); }
}
@keyframes flashOut {
  to { opacity: 0; transform: scale(1.10) translateY(-26px); filter: blur(3px); }
}

/* --------------------------------------------------------------- toasts */

#toasts {
  position: fixed;
  left: 50%;
  top: 13%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 41;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
}
.toast {
  padding: 12px 26px;
  background: var(--night);
  border: 1px solid rgba(244, 236, 220, 0.22);
  border-radius: 12px;
  box-shadow: var(--lift);
  text-align: center;
  animation: pop 0.26s cubic-bezier(0.16, 1.3, 0.4, 1);
}
.toast .t-en {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.7), 0 0 14px var(--glow);
}
.toast .t-ja { font-size: 15px; color: var(--rose); margin-top: 2px;
               text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8); }
.toast .t-tag {
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--kin);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8), 0 0 12px rgba(184, 145, 47, 0.6);
  margin-bottom: 4px;
}
.toast.fade { animation: fadeout 0.4s ease-in forwards; }
.toast.gold .t-en { text-shadow: 0 2px 5px rgba(0, 0, 0, 0.7), 0 0 18px var(--shu); }

@keyframes pop {
  from { transform: scale(0.78) translateY(10px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
@keyframes fadeout { to { transform: translateY(-14px); opacity: 0; } }

/* -------------------------------------------------------- corners, quest */

#topright {
  position: absolute;
  right: 16px;
  top: 14px;
  text-align: right;
  letter-spacing: 0.06em;
}
#stars {
  color: var(--kin);
  font-weight: 800;
  font-size: 22px;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.75), 0 0 14px rgba(184, 145, 47, 0.7);
}
#mute {
  font-size: 12px;
  margin-top: 4px;
  color: var(--rose);
  letter-spacing: 0.08em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

#wordCount {
  font-size: 12px;
  color: #fff;
  opacity: 0.6;
  margin-top: 2px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}

/* The open job. A vermilion rule down the left edge marks it as the one thing
 * on screen that is asking for something. */
/*
 * The column of pinned lines. It is one positioned stack rather than two
 * absolutely-placed panels because Nina's line is one, two or three lines tall
 * depending on the job, and anything given a fixed `top` underneath it will
 * sooner or later be sitting on top of it.
 */
#lines {
  position: absolute;
  left: 16px;
  top: 14px;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}
#quest {
  border-left: 3px solid var(--shu);
}
/* The second line is the same furniture in the lantern colour, so at a glance
   the two are plainly different kinds of thing without being different shapes. */
#note {
  border-left: 3px solid var(--kin);
}
#note.hidden { display: none; }
.qtitle {
  font-size: 10px;
  letter-spacing: 0.28em;
  color: var(--kin);
  margin-bottom: 5px;
}
.qbody { font-size: 15px; line-height: 1.55; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8); }
.qbody b {
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8), 0 0 12px var(--glow);
  letter-spacing: 0.04em;
}
.qbody .sub { display: block; font-size: 12px; color: var(--rose); margin-top: 3px; }

/* ------------------------------------------------------------- overlays */

/*
 * Every full-screen panel stands in front of the shrine at three times of day.
 *
 * The artwork is the background rather than a picture inside the panel, which
 * is both better looking and less code: nothing has to be laid out, nothing
 * competes with the buttons for the middle of the screen, and a phone in
 * portrait gets the same treatment as a laptop for free.
 *
 * The gradient over it is not decoration. The sheet in front is pale paper, so
 * the scrim's job is to give it something dark and even to sit against however
 * bright the photograph happens to be behind it.
 */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #1a1512;
  background-image:
    linear-gradient(rgba(12, 9, 7, 0.62), rgba(12, 9, 7, 0.48) 34%,
                    rgba(12, 9, 7, 0.52) 66%, rgba(12, 9, 7, 0.72)),
    url(../img/splash.jpg);
  background-size: auto, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
  image-rendering: auto;
}

/*
 * The sheet is a piece of washi laid on the photograph: warm cream, fibrous,
 * one hairline of ink around it, and a real shadow underneath. Dark text on
 * light paper is the whole departure — a menu should read like a book she is
 * being handed, not like a wall of the world she is standing in.
 */
.sheet {
  position: relative;
  width: min(900px, 94vw);
  max-height: 88vh;
  overflow: auto;
  padding: 30px 34px 34px;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    var(--washi),
    radial-gradient(120% 90% at 50% 0%, rgba(255, 253, 246, 0.9), rgba(0, 0, 0, 0) 60%),
    linear-gradient(180deg, #f7f0e2, #eadfc8);
  background-size: 160px 160px, auto, auto;
  background-blend-mode: multiply, normal, normal;
  border: 1px solid var(--hair);
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), 0 2px 0 rgba(255, 255, 255, 0.5) inset;
}

/* The title, with the vermilion rule under it that runs through the whole
 * design — the same red as the torii on the hill outside. */
.sheet h1 {
  margin: 0 0 10px;
  padding-bottom: 10px;
  font-size: 44px;
  letter-spacing: 0.14em;
  color: var(--ink);
  border-bottom: 3px solid var(--shu);
  display: inline-block;
}
.sheet h2 {
  margin: 0 0 20px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ai);
  letter-spacing: 0.04em;
}
.sheet p {
  font-size: 14px;
  line-height: 1.8;
  color: var(--ink-2);
}
.sheet a { color: var(--shu); text-decoration: none; border-bottom: 2px solid rgba(207, 70, 48, 0.35); }
.sheet a:hover { border-bottom-color: var(--shu); }

/*
 * The splash line, as a hanko — the red seal a Japanese artist presses into the
 * corner of a finished page. Same job as the throwaway line it replaces: one
 * small piece of the screen that is allowed to be a joke. It tilts a little,
 * because a stamp pressed by hand always does, and it holds still.
 */
.splash {
  position: absolute;
  right: 30px;
  top: 34px;
  max-width: 210px;
  white-space: normal;
  text-align: center;
  color: #fff4ea;
  background: var(--shu);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: 0.02em;
  padding: 10px 12px;
  border-radius: 4px;
  box-shadow: 0 0 0 2px rgba(255, 244, 234, 0.55) inset, 0 4px 12px rgba(0, 0, 0, 0.3);
  transform: rotate(-4deg);
}

/* -------------------------------------------------------------- buttons */

/*
 * A button is a wooden block resting on the page: a flat face, a hairline of
 * ink, and three pixels of its own shadow underneath. Pressing it pushes it
 * down onto the paper and the shadow goes away. That is the whole interaction,
 * and it is the only one in the game that isn't a block.
 */
.btn {
  pointer-events: auto;
  display: inline-block;
  padding: 13px 26px;
  margin: 8px 10px 3px 0;
  background: var(--paper-dk);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.07em;
  cursor: pointer;
  border: 1px solid var(--hair);
  border-radius: 7px;
  box-shadow: 0 3px 0 var(--paper-ed);
  transition: transform 0.06s ease, background 0.12s ease, box-shadow 0.06s ease;
}
.btn:hover { background: #f0e6d2; box-shadow: 0 3px 0 var(--paper-ed), 0 0 0 3px rgba(207, 70, 48, 0.28); }
.btn:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--paper-ed);
}
/* The primary action. Kept as .amber for the markup that already asks for it. */
.btn.amber {
  background: var(--shu);
  color: #fff4ea;
  border-color: rgba(0, 0, 0, 0.25);
  box-shadow: 0 3px 0 var(--shu-dk);
}
.btn.amber:hover { background: #e05340; box-shadow: 0 3px 0 var(--shu-dk), 0 0 0 3px rgba(207, 70, 48, 0.3); }
.btn.amber:active { box-shadow: 0 0 0 var(--shu-dk); }
.btn small { display: block; font-size: 11px; font-weight: 600; opacity: 0.75;
             letter-spacing: 0; margin-top: 2px; }
.btn.amber small { color: #ffe6dd; opacity: 0.9; }

.keys { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 24px; margin: 18px 0 22px; }
.keys div { font-size: 13px; color: var(--ink-2); }
.keys kbd {
  display: inline-block;
  min-width: 24px;
  text-align: center;
  padding: 3px 8px;
  margin-right: 10px;
  background: #fbf6ea;
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  border: 1px solid var(--hair);
  border-radius: 5px;
  box-shadow: 0 2px 0 var(--paper-ed);
}

/* ----------------------------------------------------- book / quiz cards */

.wgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.wcard {
  pointer-events: auto;
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  color: var(--ink);
  background: #fbf6ea;
  border: 1px solid var(--hair);
  border-radius: 8px;
  box-shadow: 0 2px 0 var(--paper-ed);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.wcard:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 0 var(--paper-ed), 0 0 0 3px rgba(207, 70, 48, 0.3);
}
.wcard .ic { font-size: 30px; line-height: 1.15; }
.wcard .ic canvas { image-rendering: pixelated; }
.wcard .en { font-size: 15px; font-weight: 800; letter-spacing: 0.05em; color: var(--ink); }
.wcard .ja { font-size: 11px; color: var(--ai); }
.wcard.locked { opacity: 0.34; cursor: default; box-shadow: none; }
.wcard.locked:hover { transform: none; box-shadow: none; }
.wcard.locked .en, .wcard.locked .ja { color: var(--ink-2); }

/* A category heading, set as a small indigo rule-and-label. */
.cat {
  margin-top: 24px;
  font-size: 11px;
  letter-spacing: 0.26em;
  color: var(--ai);
  border-bottom: 1px solid var(--hair);
  padding-bottom: 5px;
}

/* ------------------------------------------------------- spelling tray */

.bigicon { font-size: 92px; text-align: center; line-height: 1; margin: 8px 0 12px; }
.bigicon canvas { image-rendering: pixelated; }

/* The word being built. Empty cells are ruled boxes on the paper — the shape of
 * a Japanese squared writing sheet — and a filled one is stamped vermilion. */
.spell { display: flex; gap: 8px; justify-content: center; margin: 14px 0 20px; flex-wrap: wrap; }
.cell {
  width: 54px;
  height: 64px;
  background: rgba(255, 255, 255, 0.45);
  border: 2px solid var(--hair);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  font-weight: 800;
  color: var(--ink);
}
.cell.full {
  background: var(--shu);
  border-color: var(--shu-dk);
  color: #fff4ea;
}
.cell.space { border: none; background: none; width: 22px; }

.tiles { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.tile {
  pointer-events: auto;
  width: 54px;
  height: 58px;
  background: var(--paper-dk);
  font: inherit;
  font-size: 26px;
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
  border: 1px solid var(--hair);
  border-radius: 7px;
  box-shadow: 0 3px 0 var(--paper-ed);
  transition: transform 0.06s ease, background 0.12s ease;
}
.tile:hover { background: #f0e6d2; }
.tile:active { transform: translateY(3px); box-shadow: 0 0 0 var(--paper-ed); }
.tile:disabled { opacity: 0.22; cursor: default; transform: none; box-shadow: none; }
.tile.wrong { animation: shake 0.28s ease; background: var(--shu); color: #fff4ea; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.center { text-align: center; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* Say-it-again. Round, indigo, and the only circle in the menus, because it is
 * the only control that makes a sound rather than a change. */
.say {
  pointer-events: auto;
  background: var(--ai);
  color: #f2f6fb;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 3px 0 #1c3049;
}
.say:hover { background: #3a5c85; }
.say:active { transform: translateY(3px); box-shadow: 0 0 0 #1c3049; }

/* ------------------------------------------------------------- credits */

.credit { text-align: center; padding: 6px 0 4px; }
.credit .for {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--shu);
  margin: 26px 0 6px;
}
.credit .forja { font-size: 14px; color: var(--ai); margin-bottom: 24px; }
.credit .by { font-size: 20px; font-weight: 800; color: var(--ink); letter-spacing: 0.08em; }
.credit .role { font-size: 12px; letter-spacing: 0.22em; color: var(--kin); margin-bottom: 6px; }
.credit .small { font-size: 12px; color: var(--ink-2); opacity: 0.85; line-height: 1.9; margin-top: 20px; }

/* A soft darkening at the edge, so the DOM sits in the same room as the CRT. */
#hud::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 120px rgba(0, 0, 0, 0.5);
}

/* ============================================================== touch =====
 *
 * The on-screen controls, which only exist on a device that reports touch.
 *
 * Everything here is bigger than a desktop designer would draw it. The target
 * is an eight-year-old's finger on an iPad held in two hands, and a control she
 * misses is a control she stops using — so the buttons are 76px, the thumb
 * stick is floating rather than fixed, and the two clusters sit inside the
 * bottom corners where thumbs already rest.
 */

body.touch {
  /* No rubber-banding, no pull-to-refresh, no text selection on a long press. */
  overscroll-behavior: none;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* The sheets are the one thing that must still scroll under a finger. */
.sheet { touch-action: pan-y; }

.touchui {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;   /* only the controls themselves take touches */
}

/* ---- the floating stick ---- */

.tstick {
  position: absolute;
  width: 132px;
  height: 132px;
  margin: -66px 0 0 -66px;
  border-radius: 50%;
  background: rgba(10, 14, 12, 0.30);
  box-shadow: inset 0 0 0 2px rgba(244, 236, 220, 0.35);
  pointer-events: none;
}
.tknob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 244, 226, 0.6);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4), 0 0 18px rgba(255, 217, 160, 0.55);
  transform: translate(-26px, -26px);
}

/* ---- the action cluster, bottom right ---- */

.tpad {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 10px;
  justify-items: center;
}

.tbtn {
  pointer-events: auto;
  width: 76px;
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  color: #fff;
  background: rgba(22, 18, 15, 0.55);
  border: 1px solid rgba(244, 236, 220, 0.28);
  border-radius: 16px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
  user-select: none;
}
.tbtn.on {
  background: rgba(207, 70, 48, 0.55);
  border-color: rgba(255, 244, 234, 0.6);
  box-shadow: 0 0 18px rgba(207, 70, 48, 0.5);
}

/* Breaking is the verb this game is about, so it is the big one. */
.tbtn.dig {
  grid-column: 3;
  grid-row: 2 / span 2;
  height: 162px;   /* two rows plus the gap between them */
  font-size: 40px;
  background: rgba(155, 46, 28, 0.5);
}
.tbtn.put  { grid-column: 3; grid-row: 1; }
.tbtn.jump { grid-column: 2; grid-row: 3; font-size: 26px; }
.tbtn.down { grid-column: 1; grid-row: 3; font-size: 26px; }
.tbtn.use  { grid-column: 2; grid-row: 2; font-weight: 800; font-size: 26px; }
.tbtn.say  { grid-column: 1; grid-row: 2; font-size: 26px; }
.tbtn.fly  { grid-column: 1; grid-row: 1; font-size: 26px; }

/* ---- menu and book, top left, away from the thumbs ---- */

.tcorner {
  position: absolute;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  /* Five buttons now — menu, book, map, camera and (once bought) fireworks —
     which is 350px in a row and wider than a phone held upright. Wrapping keeps
     them all reachable by the left thumb instead of pushing one off-screen. */
  flex-wrap: wrap;
  max-width: min(46vw, 300px);
}
.tcorner .tbtn { width: 62px; height: 62px; font-size: 24px; }

/* ---- the rest of the HUD, rearranged for a tablet ---- */

body.touch #hotbar {
  bottom: auto;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
}
body.touch .slot { width: 54px; height: 54px; }
body.touch .slot canvas { width: 34px; height: 34px; }
/* The tiles lift upward on a desktop; on a tablet the bar is at the top, so the
 * selected one has to lift down or it walks off the screen edge. */
body.touch .slot.on { transform: translateY(5px); }

/* The quest line would sit under the hotbar; move it down. */
body.touch #lines { top: 92px; }
body.touch #topright { top: 92px; }

/* The word flash sits higher, clear of both thumbs. */
body.touch #flash { top: 40%; }

/* The look label must not land under the action pad. */
body.touch #look { top: calc(50% + 30px); }

/* No hover states on a touch screen — they stick after a tap. */
body.touch .btn:hover { background: var(--paper-dk); box-shadow: 0 3px 0 var(--paper-ed); }
body.touch .btn.amber:hover { background: var(--shu); box-shadow: 0 3px 0 var(--shu-dk); }
body.touch .wcard:hover { transform: none; box-shadow: 0 2px 0 var(--paper-ed); }
body.touch .btn { padding: 16px 28px; font-size: 17px; }
body.touch .wcard { padding: 14px 8px; }

/* ------------------------------------------------- small screens, upright ==
 *
 * A phone held in portrait is the hardest case this HUD faces: the play area is
 * a tall slot, the thumbs cover the bottom corners, and there is no width to
 * spare. Everything below shrinks the furniture and moves it out of the two
 * places a thumb naturally rests.
 *
 * The game is much better in landscape and says so once, quietly — but it has
 * to be properly playable upright, because a child will pick the phone up
 * whichever way round it already is.
 */

@media (max-width: 820px) {
  body.touch .tbtn { width: 62px; height: 62px; font-size: 24px; }
  body.touch .tbtn.dig { height: 134px; font-size: 32px; }
  body.touch .tpad { gap: 8px; }
  body.touch .tcorner .tbtn { width: 52px; height: 52px; font-size: 20px; }
  body.touch .slot { width: 48px; height: 48px; }
  body.touch .slot canvas { width: 30px; height: 30px; }
  body.touch .slot .lab { font-size: 8px; max-width: 46px; }
}

@media (max-width: 560px), (orientation: portrait) and (max-width: 900px) {
  /* The stick lives in the lower-left, so the menu and book move to the top,
   * under the hotbar, where nothing else wants to be. */
  body.touch .tcorner {
    bottom: auto;
    top: max(76px, calc(env(safe-area-inset-top) + 74px));
    left: max(10px, env(safe-area-inset-left));
    flex-direction: column;
  }
  body.touch .tcorner .tbtn { width: 48px; height: 48px; font-size: 19px; }

  body.touch .tbtn { width: 56px; height: 56px; font-size: 22px; }
  body.touch .tbtn.dig { height: 120px; font-size: 30px; }
  body.touch .tpad { gap: 7px; right: max(10px, env(safe-area-inset-right)); }

  body.touch #hotbar { gap: 4px; }
  body.touch .slot { width: 42px; height: 42px; }
  body.touch .slot canvas { width: 26px; height: 26px; }
  body.touch .slot .lab { font-size: 7px; max-width: 40px; letter-spacing: 0; }
  body.touch .slot .key { font-size: 8px; }

  /* The word is the point of the game, so it keeps its size for as long as it
   * can — but it must not run off a 360-pixel screen. */
  .fl-en { font-size: clamp(34px, 13vw, 74px); }
  .fl-ja { font-size: clamp(20px, 7vw, 40px); }
  .fl-s  { font-size: clamp(12px, 3.6vw, 18px); }

  #look .en { font-size: 24px; }
  #look .ja { font-size: 18px; }
  #look .hint { display: none; }
  body.touch #look { top: calc(50% + 18px); }

  #quest { max-width: 58vw; font-size: 13px; padding: 7px 11px; }
  .qbody { font-size: 13px; }
  #topright { top: max(72px, calc(env(safe-area-inset-top) + 70px)); }
  #stars { font-size: 17px; }

  .sheet { padding: 18px 16px 22px; width: 96vw; }
  .sheet h1 { font-size: 27px; letter-spacing: 0.08em; }
  .sheet h2 { font-size: 13px; }
  /* The seal cannot share the top line with a wrapped title on a phone, so it
   * drops below the rule and sits flat. */
  .splash {
    position: static;
    display: block;
    max-width: none;
    margin: 0 0 14px;
    transform: none;
    font-size: 12px;
  }
  .btn { padding: 13px 18px; font-size: 15px; }
  .wgrid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
  .cell { width: 42px; height: 52px; font-size: 24px; }
  .tile { width: 44px; height: 48px; font-size: 22px; }
}

/* The hint to turn the phone round. Shown once, briefly, never blocking. */
#rotate {
  position: fixed;
  left: 50%;
  bottom: 14%;
  transform: translateX(-50%);
  z-index: 45;
  display: none;
  padding: 14px 22px;
  text-align: center;
  background: var(--night);
  border: 1px solid rgba(244, 236, 220, 0.22);
  border-radius: 12px;
  box-shadow: var(--lift);
  pointer-events: none;
  animation: pop 0.3s ease;
}
#rotate .a { font-size: 30px; }
#rotate .b { font-size: 15px; font-weight: 800; color: #fff; letter-spacing: 0.06em; }
#rotate .c { font-size: 13px; color: var(--rose); }
body.show-rotate #rotate { display: block; }
