/* =========================================================================
   Theme "quaderno": a pencil drawing in an old school notebook. Wobbly hand-drawn outlines traced twice,
   colored-pencil hatching on the attempt rows. Handwriting (Caveat) for the titles and the badge;
   the rest in the rounded face of the other themes (Fredoka), at their sizes.
   Layered on style.css (loaded only while the theme is active, see theme.js).
   ========================================================================= */

/* Both faces are bundled with the app (shared with the other themes): they work offline */
@font-face {
    font-family: 'Caveat';
    font-weight: 600 700;
    font-display: swap;
    src: url('../fonts/caveat-latin.woff2') format('woff2');
}

@font-face {
    font-family: 'Fredoka';
    font-weight: 400 700;
    font-display: swap;
    src: url('../fonts/fredoka-latin.woff2') format('woff2');
}

:root {
    /* Palette: graphite on paper */
    --ink: #2b2b2b;
    /* AIUTI menu's header: the yellow highlighter of TENTA */
    --help-head: #fde047;
    --help-head-ink: var(--ink);
    --ink-soft: #4a4a4a;
    --ink-muted: #7a7a7a;
    --line: #2b2b2b;
    --line-soft: #2b2b2b;
    /* Aged paper: ivory turning yellow, darker toward the edges (see .page) */
    --surface: #faf5e8;
    --surface-alt: #f5eedd;
    --surface-sunk: #e4dcc8;
    --win-bg: #e3f1dc;
    --win-line: #2f855a;
    /* Closeness scale in colored pencils, red (far) to green (close), in the same three bands as the
       badge levels (see --closeness-scale in style.css). Light tones: the text on the rows is dark
       graphite here, laid straight on the flat fill. */
    --closeness-scale: #ec9d99 0%, #eea796 44%, #f1b994 46%, #efcf97 84%, #bfdea7 86%, #a1d5a3 100%;
    --reveal-won: #86c98a;
    /* Export "copied" check: the reveal green is too pale for a thin stroke on paper */
    --copy-ok: #2e7d32;
    /* Diamond marker of the rows and of the revealed word: graphite like the text */
    --row-marker: #2b2b2b;
    /* Warnings in red pen */
    --alert: #c0392b;
    /* Paper-colored halo around graphite text: keeps it readable over the hatching */
    --qd-halo: 1px 0 0 #faf5e8, -1px 0 0 #faf5e8, 0 1px 0 #faf5e8, 0 -1px 0 #faf5e8,
               1px 1px 0 #faf5e8, -1px -1px 0 #faf5e8, 1px -1px 0 #faf5e8, -1px 1px 0 #faf5e8;
    --reveal-surrendered: #c9c6bd;
    /* Pencil hatching laid over a fill (paper-colored stripes let the fill show as strokes) */
    --qd-hatch: repeating-linear-gradient(-45deg, rgba(250, 245, 232, 0.55) 0 3px, transparent 3px 7px);
    /* Hand-drawn outline: uneven corners, then a second fainter trace slightly off the first */
    --qd-wobbly: 255px 15px 225px 15px / 15px 225px 15px 255px;
    --qd-wobbly-alt: 15px 225px 15px 255px / 225px 15px 255px 15px;
    --qd-retrace: 2px 3px 0 -1px rgba(43, 43, 43, 0.45);

    /* Typography: handwriting for everything */
    --font-ui: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
    --font-mono: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
    /* Handwriting, kept for the titles and the badge */
    --qd-font-hand: 'Caveat', 'Segoe Print', 'Bradley Hand', cursive;

    --r-sm: 12px;
    --r-md: 12px;
    --r-lg: 18px;
}

html,
body {
    background: var(--surface-sunk);
}

/* ---------- Card: a sheet of paper outlined in pencil, traced twice ---------- */
.page {
    position: relative;
    /* Ruled sheet: a faint blue line every 32px starting below the top edge, no red margin line */
    /* No coffee stains: on a phone there is no free corner, and they sat under the theme picker
       and the footer text. The paper grain below gives the sheet its used look instead. */
    background:
        repeating-linear-gradient(transparent 0 31px, rgba(120, 160, 210, 0.35) 31px 32px) 0 20px,
        /* Ageing, uneven like real paper: a few brown foxing spots, a faint fold across the sheet,
           one corner yellowed more than the other, edges darker than the middle */
        radial-gradient(circle at 78% 31%, rgba(140, 95, 40, 0.22) 0 2px, transparent 5px),
        radial-gradient(circle at 23% 58%, rgba(140, 95, 40, 0.16) 0 3px, transparent 7px),
        radial-gradient(circle at 64% 82%, rgba(140, 95, 40, 0.18) 0 1.5px, transparent 4px),
        radial-gradient(circle at 88% 67%, rgba(140, 95, 40, 0.12) 0 4px, transparent 9px),
        radial-gradient(circle at 35% 12%, rgba(140, 95, 40, 0.14) 0 2px, transparent 5px),
        linear-gradient(176deg, transparent 47.6%, rgba(255, 255, 255, 0.45) 47.9%, rgba(130, 95, 40, 0.12) 48.3%, transparent 48.8%),
        radial-gradient(ellipse at 100% 0%, rgba(175, 125, 45, 0.14), transparent 55%),
        radial-gradient(ellipse at 0% 100%, rgba(175, 125, 45, 0.09), transparent 50%),
        radial-gradient(ellipse at 45% 45%, transparent 50%, rgba(160, 115, 45, 0.10) 100%),
        /* Paper grain: faint warm noise, so the sheet is not a flat screen color */
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.3 0 0 0 0 0.22 0 0 0 0.09 0'/></filter><rect width='180' height='180' filter='url(%23g)'/></svg>") 0 0 / 180px 180px,
        var(--surface);
    border: 2px solid var(--ink);
    border-radius: var(--qd-wobbly);
    box-shadow: 3px 4px 0 -1px rgba(43, 43, 43, 0.35);
}

/* Second, fainter pencil trace of the outline, a little crooked.
   Drawn just inside the card: .page clips anything sticking out sideways. */
.page::before {
    content: "";
    position: absolute;
    inset: 4px 3px 3px 5px;
    border: 1px solid rgba(43, 43, 43, 0.4);
    border-radius: var(--qd-wobbly-alt);
    transform: rotate(-0.4deg);
    pointer-events: none;
}

/* Logo as a sticker stuck on the sheet: white die-cut edge (drop-shadows with no blur, pushed
   in eight directions, follow the drawing's shape), a soft shadow under it (upright, as in every theme) */
.logo {
    filter:
        drop-shadow(3px 0 0 #fff) drop-shadow(-3px 0 0 #fff)
        drop-shadow(0 3px 0 #fff) drop-shadow(0 -3px 0 #fff)
        drop-shadow(2px 2px 0 #fff) drop-shadow(-2px -2px 0 #fff)
        drop-shadow(2px -2px 0 #fff) drop-shadow(-2px 2px 0 #fff)
        drop-shadow(1px 3px 3px rgba(0, 0, 0, 0.3));
}

.tagline {
    font-style: normal;
    color: var(--ink-soft);
}

/* Wavy pencil line instead of the straight rule */
.rule {
    height: 8px;
    border: none;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='8'><path d='M0 4 Q15 1 30 4 T60 4 T90 5 T120 4' fill='none' stroke='%232b2b2b' stroke-width='1.6' stroke-linecap='round' opacity='0.75'/></svg>") repeat-x center;
}

/* Handwritten titles: bigger, handwriting reads small */
.start-option-title,
.history-title {
    font-family: var(--qd-font-hand);
    font-size: 22px;
    letter-spacing: 0.02em;
    text-transform: none;
}

.start-option {
    background: transparent;
    border: 2px solid var(--ink);
    border-radius: var(--qd-wobbly-alt);
    box-shadow: var(--qd-retrace);
}

/* ---------- Buttons: hand-drawn outlines, a highlighter swipe on hover ---------- */
button,
select {
    border: 2px solid var(--ink);
    border-radius: var(--qd-wobbly);
    background-color: transparent;
    letter-spacing: 0.02em;
}

button {
    text-transform: none;
    box-shadow: var(--qd-retrace);
}


button:hover:not(:disabled) {
    background: #fff59d;
    color: var(--ink);
    transform: rotate(-1.5deg);
    box-shadow: var(--qd-retrace);
}

button:disabled {
    background: transparent;
    border-color: var(--ink-muted);
    border-style: dashed;
}

/* Primary actions: a stroke of yellow highlighter across the word, over light pencil hatching
   (no solid fill in a pencil drawing); on hover the highlighter covers the whole button */
#submit-guess,
#new-game,
#import-confirm,
#confirm-ok,
#hints-close {
    background:
        linear-gradient(transparent 42%, rgba(253, 224, 71, 0.9) 42% 82%, transparent 82%),
        repeating-linear-gradient(-45deg, rgba(43, 43, 43, 0.12) 0 2px, transparent 2px 6px);
    color: var(--ink);
}

#submit-guess:hover:not(:disabled),
#new-game:hover:not(:disabled),
#import-confirm:hover:not(:disabled),
#confirm-ok:hover:not(:disabled),
#hints-close:hover:not(:disabled) {
    background:
        repeating-linear-gradient(-45deg, rgba(43, 43, 43, 0.12) 0 2px, transparent 2px 6px),
        #fde047;
}

#submit-guess:disabled {
    background: transparent;
}

/* ---------- Fields and attempt rows ---------- */
.word-input {
    border: 2px solid var(--ink);
    border-radius: var(--qd-wobbly);
    box-shadow: var(--qd-retrace);
}

/* Every other row bends the other way, so the stack does not look stamped */
.board-stack > :nth-child(even) .word-input,
.board-stack > .word-input:nth-child(even) {
    border-radius: var(--qd-wobbly-alt);
}

/* Attempt rows: a stroke of highlighter in the closeness color (no hatching: the stripes fought with
   the letters), graphite text and marker (see .word-input.bound in style.css). No pencil outline:
   uneven ends like a marker's, and the ink sinks into the paper (multiply), its grain showing through. */
.word-input.bound {
    color: var(--ink);
    text-shadow: none;
    border: none;
    box-shadow: none;
    border-radius: 6px 16px 8px 18px / 14px 6px 16px 8px;
    mix-blend-mode: multiply;
    padding-left: 36px;
}

/* Every other stroke drawn the other way round */
.board-stack > :nth-child(even) .word-input.bound,
.board-stack > .word-input.bound:nth-child(even) {
    border-radius: 16px 6px 18px 8px / 6px 14px 8px 16px;
}

/* Graphite on a light fill keeps its contrast: the letters past the shared prefix can fade more */
.word-input.bound {
    --word-rest-opacity: 0.6;
}

/* The METÀ help's word (style.css): graphite letters like the other strokes, the light gold ones
   would vanish on the highlighter */
.word-input.bound.help-word {
    color: var(--ink);
    text-shadow: none;
}

/* Rows without the hint: a gray highlighter, dark enough to show on the paper without an outline */
.word-input.bound.no-closeness,
.word-input.bound.imported {
    --row-plain-bg: #dcd3bf;
    /* No outline here either (style.css draws one around the plain rows of the other themes) */
    border: none;
    box-shadow: none;
}

/* Guess row: dashed outline, to be filled in; a highlighter mark while typing */
.word-input.guess {
    background: transparent;
    border-style: dashed;
}

.word-input.guess:focus {
    border-style: solid;
    transform: none;
    box-shadow: var(--qd-retrace);
    background: linear-gradient(transparent 62%, rgba(253, 224, 71, 0.55) 62%);
}

.word-input.guess.won,
.word-input.guess.won:disabled {
    background: var(--qd-hatch), var(--win-bg);
}

/* Game codes stay in a typewriter font: they are random letters, handwriting would confuse them */
.code-input {
    font-family: 'Courier New', ui-monospace, monospace;
    border: 2px solid var(--ink);
    border-radius: var(--qd-wobbly-alt);
    background: transparent;
}

.code-input:focus,
select:focus {
    box-shadow: var(--qd-retrace);
}

/* ---------- Revealed secret: a note taped onto the sheet ----------
   Plain paper, no hatching (its stripes ran through the letters of the definition),
   held by two strips of tape across the top corners. A win gets a pale green note. */
.dict-entry {
    position: relative;
    color: var(--ink);
    text-shadow: none;
    border: 2px solid var(--ink);
    border-radius: var(--qd-wobbly-alt);
    /* A fresher sheet than the yellowed page: it was taped on later */
    background: #fffaea;
    box-shadow: var(--qd-retrace), 2px 4px 8px rgba(0, 0, 0, 0.08);
    transform: rotate(-0.5deg);
}

.dict-entry.won {
    background: #e8f4e1;
}

/* Two strips of semi-transparent tape over the top corners */
.dict-entry::before,
.dict-entry::after {
    content: "";
    position: absolute;
    top: -12px;
    width: 76px;
    height: 24px;
    background: rgba(226, 214, 176, 0.75);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
    pointer-events: none;
}

.dict-entry::before {
    left: -14px;
    transform: rotate(-32deg);
}

.dict-entry::after {
    right: -14px;
    transform: rotate(30deg);
}

/* A win: the found word circled in red pen, with a star scribbled beside it */
.dict-entry.won .dict-word {
    display: inline-block;
    padding: 2px 22px 6px 14px;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 60' preserveAspectRatio='none'><path d='M30 8 C80 -2 170 2 192 22 C206 40 160 56 100 56 C40 57 4 48 6 30 C8 14 40 6 88 6' fill='none' stroke='%23c0392b' stroke-width='3' stroke-linecap='round' vector-effect='non-scaling-stroke'/></svg>") center / 100% 100% no-repeat;
}

.dict-entry.won .dict-head::after {
    content: "";
    display: inline-block;
    width: 30px;
    height: 30px;
    margin-left: 8px;
    vertical-align: top;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'><path d='M20 3 L24.5 15 L37 15.5 L27 23.5 L30.5 36 L20 28.5 L9.5 36 L13 23.5 L3 15.5 L15.5 15 Z' fill='none' stroke='%23c0392b' stroke-width='2.2' stroke-linejoin='round'/></svg>") center / contain no-repeat;
    transform: rotate(12deg);
}

/* ---------- History, banner, popup ---------- */
.history-list li {
    background: transparent;
}

.history-list li::before {
    content: "-";
    width: auto;
    height: auto;
    background: none;
    color: var(--ink);
}

/* Banner: a sticky note, slightly crooked */
.banner {
    background: #fff59d;
    border: none;
    border-radius: 2px;
    transform: rotate(-0.6deg);
    box-shadow: 2px 3px 6px rgba(0, 0, 0, 0.15);
}

.banner.error {
    background: #ffd6d1;
}

.import-dialog {
    border: 2px solid var(--ink);
    border-radius: var(--qd-wobbly);
}

.import-dialog::backdrop {
    background: rgba(43, 43, 43, 0.35);
}

.dialog-title {
    font-family: var(--qd-font-hand);
    font-size: 30px;
}

/* ---------- Closeness badge: a teacher's pen remark ---------- */
.closeness-badge {
    --slant: translateY(-50%) rotate(-8deg);
    font-family: var(--qd-font-hand);
    font-style: normal;
    font-weight: 700;
    font-size: 38px;
    text-transform: none;
    letter-spacing: 0;
}

/* Paper-colored outline: keeps the pen strokes readable over the hatching */
.closeness-badge .closeness-letter {
    -webkit-text-stroke: 5px var(--edge);
    text-shadow: none;
}

/* Dark ink pen colors matching the closeness scale of the rows: bordeaux (far), burnt orange (near),
   forest green (very near and found) */
.closeness-badge.far   { --fill: #7f1717; --edge: #faf5e8; }
.closeness-badge.near  { --fill: #8c3f04; --edge: #faf5e8; }
.closeness-badge.close,
.closeness-badge.won   { --fill: #154f33; --edge: #faf5e8; }

/* ---------- Board frame (abaco / zuzzurellone): wavy pencil line like the page rule ---------- */
.dict-edge {
    letter-spacing: 0.08em;
    /* Lined up with the rows' words: 36px padding + 2px pencil border */
    --edge-indent: 38px;
}

.dict-edge::before,
.dict-edge::after {
    height: 8px;
    border: none;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='8'><path d='M0 4 Q15 1 30 4 T60 4 T90 5 T120 4' fill='none' stroke='%232b2b2b' stroke-width='1.6' stroke-linecap='round' opacity='0.75'/></svg>") repeat-x center;
}

/* Narrow screens: rows' padding drops to 32px (+ 2px border). After the rule above, so it wins */
@media (max-width: 640px) {
    .dict-edge {
        --edge-indent: 34px;
    }
}

/* ---------- Custom game panel: pencil-drawn controls ---------- */
/* Hint switch: a pill traced in pencil with a hatched knob; on = a highlighter swipe inside */
.start-option .custom-field .toggle {
    width: 54px;
    height: 30px;
    border: 2px solid var(--ink);
    border-radius: var(--qd-wobbly);
    background: transparent;
    box-shadow: var(--qd-retrace);
}

/* Knob: an empty pencil circle marked with a cross when off, a tick when on: the state reads
   from the mark itself, not only from the highlighter */
.toggle::before {
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border: 2px solid var(--ink);
    box-sizing: border-box;
    background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path d='M6 6 L14 14 M14 6 L6 14' stroke='%232b2b2b' stroke-width='2.2' stroke-linecap='round'/></svg>") center / 12px 12px no-repeat;
}

.start-option .custom-field .toggle:checked {
    background: #fde047;
    border-color: var(--ink);
}

.toggle:checked::before {
    transform: translateX(24px);
    background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path d='M4 10.5 L8.5 15 L16 5' fill='none' stroke='%232b2b2b' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/></svg>") center / 13px 13px no-repeat;
}

/* Attempts stepper: hand-drawn - and + boxes, the count written big in between */
.start-option .attempts-stepper .step-btn {
    min-width: 40px;
    height: 36px;
    font-size: 20px;
    line-height: 1;
}

/* ---------- Notebook touches ---------- */
/* Card titles underlined with a quick wavy pencil stroke */
.start-option-title {
    padding-bottom: 6px;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='8'><path d='M2 5 Q20 1 40 5 T80 4 T120 5 T158 3' fill='none' stroke='%232b2b2b' stroke-width='1.8' stroke-linecap='round' opacity='0.7'/></svg>") no-repeat left bottom / 160px 8px;
}

/* A little pencil doodled at the right end of the guess field, where the next word gets written */
.word-input.guess {
    padding-right: 52px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='34' height='34' viewBox='0 0 34 34' fill='none' stroke='%232b2b2b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M7 27 L9 20 L24 5 L29 10 L14 25 Z'/><path d='M21 8 L26 13'/><path d='M9 20 L14 25'/><path d='M7 27 L11 26'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 30px 30px;
}

/* While typing, the highlighter band of the focus rule stays and the pencil stays beside it */
.word-input.guess:focus {
    background-image:
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='34' height='34' viewBox='0 0 34 34' fill='none' stroke='%232b2b2b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M7 27 L9 20 L24 5 L29 10 L14 25 Z'/><path d='M21 8 L26 13'/><path d='M9 20 L14 25'/><path d='M7 27 L11 26'/></svg>"),
        linear-gradient(transparent 62%, rgba(253, 224, 71, 0.55) 62%);
    background-repeat: no-repeat, no-repeat;
    background-position: right 12px center, 0 0;
    background-size: 30px 30px, 100% 100%;
}

/* ---------- Pencil marks in place of the shared shapes ---------- */
/* Pickers: a "v" drawn in pencil instead of the two neat triangles */
select {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 10'><path d='M1.5 2 C4 4.5 5.5 6.5 7 8.5 C8.5 6 10.5 3.5 12.5 1.5' fill='none' stroke='%232b2b2b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-position: right 10px center;
    background-size: 14px 10px;
}


