@font-face {
  font-family: "Apple Garamond";
  src: url("assets/fonts/AppleGaramond.ttf") format("truetype");
  font-display: swap;
}

:root {
  --ink: #2c2c2c;
  --paper: #fbf7f0;
  --dot: #b9b6b0;
  --quiet: rgba(44, 44, 44, 0.6);
  --guide: 102 158 240; /* construction lines of the Alphabet: the blue paper's color, like non-photo blue pencil */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  /* The original was printed paper: every screen sits on the same paper texture. */
  background: var(--paper) url("assets/paper/whiteBackPaper.jpg") repeat;
  background-size: 512px;
  color: var(--ink);
  font-family: "Apple Garamond", Garamond, Georgia, serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; border-radius: 6px; }

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  padding-block: env(safe-area-inset-top, 0px) env(safe-area-inset-bottom, 0px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.screen.active { display: flex; animation: fade-in 0.35s ease-out; }
@keyframes fade-in { from { opacity: 0; } }

/* ---------- header ---------- */
.bar {
  position: relative;
  z-index: 2;
  /* The bar floats over the board: only its buttons take clicks, so letters near the top stay grabbable. */
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 8px 4px;
}
.icon { width: 38px; height: 38px; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); flex: none; pointer-events: auto; }
.icon img { width: 100%; height: 100%; object-fit: contain; mix-blend-mode: multiply; transition: transform 0.15s; }
/* "Aa" is wider than the square icons: a wider box gives it the sound icon's height. */
.icon.wide { width: 48px; }
.icon:hover img { transform: scale(1.08); }
.logo { height: clamp(40px, 6vw, 64px); object-fit: contain; mix-blend-mode: multiply; }
.screen-title { margin: 0; font-size: 30px; font-weight: normal; line-height: 1; }

.pill {
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  padding: 6px 24px 5px;
  font-size: 21px;
  line-height: 1.1;
  background: rgba(251, 247, 240, 0.6);
  transition: transform 0.15s;
}
.pill:hover { transform: scale(1.04); }
.pill.solid { background: var(--ink); color: var(--paper); }

.link { font-size: 18px; color: var(--quiet); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.link:hover { color: var(--ink); }

/* The studio mark: a link to its author, bottom-left on every desktop screen. */
.studio {
  position: fixed;
  left: max(18px, env(safe-area-inset-left, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  width: 48px;
  mix-blend-mode: multiply;
  z-index: 1;
}
.studio img { display: block; width: 100%; transition: transform 0.15s; }
.studio:hover img { transform: scale(1.08); }
.studio:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; border-radius: 6px; }
/* Beside the studio mark, small: what the game keeps and sends (privacy.html). The phone has it in History. */
.privacy-link {
  position: fixed; z-index: 1;
  left: calc(max(18px, env(safe-area-inset-left, 0px)) + 60px);
  bottom: calc(27px + env(safe-area-inset-bottom, 0px));
  font-size: 15px; line-height: 1;
}

/* ---------- game ---------- */
/* Daily: history | logo, "#12 · October 22 · 0:41", progress | sound, and the Alphabet in the bottom-right corner (in
   the bar on the phone). Classic: exit | progress | sound. Tutorial (also .daily): Skip | logo, progress | sound, and
   the hint under the board. */
#game .bar { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
.side { display: flex; align-items: center; gap: 18px; min-width: 0; }
.side.end { justify-content: flex-end; }
#game.daily .exit, #game.classic .history-open:not(.pill), #game.tutorial .bar .history-open, #game.tutorial .alphabet-open { display: none; }
.skip { display: none; width: 44px; flex: none; text-align: left; pointer-events: auto; font-size: 18px; }
#game.tutorial .skip { display: block; }
#game.tutorial.won .skip { visibility: hidden; }
.title { min-width: 200px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
#game.classic .title { width: min(420px, 56vw); }
#game .logo { height: 40px; }
.subline { margin: 0; font-size: 19px; line-height: 1.2; white-space: nowrap; }
.subline span + span::before { content: "·"; margin: 0 0.4em; color: var(--quiet); }
.timer { display: inline-block; min-width: 2.6em; text-align: left; color: var(--quiet); }
#game.timing .timer { color: var(--ink); }
#game.won .timer { display: none; }
#game.classic .logo, #game.classic .subline { display: none; }
#game.tutorial .subline { display: none; }
/* Tutorial hint: what to do now, large, low on the screen (the board keeps its letters above it: board.js safe()). */
#game .hint {
  display: none;
  position: absolute; left: 0; right: 0; bottom: calc(clamp(22px, 5vh, 56px) + env(safe-area-inset-bottom, 0px));
  z-index: 2;
  margin: 0;
  font-size: 36px; line-height: 1.2; text-align: center; white-space: nowrap;
  pointer-events: none;
}
#game.tutorial .hint { display: block; }
#game.tutorial.won .hint { visibility: hidden; }
#game .hint.change { animation: fade-in 0.45s ease-out; }
.alphabet-open.corner {
  position: absolute; z-index: 2;
  right: max(18px, env(safe-area-inset-right, 0px));
  bottom: calc(19px + env(safe-area-inset-bottom, 0px)); /* centered on the studio mark's line */
  mix-blend-mode: multiply;
}
body:not(.touch-ui) .bar .alphabet-open, .touch-ui .alphabet-open.corner { display: none; }

.progress {
  width: 100%;
  max-width: 420px;
  height: 8px;
  border-radius: 99px;
  background: rgba(44, 44, 44, 0.12);
  overflow: hidden;
}
#game.daily .progress { max-width: 200px; height: 5px; margin-top: 5px; }
#game.daily.won .progress { visibility: hidden; }
.progress .fill { height: 100%; width: 0; background: var(--ink); border-radius: inherit; transition: width 0.25s ease-out; }

/* The board is the whole window, like the orthographic camera; the header floats over it. */
.board { position: absolute; inset: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; mix-blend-mode: multiply; cursor: default; touch-action: none; }
#board.grab { cursor: grab; }
#board.dragging { cursor: grabbing; }
.fatal { position: absolute; inset: 40% 0 auto; text-align: center; font-size: 22px; }

.win {
  position: absolute; inset: 0;
  display: none; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 70px 16px 40px;
  pointer-events: none;
  z-index: 3;
}
#game.daily .win { padding-top: 112px; }
.win.show { display: flex; }
.win-head, .win-foot { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.win-foot { gap: 6px; }
.win-logo { width: min(60vw, 520px); mix-blend-mode: multiply; animation: pop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.win p { margin: 0; }
.win .stats { font-size: 24px; animation: fade-in 0.6s 0.3s both; }
.win .par { font-size: 18px; color: var(--quiet); font-style: italic; animation: fade-in 0.6s 0.4s both; }
.win .par:empty { display: none; }
.win-buttons { display: flex; gap: 12px; pointer-events: auto; animation: fade-in 0.5s 0.5s both; margin-bottom: 4px; }
.next-in, .streak { font-size: 18px; color: var(--quiet); animation: fade-in 0.5s 0.6s both; }
.countdown { display: inline-block; min-width: 3.6em; text-align: left; }
.win:not(.daily) :is(.share, .history-open, .next-in, .streak) { display: none; }
.win:is(.daily, .tutorial) .next-level, .win:not(.tutorial) .today-open { display: none; }
.streak:empty { display: none; }
@keyframes pop { from { transform: scale(0.2) rotate(-6deg); opacity: 0; } }

/* On-screen keyboard (phone layout only): letters in the UI font, one key size for all. */
.keyboard { display: none; }

/* ---------- history ---------- */
#history .bar, #menu .bar { pointer-events: auto; }
.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 40px;
  touch-action: pan-y;
}
.stats-row { display: flex; justify-content: center; gap: clamp(18px, 5vw, 56px); margin: 6px auto 26px; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.stat b { font-weight: normal; font-size: 38px; line-height: 1; }
.stat span { font-size: 16px; color: var(--quiet); margin-top: 4px; white-space: nowrap; }
.days {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  max-width: 980px;
  margin: 0 auto;
}
.day {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 8px 12px;
  border-radius: 14px;
  border: 1.5px solid rgba(44, 44, 44, 0.14);
  background: rgba(255, 253, 249, 0.45);
  text-align: center;
}
.day canvas { width: 100%; height: 118px; mix-blend-mode: multiply; }
.day p { margin: 0; line-height: 1.25; }
.day-name { font-size: 17px; margin-top: 4px; }
.day-result { font-size: 16px; color: var(--quiet); }
.day.missed canvas { opacity: 0.45; }
.day.missed .day-result { font-style: italic; }
.day.today { border-color: var(--ink); cursor: pointer; }
.day.today:not(.solved) .day-result { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.day.today:hover canvas { transform: scale(1.04); transition: transform 0.3s; }
.links { display: flex; justify-content: center; gap: 28px; margin: 30px 0 0; }

/* ---------- classic menu ---------- */
.chapter-title {
  align-self: center;
  margin: 26px 0 0;
  font-size: 30px;
  font-weight: normal;
  letter-spacing: 0.01em;
  line-height: 1;
}
.chapter-title.quiet { visibility: hidden; }

.pages { flex: 1; display: flex; align-items: stretch; min-height: 0; padding: 12px 0; }
.nav { align-self: center; width: 34px; height: 52px; }
.nav.next img { transform: scaleX(-1); }
.nav.next:hover img { transform: scaleX(-1) scale(1.08); }
.nav[disabled] { visibility: hidden; }
.tiles { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; min-width: 0; }
.tile { position: relative; min-height: 0; }
.tile canvas { position: absolute; inset: 0; width: 100%; height: 100%; mix-blend-mode: multiply; transition: transform 0.4s; }
.tile:hover canvas { transform: scale(1.08); } /* Level.OnMouseOver */
.dots { display: flex; justify-content: center; gap: 12px; padding: 8px 0 26px; }
.dots span { width: 14px; height: 14px; border-radius: 50%; background: var(--dot); transition: transform 0.2s; }
.dots span.on { background: var(--ink); transform: scale(1.5); }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }

.toast {
  position: fixed; left: 50%; bottom: 30%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 8px 18px; border-radius: 99px; font-size: 18px;
  opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 40;
}
.toast.show { opacity: 1; }

/* ---------- alphabet ---------- */
/* Over the game (which stays laid out under it, its clock held): the same paper, so nothing shows through. */
#alphabet { z-index: 5; background: var(--paper) url("assets/paper/whiteBackPaper.jpg") repeat; background-size: 512px; }
#alphabet .bar { pointer-events: auto; }
#alphabet .scroll { padding-top: 4px; }
.ab-sheet, .ab-detail { max-width: 1040px; margin: 0 auto; padding: 0 12px; }
.ab-sheet[hidden], .ab-detail[hidden] { display: none; }
.ab-sheet svg, .ab-detail svg { display: block; overflow: visible; mix-blend-mode: multiply; }
.ab-grid { fill: none; stroke: rgb(var(--guide) / 0.22); stroke-width: 1; vector-effect: non-scaling-stroke; }
.ab-box { fill: none; stroke: rgb(var(--guide) / 0.7); stroke-width: 1; vector-effect: non-scaling-stroke; }
.ab-ink { fill: var(--ink); }

.ab-preview { margin: 8px 0 40px; cursor: text; }
.ab-line { width: 100%; }
.ab-rules { fill: none; stroke: rgb(var(--guide) / 0.5); stroke-width: 1; vector-effect: non-scaling-stroke; }
.ab-ghost { fill: none; stroke: var(--ink); stroke-opacity: 0.32; stroke-width: 1.1; vector-effect: non-scaling-stroke; }
.ab-caret { fill: var(--ink); animation: caret 1.1s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }

/* Rows of the sheet: cap line and baseline across, glyphs spread along them. --s = px per u (alphabet.js). */
.ab-row { position: relative; display: flex; justify-content: space-between; margin: 0 0 30px; }
.ab-rule { position: absolute; left: 0; right: 0; height: 1px; background: rgb(var(--guide) / 0.5); }
.ab-rule.cap { top: 0; }
.ab-rule.base { top: calc(22 * var(--s)); }
.ab-cell { position: relative; display: flex; flex-direction: column; align-items: center; transition: transform 0.2s; }
.ab-cell:hover { transform: translateY(-3px); }
.ab-cell:hover .ab-box { stroke: rgb(var(--guide) / 1); }
.ab-cell:hover .ab-grid { stroke: rgb(var(--guide) / 0.4); }

/* Detail: ‹ the letter on its grid ›, its four turns under it. */
.ab-detail { display: grid; grid-template-columns: 34px minmax(0, 1fr) 34px; grid-template-areas: "prev fig next" ". turns .";
  align-items: center; align-content: center; gap: 20px 28px; min-height: 100%; padding-bottom: 24px; }
.ab-detail .prev { grid-area: prev; }
.ab-detail .next { grid-area: next; }
.ab-figure { grid-area: fig; margin: 0; display: grid; place-items: center; min-width: 0; }
.ab-big { cursor: pointer; }
.ab-skel { fill: none; stroke: var(--paper); stroke-width: 1.3; stroke-opacity: 0.85; vector-effect: non-scaling-stroke; }
.ab-node { fill: var(--paper); }
.ab-turns { grid-area: turns; display: flex; justify-content: center; align-items: flex-end; gap: 8px; }
.ab-chip { display: grid; place-items: center; padding: 7px; border-radius: 8px; transition: background-color 0.15s; }
.ab-chip:hover { background: rgba(44, 44, 44, 0.06); }
.ab-chip.on { box-shadow: inset 0 0 0 1.25px rgba(44, 44, 44, 0.55); }
.ab-chip .ab-box { stroke: rgb(var(--guide) / 0.45); }

/* ---------- phone layout: touch screens and narrow windows (body.touch-ui, set by main.js) ---------- */
.touch-ui .studio, .touch-ui .privacy-link { display: none; }
.touch-ui .screen { padding-left: max(10px, env(safe-area-inset-left, 0px)); padding-right: max(10px, env(safe-area-inset-right, 0px)); }
.touch-ui #game { touch-action: none; }
/* Header in flow: the board is exactly the space between the header and the keyboard. */
.touch-ui .bar { padding: 10px 0 2px; gap: 10px; }
/* 34px icons in a 44px finger target (the padding is tappable, the negative margin keeps the layout). */
.touch-ui .icon { width: 44px; height: 44px; padding: 5px; margin: -5px; }
.touch-ui .icon.wide { width: 53px; }
.touch-ui .side { gap: 10px; }
.touch-ui .title { min-width: 160px; }
.touch-ui .skip { height: 44px; margin: -5px 0; font-size: 17px; }
.touch-ui #game .logo { height: 26px; }
.touch-ui .subline { font-size: 16px; }
.touch-ui #game .hint { position: static; padding: 2px 0 6px; font-size: 25px; }
.touch-ui #game.daily .progress { max-width: 160px; height: 4px; margin-top: 4px; }
.touch-ui #game.classic .progress { height: 6px; }
.touch-ui .board { position: relative; flex: 1; min-height: 0; }
.touch-ui .win, .touch-ui #game.daily .win { padding: 4px 8px 14px; }
.touch-ui .win-logo { width: min(78vw, 420px); }
.touch-ui .win .stats { font-size: 22px; }
.touch-ui .win .pill { padding: 10px 28px 9px; }

.touch-ui .keyboard {
  display: flex; flex-direction: column; gap: 8px;
  position: relative;
  width: 100%; max-width: 560px;
  margin: 0 auto;
  padding: 6px 0 10px;
}
#game.won .keyboard { display: none; }
.kb-row { display: flex; justify-content: center; gap: 5px; }
.key {
  --unit: calc((100% - 9 * 5px) / 10);
  flex: 0 0 var(--unit);
  height: 50px;
  display: grid; place-items: center;
  padding-top: 3px; /* Garamond capitals sit high in their line box */
  border-radius: 8px;
  font-size: 25px;
  line-height: 1;
  background: rgba(255, 253, 249, 0.75);
  box-shadow: inset 0 0 0 1px rgba(44, 44, 44, 0.22), 0 1.5px 0 rgba(44, 44, 44, 0.22);
  transition: opacity 0.15s, background-color 0.08s;
}
.key.down { background: var(--ink); color: var(--paper); }
/* Tutorial: the keys to press now glow softly. */
.key.glow { background: #fffdf9; box-shadow: inset 0 0 0 1.5px var(--ink), 0 0 0 3px rgba(44, 44, 44, 0.1), 0 1.5px 0 rgba(44, 44, 44, 0.3); animation: key-hint 1.6s ease-in-out infinite; }
@keyframes key-hint { 50% { transform: translateY(-2px); } }
/* Turn keys: the in-game rotate indicator keys (white sprites tinted like render.js does). */
/* Wide keys: turn (game), space and delete (Alphabet). */
.key.wide { flex-basis: calc(var(--unit) * 1.5 + 2.5px); padding: 0; background: rgba(44, 44, 44, 0.07); }
.key.wide.down { background: rgba(44, 44, 44, 0.25); }
.key-word { font-size: 17px; padding-top: 2px; }
.key svg { width: 27px; height: 18px; }
.key.turn { position: relative; }
.key.turn.glow { background: rgba(44, 44, 44, 0.16); }
/* Sprite boxes from render.js INDICATOR (key 6.263 x 6.368 u, its back offset by 0.97, -0.63 u), at 5.75 px/u. */
.turn-icon { position: relative; width: 36px; height: 36.6px; }
.key.turn.right .turn-icon { transform: scaleX(-1); }
.turn-key, .turn-back { position: absolute; -webkit-mask: center / contain no-repeat; mask: center / contain no-repeat; }
.turn-key { inset: 0; background: var(--ink); -webkit-mask-image: url("assets/ui/rotateIndicator.png"); mask-image: url("assets/ui/rotateIndicator.png"); }
.turn-back { left: 11.9px; top: 0.1px; width: 23.4px; height: 29.1px; background: #fef9f3;
  -webkit-mask-image: url("assets/ui/rotateBack.png"); mask-image: url("assets/ui/rotateBack.png"); }
/* While a letter is dragged the keyboard is where it goes to be removed. */
.kb-drop {
  position: absolute; inset: 6px 0 10px;
  display: grid; place-items: center;
  border: 1.5px dashed rgba(44, 44, 44, 0.45);
  border-radius: 12px;
  font-size: 22px; color: var(--quiet);
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s, background-color 0.15s;
}
.keyboard.drop .key { opacity: 0; }
.keyboard.drop .kb-drop { opacity: 1; }
.keyboard.over .kb-drop { background: rgba(240, 104, 103, 0.14); border-color: #d44b4a; color: #b8302f; }

.touch-ui .days { grid-template-columns: repeat(2, 1fr); gap: 10px; }
.touch-ui .day canvas { height: 104px; }
.touch-ui .stats-row { gap: 6px; justify-content: space-around; margin-bottom: 18px; }
.touch-ui .stat { min-width: 0; }
.touch-ui .stat b { font-size: 32px; }
.touch-ui .stat span { font-size: 14px; }
.touch-ui .tiles { grid-template-columns: 1fr; }

/* Alphabet on the phone: the keys come up when the preview line is tapped. */
.touch-ui #alphabet:not(.typing) .ab-keys { display: none; }
.touch-ui .ab-sheet, .touch-ui .ab-detail { padding: 0 4px; }
.touch-ui .ab-preview { margin-bottom: 30px; }
.touch-ui .ab-row { margin-bottom: 20px; }
.touch-ui .ab-detail { gap: 16px 0; }

/* Phone held sideways: little height, so a slimmer header and keyboard. */
@media (max-height: 500px) {
  .touch-ui #game .logo { display: none; }
  .touch-ui .bar { padding-top: 6px; }
  .touch-ui .keyboard { gap: 5px; padding: 4px 0 6px; }
  .touch-ui .key { height: 36px; font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  .screen.active, .win-logo, .win .stats, .win .par, .win-buttons, .next-in, .streak, #game .hint.change, .key.glow, .ab-caret { animation: none; }
}
