/* Drawing Circles: the Spirograph desk. A drawing set opened on a kitchen
   table: corrugated card, a pinned sheet of paper, plastic wheels, one
   ballpoint. The canvas in draw.js reads these custom properties once. */
:root {
  color-scheme: light;
  --desk: #C4A06E;
  --desk-edge: #A9834F;
  --paper: #F2EFE6;
  --tray: #E6E0D2;
  --ink: #202018;
  --graphite: #5A564D;
  --fwd: #F4BE4A;
  --fwd-rim: #9A6A12;
  --back: #245AA8;
  --leash: #E0603E;
  --pin: #B8B5AC;
  --pin-rim: #6E6A60;
  --sans: "Atkinson Hyperlegible", "Noto Sans TC", sans-serif;
  --display: "Bagel Fat One", "Atkinson Hyperlegible", "Noto Sans TC", sans-serif;
  /* The shared Play Lab shell reads these. */
  --pl-font: var(--sans);
  --pl-topbar-bg: transparent;
  --pl-topbar-text: var(--ink);
  --pl-control-text: var(--ink);
  --pl-control-bg: var(--paper);
  --pl-control-border: var(--ink);
  --pl-focus: var(--back);
  --pl-overlay: rgb(32 32 24 / .55);
  --pl-card-bg: var(--paper);
  --pl-card-text: var(--ink);
  --pl-card-muted: var(--graphite);
  --pl-card-border: var(--ink);
  --pl-primary: var(--ink);
  --pl-primary-text: var(--paper);
  --pl-shadow: rgb(32 32 24 / .35);
  --pl-share-bg: var(--paper);
  --pl-radius-control: 3px;
  --pl-radius-card: 3px;
  --pl-radius-picture: 2px;
  font-family: var(--sans);
  background: var(--desk);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  min-width: 320px;
  overflow-x: hidden;
  background-color: var(--desk);
  background-image: repeating-linear-gradient(90deg, rgba(0, 0, 0, .035) 0 2px, transparent 2px 7px);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 20px;
  line-height: 1.35;
}
button, a { font: inherit; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* A paper tab: every button on the desk. */
button {
  min-height: 44px;
  min-width: 44px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 2px 0 var(--desk-edge);
  font: 700 20px/1.1 var(--sans);
  cursor: pointer;
  touch-action: manipulation;
}
button:active { transform: translateY(2px); box-shadow: none; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--back); outline-offset: 3px; }
/* Not available: flat tray colour, graphite text (6:1 on the tray), no opacity. */
button:disabled { color: var(--graphite); background: var(--tray); border-style: dashed; box-shadow: none; cursor: default; transform: none; }
.primary-button { color: var(--paper); background: var(--ink); }
.primary-button:disabled { color: var(--graphite); background: var(--tray); }

.shell {
  width: min(100%, 430px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(62px + env(safe-area-inset-top)) 12px calc(10px + env(safe-area-inset-bottom));
}

/* Header on the desk: name in the display face, paper tabs for the rest. */
[data-pl="topbar"] { height: calc(62px + env(safe-area-inset-top)); box-shadow: none; }
.pl-topbar__inner { width: min(100%, 430px); height: 60px; padding: 0 12px; gap: 10px; }
[data-pl="back"] {
  position: relative; isolation: isolate; flex: 0 1 auto; min-width: 0; justify-content: flex-start; padding: 0; border: 0; border-radius: 0; background: transparent;
  color: var(--ink); font: 400 28px/.98 var(--display); letter-spacing: .01em; white-space: normal; text-align: left;
}
.pl-topbar__actions { gap: 6px; flex: 0 0 auto; margin-left: auto; }
.brand-wheel { position: absolute; z-index: -1; left: -8px; top: 50%; width: 56px; height: 56px; transform: translateY(-50%); pointer-events: none; }
.brand-wheel path { fill: rgba(244, 190, 74, .5); stroke: var(--fwd-rim); stroke-width: 2; stroke-linejoin: round; }
.brand-wheel circle { fill: var(--pin); stroke: var(--pin-rim); stroke-width: 1.5; }
.pl-topbar__actions button, [data-pl="back"], .pl-howto-footer button {
  border-radius: 3px; border: 2px solid var(--ink); color: var(--ink); background: var(--paper); box-shadow: 0 2px 0 var(--desk-edge);
  font: 700 20px/1.1 var(--sans);
}
[data-pl="back"] { border: 0; background: transparent; box-shadow: none; font: 400 28px/.98 var(--display); }
.pl-topbar__actions button { min-width: 44px; min-height: 44px; padding: 0 9px; }
.pl-howto-word { display: none; }
.pl-howto-question { display: inline; font-size: 22px; font-weight: 700; }
@media (min-width: 375px) {
  .pl-howto-word { display: inline-block; width: 3.3em; line-height: 1.05; white-space: normal; text-align: center; }
  .pl-howto-question { display: none; }
  .pl-topbar__actions { gap: 5px; }
  .pl-topbar__actions button { padding: 0 6px; }
}
@media (max-width: 359px) {
  .pl-topbar__inner { padding: 0 8px; gap: 9px; }
  .pl-topbar__actions { gap: 4px; }
  .pl-topbar__actions button { width: auto; min-width: 44px; padding: 0 7px; font-size: 20px; }
  [data-pl="back"] { font-size: 28px; }
}

#play-screen { padding: 0; }
.level-row { display: none; }
.instruction { min-height: 28px; margin: 2px 2px 8px; color: var(--ink); font-size: 22px; font-weight: 700; line-height: 1.25; }
.instruction.pl-new-rule { margin: 2px 2px 8px; }
.pl-new-tag { display: inline-block; margin-right: 4px; padding: 1px 8px; border: 2px solid var(--ink); border-radius: 3px; color: var(--ink); background: var(--tray); font-size: 18px; line-height: 1.2; vertical-align: 1px; }
.mode-status { min-height: 0; margin: 0 0 6px; color: var(--ink); font-size: 18px; font-weight: 700; }
.mode-status:empty { display: none; }

/* The pinned sheet: 0.4 degrees off square, the two pins not level. */
.board-shell {
  position: relative;
  width: 100%;
  margin-top: 2px;
  overflow: visible;
  border-radius: 2px;
  background: var(--paper);
  box-shadow: 0 1px 0 var(--desk-edge), 0 3px 0 rgba(0, 0, 0, .14), 0 8px 14px rgba(60, 40, 10, .16);
  transform: rotate(-.4deg);
}
.board-shell::before, .board-shell::after {
  content: ''; position: absolute; z-index: 2; width: 14px; height: 14px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 35% 35%, #EDEBE5 0 2px, var(--pin) 3px); border: 1.5px solid var(--pin-rim);
}
.board-shell::before { top: 6px; left: 4px; }
.board-shell::after { top: 8px; right: 4px; }
#board { display: block; width: 100%; height: auto; touch-action: pan-y; user-select: none; border-radius: 2px; }
#ruler, #tray { display: none; }
.message { min-height: 0; height: 0; overflow: hidden; margin: 0; }
.credit { margin: 8px 2px 0; color: var(--ink); font-size: 18px; line-height: 1.4; }
/* On a short screen the board gets the room; the same story is in Why this exists. */
@media (max-height: 700px) { .credit { display: none; } }

.controls { display: flex; justify-content: center; gap: 10px; padding: 12px 0 0; }
.controls button { min-width: 128px; min-height: 48px; }
#play-screen.won .controls { display: none; }

/* The win slip: paper on the desk, under the sheet, in the page flow. */
.result-card {
  position: sticky; bottom: max(8px, env(safe-area-inset-bottom)); z-index: 6;
  margin: 12px 0 0; padding: 12px 14px 14px;
  border: 2px solid var(--ink); border-radius: 0; background: var(--paper); box-shadow: 0 3px 0 var(--desk-edge);
  text-align: center;
}
.result-card[hidden] { display: none; }
.result-title { margin: 0; font: 400 28px/1.1 var(--display); }
.result-marks { margin: 6px 0 8px; font-size: 20px; font-weight: 700; }
.card-link { display: block; width: 100%; margin: 0 0 10px; border-style: dashed; background: var(--tray); box-shadow: none; }
.card-link[hidden] { display: none; }
.share-line { margin: 8px 0 0; font-size: 18px; overflow-wrap: anywhere; white-space: pre-line; }
.share-line[hidden] { display: none; }
.share-status { min-height: 0; margin: 6px 0 0; font-size: 18px; }
.share-status:empty { display: none; }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.result-actions button { min-width: 0; min-height: 48px; padding: 0 14px; }

/* Levels page. */
.map-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0 8px; }
.map-heading h1 { margin: 0; font: 700 28px/1.1 var(--sans); }
#map-copy { color: var(--ink); font-size: 20px; font-weight: 400; }
.quiet-button { min-height: 44px; }
.modes { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 12px; }
.mode-card { min-width: 0; border: 2px solid var(--ink); border-radius: 3px; background: var(--paper); box-shadow: 0 2px 0 var(--desk-edge); }
.mode-open { width: 100%; min-height: 76px; border: 0; padding: 8px 10px; background: transparent; box-shadow: none; text-align: left; }
.mode-open:disabled { border: 0; background: var(--tray); }
.mode-open strong, .mode-open small { display: block; }
.mode-open strong { font-size: 20px; color: inherit; }
.mode-open small { margin-top: 4px; color: var(--graphite); font-size: 18px; font-weight: 400; line-height: 1.25; }
.difficulty-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-top: 2px solid var(--ink); }
.difficulty-picker button { min-width: 0; padding: 0 2px; border-width: 2px; font-size: 18px; box-shadow: none; }
.difficulty-picker button.selected { color: var(--paper); background: var(--ink); }
.level-map { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.level-tile { min-height: 76px; padding: 8px 10px; text-align: left; }
.level-tile strong, .level-tile small { display: block; }
.level-tile strong { font-size: 20px; }
.level-tile small { margin-top: 4px; color: var(--graphite); font-size: 18px; font-weight: 400; line-height: 1.25; }
.level-tile.complete { color: var(--paper); background: var(--ink); }
.level-tile.complete small { color: var(--tray); }
.sketchbook { margin-top: 22px; padding: 14px 0 4px; border-top: 2px solid var(--ink); }
.sketchbook h2 { margin: 0; font: 700 24px/1.2 var(--sans); }
.sketchbook p { margin: 8px 0 12px; color: var(--ink); font-size: 18px; }
.sketches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.sketch { display: block; width: 100%; min-width: 0; height: auto; padding: 7px; text-align: left; }
.sketch canvas { display: block; width: 100%; height: auto; border: 1px solid var(--desk-edge); }
.sketch strong, .sketch small { display: block; overflow: hidden; margin-top: 6px; text-overflow: ellipsis; white-space: nowrap; }
.sketch strong { font-size: 18px; }
.sketch small { color: var(--graphite); font-size: 18px; font-weight: 400; }

/* The sketch card: a little collectible with a desk-brown frame. It still tilts and shines. */
.sketch-card-modal { position: fixed; z-index: 40; inset: 0; display: grid; place-items: center; padding: 18px; overflow: hidden; background: rgb(32 32 24 / .7); perspective: 1000px; touch-action: none; }
.sketch-card-modal[hidden] { display: none; }
.card-close { position: fixed; top: max(10px, env(safe-area-inset-top)); right: 12px; z-index: 2; }
.sketch-card-modal { --plc-ink: var(--ink); --plc-paper: var(--paper); --plc-line: var(--desk-edge); --plc-moss: var(--desk-edge); --plc-warm: var(--fwd-rim); --plc-dim: var(--graphite); --plc-shadow: rgb(0 0 0 / .45); }
.sketch-card-modal .plc-card { width: min(82vw, 320px); aspect-ratio: 320 / 380; box-shadow: 0 6px 0 rgb(0 0 0 / .25); }
.sketch-card-modal .plc-card__inner { grid-template-rows: minmax(0, 1fr) auto; gap: 10px; border: 6px solid var(--desk); border-radius: 3px; background: var(--paper); }
.sketch-card-modal .plc-card__art { position: relative; min-height: 0; padding: 0; overflow: hidden; border-color: var(--desk-edge); border-radius: 2px; background: var(--paper); }
.sketch-card-modal .plc-card__art canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; }
.sketch-card-modal .plc-card__title { color: var(--ink); font: 400 24px/1.1 var(--display); }
.sketch-card-modal .plc-card__mark { color: var(--graphite); font-family: var(--sans); font-size: 18px; }
.sketch-card-modal .plc-card__date { color: var(--graphite); font: 400 18px/1.1 var(--sans); opacity: 1; }
@media (max-height: 620px) { .sketch-card-modal .plc-card { width: min(67vw, 255px); } }

/* The hint hand. */
.hand-demo {
  position: absolute; z-index: 3; display: none; width: 40px; height: 44px; margin: -22px 0 0 -20px; border-radius: 0; color: transparent;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 44'%3E%3Cpath d='M14 4c2.2 0 4 1.8 4 4v12l1-.2c1.6-.3 3.2.6 3.7 2.1 1.6-.6 3.4.1 4.1 1.6 1.7-.5 3.5.4 4.1 2 .2.5.3 1 .3 1.6V34c0 3.3-2.7 6-6 6h-8.6c-1.9 0-3.6-.9-4.8-2.4L5.6 30c-1.2-1.6-.9-3.8.6-5 1.4-1.1 3.4-1 4.6.3l-.8-.8V8c0-2.2 1.8-4 4-4z' fill='%23F2EFE6' stroke='%23202018' stroke-width='2.5' stroke-linejoin='round'/%3E%3Cpath d='M18 20v6M22.7 22v5M26.8 23.6V28' stroke='%23202018' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
  box-shadow: none; font-size: 0; line-height: 0; pointer-events: none; filter: drop-shadow(1px 2px 0 rgb(0 0 0 / .3));
}
.hand-demo.running { display: block; animation: none; }
.hand-demo i { display: none; }
.hand-demo[data-dir="down"] { transform: rotate(180deg); }
.hand-demo[data-dir="left"] { transform: rotate(-90deg); }

.success-effect { position: absolute; inset: 0; z-index: 3; overflow: hidden; pointer-events: none; }
.success-effect i { position: absolute; top: 47%; left: 50%; width: 9px; height: 9px; border-radius: 2px; opacity: 0; background: var(--fwd); }
.success-effect.on i { animation: confetti .72s ease-out both; }
.success-effect i:nth-child(2) { background: var(--back); animation-delay: .05s; }
.success-effect i:nth-child(3) { background: var(--leash); animation-delay: .1s; }
.success-effect i:nth-child(4) { background: var(--fwd-rim); animation-delay: .02s; }
.success-effect i:nth-child(5) { background: var(--ink); animation-delay: .12s; }
@keyframes confetti { 0% { transform: translate(0, 0) rotate(0); opacity: 1; } 100% { transform: translate(var(--x, 0), var(--y, 0)) rotate(240deg); opacity: 0; } }
.success-effect i:nth-child(1) { --x: -112px; --y: -105px; }.success-effect i:nth-child(2) { --x: 106px; --y: -96px; }.success-effect i:nth-child(3) { --x: 130px; --y: 92px; }.success-effect i:nth-child(4) { --x: -126px; --y: 78px; }.success-effect i:nth-child(5) { --x: 8px; --y: -145px; }

.load-error { margin: 54px 8px; padding: 18px; border: 2px solid var(--leash); border-radius: 3px; background: var(--paper); color: var(--ink); line-height: 1.4; }

/* How to play and the first-visit card: one paper card on the desk. */
[data-pl="howto-card"] { padding: 14px 16px; border: 2px solid var(--ink); box-shadow: 0 4px 0 rgb(0 0 0 / .25); }
[data-pl="howto-card"] h2 { margin-bottom: 8px; font: 700 26px/1.1 var(--sans); }
[data-pl="howto-lines"] { margin-bottom: 10px; color: var(--ink); font: 400 20px/1.3 var(--sans); }
[data-pl="howto-pictures"] { margin-bottom: 8px; }
[data-pl="howto-pictures"] canvas { width: auto; height: 118px; min-width: 80px; min-height: 80px; }
@media (max-height: 640px) { [data-pl="howto-lines"] { font-size: 18px; } }
[data-pl="howto-credit"], [data-pl="howto-pager"] { color: var(--graphite); font: 400 18px/1.35 var(--sans); }
[data-pl="howto-pager"] button { font: 700 22px/1 var(--sans); }
[data-pl="howto-pictures"] canvas { border: 2px solid var(--ink); border-radius: 2px; }
.pl-howto-footer button { font-size: 20px; }
.pl-howto-footer .pl-howto-start { color: var(--paper); background: var(--ink); }
[data-pl="share-fallback"] { font: 400 18px/1.35 var(--sans); }
.playlab-howto-open [data-pl="topbar"] { z-index: 30; }

.reduced-motion *, .reduced-motion *::before, .reduced-motion *::after { animation-duration: .001ms; animation-iteration-count: 1; scroll-behavior: auto; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms; animation-iteration-count: 1; scroll-behavior: auto; } }
