/* Mam's Block Puzzle: a wooden board and chunky wooden blocks, big buttons and big writing, for a phone held upright
   or an iPad on its side. As in Dadtris, the board and the pieces are drawn by three.js on the #view canvas laid over
   the page; #board-slot and the .tray-slot boxes only mark where (render/scene.js reads their positions). Each look
   is a body class setting the colours below (js/looks.js has the matching board and block colours). */

:root {
    --font: "Trebuchet MS", "Segoe UI", Roboto, Arial, sans-serif;
    --title-font: Georgia, "Times New Roman", serif;
    --bg: #6b4424;
    --bg-deep: #4a2c14;
    --ink: #fff7e6;
    --muted: #f1d9b0;
    --panel: rgba(40, 20, 6, 0.35);
    --panel-edge: #c99a5b;
    --btn: linear-gradient(#a8743f, #8a5a2b);
    --btn-ink: #fff7e6;
    --btn-edge: #4a2c14;
    --btn-down: #b98450;
    --primary: linear-gradient(#5fb35a, #3f8f3b);
    --primary-ink: #fff;
    --primary-edge: #23561f;
    --gold: #f2b632;
    --gold-ink: #3a2400;
    --gold-edge: #8a5f00;
    --hi: #ffd60a;
    --hi-ink: #1a1300;
    --hi-edge: #8a6d00;
    --overlay: rgba(40, 22, 8, 0.86);
    --radius: 16px;
    --top-h: 76px;
    --vw: 1vw; /* (js/fit.js: see #ui) */
    --vh: 1vh;
}
body.look-walnut {
    --bg: #3b2416;
    --bg-deep: #24150b;
    --panel-edge: #9c6a3c;
    --btn: linear-gradient(#7a4d2b, #5e3a1f);
    --btn-down: #8c5d37;
    --overlay: rgba(20, 11, 5, 0.88);
}
body.look-contrast {
    --font: Verdana, "Segoe UI", Arial, sans-serif;
    --bg: #000;
    --bg-deep: #000;
    --ink: #fff;
    --muted: #fff;
    --panel: #000;
    --panel-edge: #fff;
    --btn: #000;
    --btn-ink: #fff;
    --btn-edge: #fff;
    --btn-down: #444;
    --primary: #ffe600;
    --primary-ink: #000;
    --primary-edge: #fff;
    --hi: #ff9100;
    --hi-ink: #000;
    --hi-edge: #fff;
    --overlay: rgba(0, 0, 0, 0.92);
}

* {
    box-sizing: border-box;
}
html {
    -webkit-text-size-adjust: 100%; /* (the phone's own text size is left to js/fit.js, not boosted here and there) */
    text-size-adjust: 100%;
}
html,
body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}
body {
    /* planks */
    background:
        repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.12) 0 2px, transparent 2px 96px),
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.025) 0 3px, transparent 3px 11px),
        linear-gradient(var(--bg), var(--bg-deep));
    background-color: var(--bg-deep);
    color: var(--ink);
    font-family: var(--font);
    font-weight: 700;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
body.look-contrast {
    background: #000;
}
button {
    font: inherit;
    color: inherit;
    cursor: pointer;
    touch-action: manipulation;
}
svg {
    fill: currentColor;
}
[hidden] {
    display: none !important;
}

/* everything on the page (index.html #ui), scaled down as one by js/fit.js when the page is smaller than the game is
   laid out for. Inside it, sizes that follow the page use var(--vw) / var(--vh): fit.js sets them to the laid-out
   page's 1vw and 1vh (a transform leaves vw and vh at the real page's). */
#ui {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    transform-origin: 0 0;
    background: inherit;
}

/* ---- top bar ---- */
#topbar {
    position: fixed;
    top: env(safe-area-inset-top);
    left: env(safe-area-inset-left);
    right: env(safe-area-inset-right);
    height: var(--top-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    gap: 8px;
    z-index: 60;
}
body.screen-open #hud,
body.screen-open #btn-pause,
body:not(.playing) .in-game {
    visibility: hidden;
}
.icon-btn {
    width: 72px;
    height: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: var(--btn);
    color: var(--btn-ink);
    border: 3px solid var(--btn-edge);
    border-radius: 12px;
    padding: 4px;
}
.icon-btn svg {
    width: 30px;
    height: 30px;
}
.icon-btn .lbl {
    font-size: 11px;
    line-height: 1;
    white-space: nowrap;
    font-family: Arial, sans-serif;
}
.icon-btn:active {
    background: var(--btn-down);
}
#hud {
    flex: 1;
    text-align: center;
    line-height: 1.05;
}
#hud-score {
    font-size: clamp(32px, 10 * var(--vw), 46px);
    font-variant-numeric: tabular-nums;
    text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
#hud-best {
    font-size: 15px;
    color: var(--muted);
}

/* ---- the play area: goal, board, the three pieces, the helpers ---- */
#app {
    position: fixed;
    inset: 0;
    padding: calc(env(safe-area-inset-top) + var(--top-h)) env(safe-area-inset-right) env(safe-area-inset-bottom)
        env(safe-area-inset-left);
}
#play {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 4px 12px 12px;
}
#goal {
    width: 100%;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 19px;
    text-align: center;
}
#goal-text {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 14px;
}
#goal-text .gem {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-variant-numeric: tabular-nums;
}
#goal-text .gem i {
    width: 22px;
    height: 22px;
    display: inline-block;
    border-radius: 6px;
}
#goal-text .gem.done {
    opacity: 0.55;
    text-decoration: line-through;
}
#goal-bar {
    height: 14px;
    border-radius: 7px;
    background: var(--panel);
    border: 2px solid var(--panel-edge);
    overflow: hidden;
}
#goal-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #7fd36b, #3f8f3b);
    transition: width 0.3s;
}
#board-slot {
    flex: none;
    touch-action: none;
}
#tray {
    flex: 1;
    width: 100%;
    max-width: 560px;
    min-height: 0;
    display: flex;
    gap: 8px;
}
.tray-slot {
    flex: 1;
    min-height: 90px;
    background: var(--panel);
    border: 3px solid transparent;
    border-radius: var(--radius);
    padding: 0;
    touch-action: none;
}
.tray-slot.selected {
    border-color: var(--hi);
    box-shadow: 0 0 0 3px rgba(255, 214, 10, 0.35);
}
#helpers {
    flex: none;
    width: 100%;
    max-width: 560px;
    display: flex;
    gap: 8px;
}
.helper {
    flex: 1;
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--btn);
    color: var(--btn-ink);
    border: 3px solid var(--btn-edge);
    border-radius: 14px;
    box-shadow: 0 4px 0 var(--btn-edge);
    font-size: 17px;
    padding: 4px 6px;
    position: relative;
    min-width: 0;
}
.helper span {
    min-width: 0;
    overflow: hidden; /* (big writing stays inside its own button, so a press there is that button's) */
}
.helper svg {
    width: 26px;
    height: 26px;
    flex: none;
}
.helper b {
    position: absolute;
    top: -10px;
    right: -6px;
    min-width: 28px;
    height: 28px;
    border-radius: 14px;
    background: var(--gold);
    color: var(--gold-ink);
    border: 2px solid var(--gold-edge);
    font-size: 16px;
    line-height: 24px;
    text-align: center;
}
.helper:disabled {
    opacity: 0.45;
}
.helper:active:not(:disabled) {
    transform: translateY(3px);
    box-shadow: 0 1px 0 var(--btn-edge);
}
/* the iPad (or any wide screen): board on the left, everything else beside it */
body.wide #play {
    display: grid;
    grid-template-columns: auto minmax(260px, 420px);
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "board goal" "board tray" "board helpers";
    justify-content: center;
    align-items: stretch;
    column-gap: 28px;
    row-gap: 14px;
}
body.wide #board-slot {
    grid-area: board;
    align-self: center;
}
body.wide #goal {
    grid-area: goal;
}
body.wide #tray {
    grid-area: tray;
    flex-direction: column;
}
body.wide #helpers {
    grid-area: helpers;
}

#view {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    pointer-events: none;
}
#banner {
    position: fixed;
    left: 0;
    right: 0;
    top: 34%;
    text-align: center;
    z-index: 40;
    font-family: var(--title-font);
    font-size: clamp(36px, 11 * var(--vw), 64px);
    color: #fff3c4;
    pointer-events: none;
    text-shadow:
        0 4px 0 #6b3a12,
        0 0 20px rgba(0, 0, 0, 0.45);
    animation: pop 1.2s ease-out forwards;
}
@keyframes pop {
    0% {
        transform: scale(0.6);
        opacity: 0;
    }
    15% {
        transform: scale(1.12);
        opacity: 1;
    }
    30% {
        transform: scale(1);
    }
    80% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translateY(-24px);
    }
}
body.fx-simple #banner {
    animation: none;
}

/* ---- screens ---- */
.screen {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: none;
    flex-direction: column;
    align-items: center;
    padding: calc(env(safe-area-inset-top) + 78px) 16px calc(env(safe-area-inset-bottom) + 16px);
    background: inherit;
    background-color: var(--bg-deep);
    overflow-y: auto;
}
.screen.on {
    display: flex;
}
.screen.overlay {
    background: var(--overlay);
    justify-content: center;
}
.screen h2 {
    font-family: var(--title-font);
    font-size: clamp(32px, 9 * var(--vw), 44px);
    margin: 0 0 16px;
}
.screen-head {
    width: min(100%, 560px);
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 10px;
}
.screen-head h2 {
    margin: 0;
}
.hint {
    color: var(--muted);
    font-size: 18px;
    text-align: center;
    max-width: 420px;
    font-weight: 600;
}
.logo {
    font-family: var(--title-font);
    font-size: clamp(40px, 12 * var(--vw), 64px);
    line-height: 1;
    text-align: center;
    margin: 0 0 14px;
    color: #fff3c4;
    text-shadow: 0 4px 0 #6b3a12;
}
.logo span {
    font-size: 0.62em;
    color: #ffd98a;
}
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: min(90 * var(--vw), 440px);
}
.menu-row {
    display: flex;
    gap: 12px;
}
.menu-row .big {
    flex: 1;
}
.big,
.big-ish {
    min-height: 64px;
    font-size: clamp(22px, 6.5 * var(--vw), 28px);
    background: var(--btn);
    color: var(--btn-ink);
    border: 3px solid var(--btn-edge);
    border-radius: var(--radius);
    box-shadow: 0 5px 0 var(--btn-edge);
    padding: 8px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.big-ish {
    min-height: 58px;
    font-size: 21px;
    flex: none;
}
.big:active,
.big-ish:active {
    transform: translateY(4px);
    box-shadow: 0 1px 0 var(--btn-edge);
}
.big small {
    font-size: 15px;
    font-weight: 600;
    opacity: 0.85;
}
.big.primary {
    background: var(--primary);
    color: var(--primary-ink);
    border-color: var(--primary-edge);
    box-shadow: 0 5px 0 var(--primary-edge);
    min-height: 88px;
    font-size: clamp(32px, 9 * var(--vw), 40px);
}
.big.secondary {
    min-height: 74px;
    border-width: 4px;
}
.big.gold {
    background: var(--gold);
    color: var(--gold-ink);
    border-color: var(--gold-edge);
    box-shadow: 0 5px 0 var(--gold-edge);
}
.big:disabled {
    opacity: 0.45;
}
.big.fs-toggle,
#btn-fs.on {
    background: var(--hi);
    color: var(--hi-ink);
    border-color: var(--hi-edge);
}
.big.fs-toggle {
    flex-direction: row;
    gap: 12px;
    min-height: 74px;
    box-shadow:
        0 5px 0 var(--hi-edge),
        0 0 0 4px color-mix(in srgb, var(--hi) 35%, transparent);
}
.big.fs-toggle svg {
    width: 30px;
    height: 30px;
}
.fs-prompt {
    margin: 0 0 12px;
    min-height: 54px;
    font-size: 21px;
    background: transparent;
    border: 3px dashed var(--panel-edge);
    border-radius: var(--radius);
    padding: 8px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.fs-prompt svg {
    width: 28px;
    height: 28px;
}

/* game over / level won */
.over-score {
    font-size: clamp(54px, 16 * var(--vw), 84px);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}
.over-best {
    font-size: 28px;
    color: var(--gold);
    margin-top: 6px;
}
.over-detail {
    font-size: 20px;
    color: var(--muted);
    margin: 8px 0;
    text-align: center;
}
.stars {
    font-size: 54px;
    letter-spacing: 6px;
    color: var(--gold);
    text-shadow: 0 3px 0 #6b3a12;
}
#over-reward {
    text-align: center;
    margin: 8px 0;
    font-size: 20px;
}
#over-reward canvas {
    width: min(60 * var(--vw), 240px);
    height: auto;
    border-radius: 14px;
    border: 4px solid var(--panel-edge);
    display: block;
    margin: 8px auto;
}
#scr-over .menu-buttons {
    margin-top: 14px;
}

/* yes/no */
.dialog {
    z-index: 70;
}
.dialog .panel {
    width: min(90 * var(--vw), 440px);
    background: var(--btn);
    background-color: var(--bg);
    border: 3px solid var(--btn-edge);
    border-radius: var(--radius);
    padding: 22px 18px;
    text-align: center;
}
#dlg-text {
    font-size: 24px;
    margin: 0 0 18px;
    line-height: 1.3;
}
.dlg-buttons {
    display: flex;
    gap: 12px;
}
.dlg-buttons .big {
    flex: 1;
}
.dlg-buttons .big.primary {
    min-height: 72px;
    font-size: 28px;
}

/* settings */
#settings-body,
#stats-body,
#about-body,
#adventure-body,
#daily-body {
    width: min(100%, 560px);
}
#settings-body {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin: 6px 0 22px;
}
.set-row h3 {
    font-size: 21px;
    margin: 0 0 8px;
}
.set-row p {
    font-size: 16px;
    font-weight: 600;
    color: var(--muted);
    margin: 6px 0 0;
}
.seg {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.seg button {
    flex: 1 1 30%;
    min-height: 60px;
    font-size: 19px;
    background: var(--btn);
    color: var(--btn-ink);
    border: 3px solid var(--btn-edge);
    border-radius: 12px;
    padding: 6px 8px;
}
.seg button.on {
    background: var(--primary);
    color: var(--primary-ink);
    border-color: var(--primary-edge);
    outline: 3px solid var(--ink);
    outline-offset: 2px;
}
.seg button.on::before {
    content: "✓ ";
}
#scr-settings > .back {
    width: min(90 * var(--vw), 440px);
}

/* stats */
.stat-list div {
    display: flex;
    justify-content: space-between;
    font-size: 21px;
    padding: 12px 4px;
    border-bottom: 2px solid var(--panel-edge);
}
.stat-list span:last-child {
    font-variant-numeric: tabular-nums;
}

/* adventure map */
.chapter {
    margin: 14px 0 22px;
}
.chapter h3 {
    font-size: 22px;
    margin: 0 0 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.chapter h3 canvas {
    width: 56px;
    height: 56px;
    border-radius: 10px;
    border: 3px solid var(--panel-edge);
}
.levels {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}
.level {
    aspect-ratio: 1;
    min-height: 60px;
    border-radius: 14px;
    border: 3px solid var(--btn-edge);
    background: var(--btn);
    color: var(--btn-ink);
    font-size: 22px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2px;
}
.level small {
    font-size: 13px;
    color: var(--gold);
    letter-spacing: 1px;
}
.level.next {
    background: var(--primary);
    border-color: var(--primary-edge);
    color: var(--primary-ink);
    outline: 3px solid var(--hi);
}
.level:disabled {
    opacity: 0.4;
}
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
    margin: 10px 0 24px;
}
.gallery figure {
    margin: 0;
    text-align: center;
    font-size: 15px;
}
.gallery canvas {
    width: 100%;
    height: auto;
    border-radius: 12px;
    border: 3px solid var(--panel-edge);
}
.gallery .locked canvas {
    filter: brightness(0.25) grayscale(1);
}

/* daily calendar */
.calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    margin: 12px 0 18px;
}
.calendar div {
    aspect-ratio: 1;
    border-radius: 10px;
    background: var(--panel);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
}
.calendar .done {
    background: var(--primary);
    color: var(--primary-ink);
}
.calendar .today {
    outline: 3px solid var(--hi);
}
.calendar .head {
    background: none;
    font-size: 14px;
    color: var(--muted);
}

/* about */
#about-body {
    font-size: 19px;
    font-weight: 500;
    line-height: 1.5;
}
#about-body a {
    color: inherit;
}
#about-body .version {
    display: inline-block;
    padding: 4px 14px;
    border: 2px solid var(--panel-edge);
    border-radius: 999px;
    background: var(--panel);
    font-weight: 700;
}
#about-body .big {
    margin: 16px auto;
    width: min(90 * var(--vw), 440px);
}
#about-body .contact a {
    overflow-wrap: anywhere;
    -webkit-user-select: text;
    user-select: text;
}
.credits {
    white-space: pre-wrap;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 13px;
    line-height: 1.45;
    background: var(--panel);
    padding: 10px;
    border-radius: 8px;
    overflow-wrap: anywhere;
}
