/* Tilt. Palette and type follow the Daily Marble site: paper, ink, house coral. --team is set per
   board to the team whose world it is. */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
:root {
  --paper: #F1EDE1; --paper-2: #E7E0CE; --paper-3: #DCD3BD; --ink: #14110B; --ink-2: #5E5647;
  --house: #FF6B6B; --house-ink: #B0332E; --rule: rgba(20,17,11,0.16);
  --good: #1F8A5B; --gold: #D38C08; --scrim: rgba(20,17,11,0.5);
  --team: #E23D28;
  --display: 'Archivo', 'Arial Narrow', system-ui, sans-serif;
  --body: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #100E0A; --paper-2: #1D1A14; --paper-3: #2A261E; --ink: #F1EDE1; --ink-2: #B4AB98;
    --house: #FF7A72; --house-ink: #FF9D95; --rule: rgba(241,237,225,0.16);
    --good: #4CC98A; --gold: #F2B233; --scrim: rgba(0,0,0,0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #100E0A; --paper-2: #1D1A14; --paper-3: #2A261E; --ink: #F1EDE1; --ink-2: #B4AB98;
  --house: #FF7A72; --house-ink: #FF9D95; --rule: rgba(241,237,225,0.16);
  --good: #4CC98A; --gold: #F2B233; --scrim: rgba(0,0,0,0.6);
  color-scheme: dark;
}
html, body { height: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--body); overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
/* a swipe must never select text or open the long-press menu, and taps should not flash grey */
html { -webkit-tap-highlight-color: transparent; }
.tilt-stage, .controls, .mast { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
:focus-visible { outline: 2px solid var(--house-ink); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* viewport-fit=cover lets the page run under the notch, status bar and home indicator, so each
   edge adds its safe-area inset (zero on a desktop and in most mobile browsers). */
#app { height: 100%; display: flex; flex-direction: column; padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
.mast { display: flex; align-items: center; gap: 10px; padding: calc(18px + env(safe-area-inset-top, 0px)) 16px 10px; flex: none; }
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand b { font: 900 30px/0.8 var(--display); font-stretch: 125%; letter-spacing: -0.01em; display: inline-block; transform: rotate(-4deg); transform-origin: 20% 80%; }
.brand b i { font-style: normal; color: var(--house-ink); }
.brand small { font: 700 10px/1 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-2); }
.mast .spacer { flex: 1; }
.chip-btn { display: flex; align-items: center; gap: 8px; border: 1px solid var(--rule); background: var(--paper-2); border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: 13px; }
.chip-btn b { font-family: var(--mono); color: var(--house-ink); }
.chip-btn:hover, .icon-btn:hover { border-color: var(--ink); }
.chip-btn.daily { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip-btn.daily b { color: var(--house); }
.icon-btn { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--rule); background: transparent; font-weight: 800; flex: none; }

.play { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.board-col { min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px 16px calc(12px + env(safe-area-inset-bottom, 0px)); gap: 10px; }
.level-head { width: 100%; max-width: 560px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.level-head .eyebrow { margin-bottom: 4px; }
.level-head h1 { margin: 0; font: 900 clamp(26px, 5vw, 38px)/0.9 var(--display); font-stretch: 118%; text-transform: uppercase; text-wrap: balance; }
.level-head h1 span { color: var(--team); filter: saturate(1.1); }
.counter { text-align: right; font-variant-numeric: tabular-nums; flex: none; }
.counter b { display: block; font: 800 34px/0.9 var(--display); font-stretch: 112%; }
.counter span { font: 700 10.5px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
.counter.over b { color: var(--house-ink); }
.eyebrow { font: 700 10.5px/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-2); }

.tilt-stage { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; perspective: 900px; position: relative; }
.tray { position: relative; transition: transform 320ms cubic-bezier(.2,.9,.3,1.2); transform-style: preserve-3d; touch-action: none; }
.tray.moving { transition: transform 140ms ease-out; }
#board { display: block; touch-action: none; }
.banner { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--ink); color: var(--paper); border-radius: 14px; padding: 16px 18px 14px; width: min(320px, calc(100% - 32px)); text-align: center; box-shadow: 0 16px 40px rgba(0,0,0,0.35); display: flex; flex-direction: column; gap: 10px; align-items: center; }
.banner strong { font: 900 24px/1 var(--display); font-stretch: 118%; text-transform: uppercase; }
.banner p { margin: 0; font-size: 14px; line-height: 1.4; color: color-mix(in srgb, var(--paper) 78%, transparent); }
.banner .row { display: flex; gap: 8px; }
.banner button { border: 0; border-radius: 10px; padding: 9px 16px; font-weight: 700; background: var(--house); color: #14110B; }
.banner button.alt { background: transparent; border: 1px solid color-mix(in srgb, var(--paper) 40%, transparent); color: var(--paper); }

.controls { width: 100%; max-width: 560px; display: flex; gap: 8px; align-items: center; }
.ctl { border: 1px solid var(--rule); background: var(--paper-2); border-radius: 10px; padding: 9px 12px; font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.ctl:hover:not(:disabled) { border-color: var(--ink); }
.ctl:disabled { opacity: 0.4; cursor: default; }
.ctl kbd { font: 700 10px/1 var(--mono); color: var(--ink-2); border: 1px solid var(--rule); border-radius: 4px; padding: 2px 4px; }
.controls .spacer { flex: 1; }
.pad { display: grid; grid-template-columns: repeat(4, 38px); gap: 5px; }
.pad button { height: 38px; border-radius: 9px; border: 1px solid var(--rule); background: var(--paper-2); font-size: 16px; font-weight: 800; }
.pad button:hover { border-color: var(--ink); }
.swipe-hint { font-size: 12px; color: var(--ink-2); }

.panel { border-left: 1px solid var(--rule); padding: 18px 18px 16px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; min-height: 0; }
.cards { display: flex; flex-direction: column; gap: 8px; }
.who { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: center; }
.who canvas { width: 44px; height: 44px; }
.who strong { display: block; font-size: 14px; }
.who span { font-size: 13px; color: var(--ink-2); line-height: 1.35; }
.who em { font-style: normal; font: 700 10px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }
.rules { margin: 0; padding: 0; list-style: none; display: grid; gap: 7px; font-size: 13px; line-height: 1.4; color: var(--ink-2); }
.rules li { display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: start; }
.rules canvas { width: 22px; height: 22px; }
.rules b { color: var(--ink); }
.stars { font-size: 18px; letter-spacing: 2px; color: var(--gold); }
.stars .off { color: var(--paper-3); }
.fine { font-size: 12px; color: var(--ink-2); line-height: 1.45; margin: 0; }

/* sheets */
.sheet-back { position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.sheet { background: var(--paper); color: var(--ink); border-radius: 16px; width: min(540px, 100%); max-height: calc(100% - 8px); overflow-y: auto; padding: 22px 22px 20px; box-shadow: 0 20px 60px rgba(0,0,0,0.4); display: flex; flex-direction: column; gap: 14px; }
.sheet h2 { margin: 0; font: 900 clamp(34px, 8vw, 52px)/0.88 var(--display); font-stretch: 125%; text-transform: uppercase; text-wrap: balance; }
.sheet h2 em { font-style: normal; color: var(--house-ink); }
.sheet .lede { margin: 0; font-size: 15px; line-height: 1.45; color: var(--ink-2); }
.sheet .lede b { color: var(--ink); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.big { flex: 1 1 200px; border: 0; border-radius: 12px; background: var(--house); color: #14110B; padding: 13px 16px; font: 900 19px/1 var(--display); font-stretch: 125%; text-transform: uppercase; box-shadow: 0 3px 0 var(--house-ink); }
.big:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--house-ink); }
.plain { flex: 1 1 130px; border: 1px solid var(--ink); background: transparent; border-radius: 12px; padding: 12px 14px; font-weight: 700; font-size: 14px; }
.plain:hover { background: var(--paper-2); }
.share-box { font: 500 13px/1.5 var(--mono); background: var(--paper-2); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; user-select: all; margin: 0; }
.result-row { display: flex; gap: 18px; align-items: baseline; flex-wrap: wrap; }
.result-row .stars { font-size: 34px; }
.result-row span { font-size: 14px; color: var(--ink-2); }
.result-row span b { font: 800 22px/1 var(--display); color: var(--ink); }
.demo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.demo figure { margin: 0; border-radius: 10px; background: var(--paper-2); padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.demo canvas { width: 100%; aspect-ratio: 5 / 3; }
.demo figcaption { font-size: 12.5px; line-height: 1.35; color: var(--ink-2); }
.demo figcaption b { color: var(--ink); }

.worlds { display: grid; gap: 10px; }
.world { border: 1px solid var(--rule); border-radius: 12px; padding: 10px 12px; display: grid; grid-template-columns: 40px 1fr; gap: 4px 12px; align-items: center; }
.world canvas { width: 40px; height: 40px; grid-row: span 2; }
.world .wt strong { font: 800 15px/1.1 var(--display); font-stretch: 112%; text-transform: uppercase; }
.world .wt span { display: block; font-size: 12.5px; color: var(--ink-2); }
.lv-row { display: flex; gap: 6px; flex-wrap: wrap; }
.lv { min-width: 44px; border: 1px solid var(--rule); background: var(--paper-2); border-radius: 8px; padding: 5px 6px; font: 700 12px/1.1 var(--mono); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.lv small { font-size: 9px; letter-spacing: 1px; color: var(--gold); }
.lv:hover { border-color: var(--ink); }
.lv[aria-current="true"] { border: 2px solid var(--house); padding: 4px 5px; }
.daily-card { border: 0; border-radius: 12px; background: var(--ink); color: var(--paper); padding: 14px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; text-align: left; }
.daily-card strong { font: 900 22px/1 var(--display); font-stretch: 118%; text-transform: uppercase; }
.daily-card span { font-size: 13px; color: color-mix(in srgb, var(--paper) 75%, transparent); }
.daily-card .go { grid-row: span 2; background: var(--house); color: #14110B; border-radius: 10px; padding: 10px 14px; font: 900 15px/1 var(--display); font-stretch: 118%; text-transform: uppercase; }

/* controls: level bubble, mode sheet, toast */
.bubble { position: absolute; right: 10px; bottom: 10px; width: 56px; height: 56px; border-radius: 50%; border: 2px solid var(--rule); background: var(--paper-2); pointer-events: none; }
.bubble::before { content: ''; position: absolute; inset: 30%; border-radius: 50%; border: 1px dashed var(--ink-2); opacity: 0.6; }
.bubble i { position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; background: var(--ink-2); transition: background 120ms; }
.bubble.hot { border-color: var(--house); }
.bubble.hot i { background: var(--house); }
.bubble.cool i { background: var(--ink-2); opacity: 0.5; }
.note { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); background: var(--ink); color: var(--paper); border-radius: 10px; padding: 8px 12px; font-size: 13px; font-weight: 600; max-width: calc(100% - 32px); text-align: center; z-index: 2; box-shadow: 0 8px 24px rgba(0,0,0,0.3); }
.modes { display: grid; gap: 8px; }
.mode { display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: center; text-align: left; border: 1px solid var(--rule); background: transparent; border-radius: 12px; padding: 10px 12px; }
.mode:hover { border-color: var(--ink); }
.mode[aria-checked="true"] { border: 2px solid var(--house); padding: 9px 11px; background: color-mix(in srgb, var(--house) 10%, transparent); }
.mode .glyph { width: 44px; height: 44px; border-radius: 10px; background: var(--paper-2); display: grid; place-items: center; font: 800 20px/1 var(--display); }
.mode strong { display: block; font-size: 15px; }
.mode span { font-size: 13px; color: var(--ink-2); line-height: 1.35; }
.toggles { display: grid; gap: 6px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--rule); padding-top: 10px; font-size: 14px; }
.toggle small { display: block; color: var(--ink-2); font-size: 12.5px; }
.switch { width: 46px; height: 28px; border-radius: 999px; border: 0; background: var(--paper-3); position: relative; flex: none; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--paper); box-shadow: 0 1px 3px rgba(0,0,0,0.3); transition: transform 150ms; }
.switch[aria-checked="true"] { background: var(--good); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.status { font: 500 12px/1.5 var(--mono); color: var(--ink-2); background: var(--paper-2); border-radius: 10px; padding: 8px 10px; margin: 0; }
.debug { display: grid; grid-template-columns: auto 1fr 3.5em; gap: 6px 10px; align-items: center; font: 500 12px/1 var(--mono); }
.debug input { width: 100%; }
.haptic-sw { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; overflow: hidden; }
.ctl .lbl { white-space: nowrap; }
body.mode-buttons .pad { display: grid; }

@media (max-width: 820px) {
  .play { grid-template-columns: 1fr; }
  .panel { display: none; }
  .board-col { padding: 4px 16px calc(12px + env(safe-area-inset-bottom, 0px)); gap: 8px; }
  .brand small { display: none; }
  .pad { display: none; }
  .ctl kbd { display: none; }
  .controls { flex-wrap: wrap; }
  #undo .lbl, #restart .lbl { display: none; }
  body.mode-buttons .pad { width: 100%; grid-template-columns: repeat(4, 1fr); order: 5; }
  body.mode-buttons .pad button { height: 52px; font-size: 22px; }
  body:not(.mode-swipe) .swipe-hint { display: none; }
}
@media (min-width: 821px) { .swipe-hint { display: none; } }

/* A phone on its side: too short for the stacked layout, so the board takes the left and the
   title, counter and controls stack in a column on the right. The installed app is locked to
   portrait; this is for the browser. */
@media (orientation: landscape) and (max-height: 540px) {
  .play { grid-template-columns: 1fr; }
  .panel { display: none; }
  .mast { padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 6px; }
  .brand small { display: none; }
  .brand b { font-size: 24px; }
  .board-col {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(200px, 280px);
    grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "stage head" "stage ." "stage controls";
    gap: 8px 20px; padding: 2px 16px calc(10px + env(safe-area-inset-bottom, 0px)); align-items: start;
  }
  .tilt-stage { grid-area: stage; height: 100%; }
  .level-head { grid-area: head; flex-direction: column; align-items: flex-start; gap: 8px; }
  .level-head h1 { font-size: 30px; }
  .counter { text-align: left; }
  .counter b { font-size: 28px; }
  .controls { grid-area: controls; flex-wrap: wrap; align-self: end; }
  .controls .spacer, .swipe-hint, .ctl kbd { display: none; }
  #undo .lbl, #restart .lbl { display: none; }
  .pad { display: none; }
  body.mode-buttons .pad { display: grid; width: 100%; grid-template-columns: repeat(4, 1fr); }
  body.mode-buttons .pad button { height: 44px; font-size: 18px; }
  .bubble { width: 44px; height: 44px; }
}


/* the smallest phones (320px): keep the controls on one row */
@media (max-width: 359px) { .swipe-hint { display: none; } .ctl { padding: 9px 10px; } }
