@import url("https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600&family=Gochi+Hand&display=swap");

/* Hand Turkey: a craft table, a sheet of construction paper and a box of crayons. The table, the paper and
   the turkey are all drawn on one canvas (#scene); the DOM carries the crayon box, the buttons and the chrome. */
:root {
  --font: "Geist", system-ui, -apple-system, sans-serif;
  --hand: "Gochi Hand", "Patrick Hand", "Comic Sans MS", cursive;
  --ink: #f6ead2;
  --ink-dim: rgba(246, 234, 210, 0.62);
  --panel: rgba(46, 28, 16, 0.86);
  --panel-hi: rgba(78, 49, 28, 0.95);
  --line: rgba(246, 214, 160, 0.2);
  --ring: rgba(255, 207, 120, 0.95);
  --go-a: #f6c75a; --go-b: #e3902d;
  --safe-t: max(12px, env(safe-area-inset-top));
  --safe-b: max(14px, env(safe-area-inset-bottom));
  --safe-l: max(14px, env(safe-area-inset-left));
  --safe-r: max(14px, env(safe-area-inset-right));
}
*,*::before,*::after { box-sizing: border-box; }
html, body { -webkit-tap-highlight-color: transparent; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { font-family: var(--font); background: #3b2414; color: var(--ink); touch-action: none; }

canvas#scene {
  display: block; position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; z-index: 0;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; cursor: crosshair;
}
body.m-dec canvas#scene { cursor: pointer; }
body.m-draw canvas#scene { cursor: default; }

/* ---- the dock: hint, crayon box, buttons ---- */
.dock {
  position: fixed; z-index: 8; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 42px); width: max-content; max-width: calc(100vw - 20px);
  display: flex; flex-direction: column; align-items: center; gap: 8px; transition: opacity .3s ease;
}
.hint {
  margin: 0; max-width: min(92vw, 560px); min-height: 1.5em; text-align: center; pointer-events: none;
  font-family: var(--hand); font-size: 1.12rem; line-height: 1.25; letter-spacing: 0.01em; color: var(--ink);
  text-shadow: 0 1px 8px rgba(20, 10, 4, 0.95), 0 0 2px rgba(20, 10, 4, 0.9); transition: opacity .5s;
}
.hint.is-hidden { opacity: 0; }

.palette { display: flex; align-items: flex-end; justify-content: center; gap: 4px; padding: 0 4px; min-height: 52px; }
.crayon {
  appearance: none; border: 0; padding: 0; margin: 0; cursor: pointer; background: none; flex: none;
  width: 25px; height: 50px; position: relative; touch-action: manipulation;
  transition: transform .14s cubic-bezier(.3,1.5,.5,1); filter: drop-shadow(0 3px 3px rgba(0,0,0,.45));
}
.crayon i {
  display: block; width: 100%; height: 100%;
  clip-path: polygon(50% 0, 100% 17%, 100% 100%, 0 100%, 0 17%);
  background:
    linear-gradient(90deg, rgba(255,255,255,.28), rgba(255,255,255,0) 38%, rgba(0,0,0,.18)),
    linear-gradient(to bottom, transparent 0 38%, #f1e3bd 38% 46%, #d9c590 46% 48%, #f1e3bd 48% 80%, transparent 80%),
    var(--c);
}
.crayon:hover { transform: translateY(-3px); }
.crayon[aria-checked="true"] { transform: translateY(-9px) scale(1.06); }
.crayon:focus-visible { outline: 2px dashed var(--ring); outline-offset: 2px; border-radius: 4px; }
body.m-cap .palette, body.m-draw .palette { visibility: hidden; pointer-events: none; }

.acts { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.grp { display: none; align-items: center; justify-content: center; flex-wrap: wrap; gap: 7px; }
body.m-cap .grp--cap, body.m-dec .grp--dec { display: flex; }
body.m-draw .acts { visibility: hidden; pointer-events: none; }
body:not(.m-dec) .share-host { display: none; }

.pill, .dock .opt-share.opt-share {
  appearance: none; cursor: pointer; font-family: var(--font); margin: 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 13px;
  border-radius: 999px; font-size: 0.78rem; font-weight: 600; letter-spacing: 0.01em; opacity: 1; white-space: nowrap;
  color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 240, 210, 0.08) inset, 0 5px 14px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  transition: transform .12s ease, background .15s ease, border-color .15s ease; touch-action: manipulation; text-decoration: none;
}
.pill:hover, .dock .opt-share.opt-share:hover { background: var(--panel-hi); border-color: rgba(255, 214, 150, 0.45); text-decoration: none; }
.pill:active, .dock .opt-share.opt-share:active { transform: scale(0.95); }
.pill:focus-visible, .dock .opt-share.opt-share:focus-visible { outline: 2px dashed var(--ring); outline-offset: 2px; }
.pill[aria-pressed="true"] { background: rgba(246, 199, 90, 0.22); border-color: rgba(246, 199, 90, 0.75); color: #fff3d2; }
.pill[disabled] { opacity: 0.4; cursor: default; pointer-events: none; }
.pill svg, .dock .opt-share.opt-share svg { width: 17px; height: 17px; flex: none; }
.pill--go { background: linear-gradient(180deg, var(--go-a), var(--go-b)); color: #2b1608; border-color: rgba(255, 238, 190, 0.7); box-shadow: 0 1px 0 rgba(255,255,255,.55) inset, 0 7px 18px rgba(227, 144, 45, 0.28); }
.pill--go:hover { background: linear-gradient(180deg, #ffd57a, #eba040); border-color: #fff1c8; }
.paperdot { width: 16px; height: 16px; border-radius: 4px; background: #c9a06a; border: 1.5px solid rgba(255,255,255,.6); display: block; flex: none; }
.share-host { display: inline-flex; }
.share-host:empty { display: none; }
.dock .opt-share.opt-share { padding: 0 13px 0 11px; font-size: 0.78rem; }

.sound-btn {
  appearance: none; position: fixed; z-index: 12; cursor: pointer; padding: 0;
  top: var(--safe-t); right: var(--safe-r); width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.45); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  transition: transform .12s ease, opacity .15s ease;
}
.sound-btn:active { transform: scale(0.94); }
.sound-btn[aria-pressed="false"] { opacity: 0.55; }
.sound-btn[aria-pressed="false"] .sound-btn__wave { opacity: 0; }
.sound-btn:focus-visible { outline: 2px dashed var(--ring); outline-offset: 3px; }

.frame { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.frame__corner {
  position: absolute; font-size: clamp(0.58rem, 1.2vw, 0.7rem); font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase;
  color: rgba(246, 234, 210, 0.55); white-space: nowrap; font-family: var(--font); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
}
.frame__corner--tl { top: calc(var(--safe-t) + 13px); left: var(--safe-l); }
.frame__corner--tr { top: calc(var(--safe-t) + 13px); right: calc(var(--safe-r) + 54px); }
.frame__corner--bl { bottom: max(18px, env(safe-area-inset-bottom)); left: var(--safe-l); }
.frame__corner a { color: inherit; text-decoration: none; pointer-events: auto; border-bottom: 1px solid transparent; transition: color .14s, border-color .14s; }
.frame__corner a:hover { color: #ffe3a8; border-bottom-color: rgba(255, 227, 168, 0.5); }

/* the shared tip-jar and fullscreen badges sit side by side in the bottom-right corner */
.opt-tipjar.opt-tipjar { top: auto; bottom: max(14px, env(safe-area-inset-bottom)); transform: none; }
.opt-fs.opt-fs { top: auto; bottom: max(14px, env(safe-area-inset-bottom)); right: calc(max(14px, env(safe-area-inset-right)) + 54px); transform: none; }
.opt-tipjar.opt-tipjar.tj-nudge { animation: none; }

@media (max-width: 560px) {
  .pill .lbl { display: none; }
  .pill#pngBtn, .pill#cardBtn, .pill#paperBtn, .pill#newBtn, .pill#clearBtn { width: 38px; padding: 0; }
  .dock .opt-share.opt-share { padding: 0 12px 0 10px; }
  .hint { font-size: 1.05rem; }
}
@media (max-width: 400px) { .crayon { width: 23px; } .palette { gap: 3px; } }

/* phone on its side: crayon box on the left, buttons on the right, the paper in the middle */
@media (max-height: 500px) and (orientation: landscape) {
  .dock { position: static; transform: none; display: contents; }
  .hint { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(8px, env(safe-area-inset-bottom)); z-index: 8; font-size: 1rem; }
  .palette {
    position: fixed; z-index: 8; left: max(66px, env(safe-area-inset-left)); top: 50%; transform: translateY(-50%);
    display: grid; grid-template-columns: repeat(2, auto); gap: 4px 6px; min-height: 0; padding: 0; align-items: center;
  }
  .crayon { width: 54px; height: 22px; }
  .crayon i { clip-path: polygon(0 50%, 17% 0, 100% 0, 100% 100%, 17% 100%);
    background:
      linear-gradient(180deg, rgba(255,255,255,.28), rgba(255,255,255,0) 38%, rgba(0,0,0,.18)),
      linear-gradient(to right, transparent 0 38%, #f1e3bd 38% 46%, #d9c590 46% 48%, #f1e3bd 48% 80%, transparent 80%),
      var(--c); }
  .crayon:hover { transform: translateX(3px); }
  .crayon[aria-checked="true"] { transform: translateX(7px) scale(1.04); }
  .acts { position: fixed; z-index: 8; right: max(66px, env(safe-area-inset-right)); top: 50%; transform: translateY(-50%); gap: 0; }
  .grp { display: none; flex-direction: row; flex-wrap: wrap; width: 90px; gap: 6px; justify-content: center; }
  body.m-cap .grp--cap { width: 130px; flex-direction: column; flex-wrap: nowrap; }
  body.m-cap .grp--cap .pill { width: 100%; }
  .grp--dec .pill, .dock .opt-share.opt-share { width: 38px; padding: 0; }
  .grp--dec .pill .lbl, .grp--dec .pill span:not(.lbl) { display: none; }
  .dock .opt-share.opt-share span { display: none; }
  .frame__corner--tl, .frame__corner--tr { top: calc(var(--safe-t) + 4px); }
}
@media (prefers-reduced-motion: reduce) { .pill, .crayon, .sound-btn, .hint, .dock { transition: none; } }

/* off-screen measuring of the dock (the script sizes the paper by it) */
body.mz .dock { opacity: 0 !important; pointer-events: none !important; }
body.mz .grp--dec { display: flex !important; }
body.mz .grp--cap { display: none !important; }
body.mz .palette { visibility: hidden; }
body.mz .acts { visibility: hidden; }
body.mz .share-host { display: inline-flex !important; }
