/* Look "A · Χαρτί" (D-019): warm paper, deep-blue ink, crayon highlight, Playpen Sans. */

/* Playpen Sans (OFL, fonts/OFL.txt) — variable 400–700, self-hosted so it works offline.
   Subsets and unicode-ranges as served by Google Fonts. */
@font-face {
  font-family: 'Playpen Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url(../fonts/playpen-sans-greek.woff2) format('woff2');
  unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF;
}
@font-face {
  font-family: 'Playpen Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url(../fonts/playpen-sans-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --paper: #fff3e4;
  --grain: rgba(46, 53, 97, .07);   /* faint dot grain on the paper */
  --card: #fffaf3;
  --ink: #2e3561;                    /* deep blue instead of black */
  --ink-soft: #8a8fb0;
  --hl: #ffd75e;                     /* the word being spoken: crayon stroke */
  --mark: #cde4fb;                   /* words marked by a drag */
  --btn: #ef7a61;                    /* play button */
  --btn-ink: #fff6ec;
  --btn-deep: #c95c45;
  --btn-edge: #2e3561;               /* its hand-drawn outline */
  --font: 'Playpen Sans', 'Comic Sans MS', system-ui, sans-serif;
  --text-size: 1.72rem;
  --line: 2.25;
  --hold-ms: 1000ms;                 /* hold the house this long to leave a story */
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

html { background: var(--paper); }
body {
  margin: 0; min-height: 100dvh; color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(circle at 1px 1px, var(--grain) 1px, transparent 1.5px);
  background-size: 14px 14px;
}
button { font: inherit; color: inherit; }

.error { padding: 1rem; color: #a3321c; font-size: 1.25rem; }

/* ── Story list: a grid of square cards. 9.5rem minimum → 2 columns on every common phone width
   (360–430 CSS px), more on tablets/desktop. auto-fill keeps card size stable with few stories. */
.story-list {
  list-style: none; margin: 0;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
           max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(9.5rem, 100%), 1fr));
}
.story-list a {
  aspect-ratio: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.75rem; box-sizing: border-box;
  font-size: 1.3rem; font-weight: 500; text-align: center; color: inherit; text-decoration: none;
  background: var(--card); border-radius: 1.25rem;
  box-shadow: 0 4px 0 rgba(46, 53, 97, .12);
  transition: transform .08s, box-shadow .08s;
}
.story-list a:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(46, 53, 97, .12); }
.story-list .icon { font-size: 4rem; line-height: 1; }
.story-list img.icon { width: 5rem; height: 5rem; }

/* ── Reader: one screen — top bar, scrolling text, play button. ─────────────────────────── */
story-reader {
  position: relative; box-sizing: border-box;
  height: 100dvh; display: grid;
  grid-template-areas: "top" "text" "bottom";
  grid-template-rows: auto 1fr auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.reader-top {
  grid-area: top; display: grid; grid-template-columns: 3.5rem 1fr 3.5rem; align-items: center;
  padding: 10px 12px 4px;
}
.reader-title {
  margin: 0; text-align: center; font-size: 1.15rem; font-weight: 700;
  color: var(--ink-soft); text-wrap: balance;
}
.reader-title .icon { margin-right: .3em; }
.reader-title img.icon { width: 1.3em; height: 1.3em; vertical-align: -.25em; }

.reader-scroll {
  grid-area: text; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 16px 16px;
}
.story-text {
  max-width: 40rem; margin: 0 auto;
  font-size: var(--text-size); line-height: var(--line);
  touch-action: pan-y;           /* up/down scrolls; sideways drags mark words (D-017, D-019) */
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  cursor: pointer;
}
.story-text p { margin: 0 0 .9em; }

.w { border-radius: .28em; padding: .04em .06em; margin: 0 -.06em; transition: background-color .12s, box-shadow .12s; }
.w.marked { background: var(--mark); box-shadow: .16em 0 0 var(--mark), -.16em 0 0 var(--mark); } /* shadows bridge the spaces */
.w.on {
  background: linear-gradient(100deg, transparent 0 2%, var(--hl) 5% 95%, transparent 98%);
  border-radius: .45em .2em .5em .25em; box-shadow: none;
}

.reader-bottom { grid-area: bottom; display: flex; justify-content: center; align-items: center; padding: 10px 16px 22px; }

/* Play: a coral disc with a hand-drawn outline that turns while the story plays. */
.play {
  position: relative; width: 5.6rem; height: 5.6rem; padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: var(--btn); color: var(--btn-ink);
  box-shadow: 0 4px 0 var(--btn-deep);
  touch-action: manipulation;
  transition: transform .08s, box-shadow .08s, opacity .2s;
}
.play:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--btn-deep); }
.play:disabled { opacity: .45; }
.play:focus-visible { outline: 3px solid var(--ink); outline-offset: 8px; }
.play .icon { width: 46%; height: 46%; position: relative; }
.play .i-pause, .play.playing .i-play { display: none; }
.play.playing .i-pause { display: block; }
.play .outline {
  position: absolute; inset: -9px; pointer-events: none;
  border: 3px solid var(--btn-edge); opacity: .75;
  border-radius: 47% 53% 44% 56% / 52% 45% 55% 48%;
}
.play.playing .outline { animation: spin 5s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Leave the story: a quiet house, top-left. Hold it (--hold-ms) — a ring fills; a tap only wiggles it. */
.exit {
  position: relative; width: 3.25rem; height: 3.25rem; padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: transparent; color: var(--ink-soft); opacity: .75;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.exit:focus-visible { outline: 2px solid var(--ink); }
.exit .house { width: 1.55rem; height: 1.55rem; }
.exit .ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.exit .ring circle {
  fill: none; stroke: var(--btn); stroke-width: 3.5; stroke-linecap: round;
  stroke-dasharray: 144.5; stroke-dashoffset: 144.5;   /* 2π·23 */
}
.exit.holding .ring circle { stroke-dashoffset: 0; transition: stroke-dashoffset var(--hold-ms) linear; }
.exit.wiggle { animation: wiggle .4s; }
@keyframes wiggle { 25% { transform: rotate(-10deg); } 75% { transform: rotate(10deg); } }

.hint {
  position: absolute; z-index: 5; top: calc(env(safe-area-inset-top) + 3.9rem); left: calc(env(safe-area-inset-left) + 12px);
  padding: .45rem .75rem; border-radius: .7rem;
  background: var(--ink); color: var(--paper); font-size: .95rem;
  opacity: 0; transform: translateY(-4px); transition: opacity .2s, transform .2s; pointer-events: none;
}
.hint.show { opacity: 1; transform: none; }

/* Landscape phones: play moves to the right edge. */
@media (orientation: landscape) and (max-height: 540px) {
  story-reader {
    grid-template-areas: "top top" "text bottom";
    grid-template-columns: 1fr auto; grid-template-rows: auto 1fr;
  }
  .reader-top { padding-top: 4px; }
  .reader-bottom { padding: 0 20px 12px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .play.playing .outline, .exit.wiggle { animation: none; }
}
