/* Doodle. Black and white tools on a cream page. */
:root {
  --bg: #f7f2e8;
  --paper: #ffffff;
  --ink: #111111;
  --mute: #5f594d;
  --hover: #f8f3ea;
  --display: "Instrument Serif", Georgia, serif;
  --text: "Inter Tight", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
/* softer tan that fades out toward the edges. it sits on its own layer so it
   can drop out when you click the title for a new color */
html { position: relative; --page-ink: var(--ink); --page-mute: var(--mute); }
html::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(120% 80% at 50% 0, #f3ebdb, var(--bg) 70%);
}
html[data-tint]::before { opacity: 0; }
body {
  margin: 0;
  color: var(--page-ink);
  background: transparent;
  font: 15px/1.5 var(--text);
  padding-block: 24px 56px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.wrap { max-width: 1280px; margin: 0 auto; display: flex; flex-direction: column; gap: 44px; }
main { display: flex; flex-direction: column; gap: 48px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
h2 { margin: 0; font: 400 clamp(28px, 4vw, 40px)/1.05 var(--display); }
.label { font: 11px var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--page-mute); }

.top { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.top a { color: var(--page-ink); font-size: 13.5px; }

/* Buttons */
button {
  font: 500 13.5px var(--text);
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
}
button:hover { background: var(--hover); }
button:focus-visible, .frame:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
button[aria-pressed="true"] { background: var(--ink); color: #fff; }
button[aria-pressed="true"]:hover, .save:hover { background: #2c2c2c; }
button:disabled { opacity: .5; cursor: default; }
.save { background: var(--ink); color: #fff; }
button.link { border: 0; background: none; padding: 0 2px; text-decoration: underline; font-size: inherit; }
.spacer { flex: 1; }

/* Editor (used for the title box and the main studio) */
.editor { --sheet: #fff; --on-sheet: var(--mute); --guide: rgba(17, 17, 17, .14); display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.editor[data-theme="dark"] { --sheet: #111; --on-sheet: #b9b3a6; --guide: rgba(255, 255, 255, .18); }
.sheet-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.sheet-head b { font: 400 26px var(--display); }

.board {
  position: relative;
  width: 100%;
  aspect-ratio: var(--ratio, 1);
  border: 1.5px solid var(--ink);
  border-radius: 14px;
  background: var(--sheet);
  overflow: hidden;
  touch-action: none;
}
.board canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
[data-draw] { cursor: crosshair; }
.guide { position: absolute; inset: 12%; border: 1px dashed var(--guide); border-radius: 8px; pointer-events: none; }
.hint {
  position: absolute; inset: 0; display: grid; place-items: center; margin: 0;
  font: 400 clamp(22px, 3vw, 32px) var(--display); color: var(--on-sheet);
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
.editor[data-empty="true"] .hint { opacity: .55; }

.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sizes { display: flex; gap: 4px; }
.sizes button { width: 38px; height: 38px; padding: 0; display: grid; place-items: center; }
.sizes i { display: block; border-radius: 50%; background: currentColor; }
.status { min-height: 1.5em; margin: 0; font-size: 13.5px; color: var(--page-mute); }

.strip { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 10px; }
.frame {
  position: relative;
  aspect-ratio: var(--ratio, 1);
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: var(--sheet);
  cursor: pointer;
  overflow: hidden;
}
.frame canvas { width: 100%; height: 100%; display: block; }
.frame span { position: absolute; left: 8px; top: 6px; font: 11px var(--mono); color: var(--on-sheet); }
.frame[aria-current="true"] { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink); }

/* Title */
.hero { display: flex; flex-direction: column; gap: 14px; }
.hero-edit { max-width: 880px; }
.hero-edit .strip { --cols: 3; }
.hero[data-mode="show"] .hero-edit,
.hero[data-mode="edit"] .hero-show { display: none; }
.hero-show { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.masthead { width: 100%; max-width: 880px; display: grid; }
/* the whole title is a button: click it to change the page color */
#tint { appearance: none; -webkit-appearance: none; font: inherit; color: inherit; background: transparent; border: 0; border-radius: 0; box-shadow: none; padding: 0; margin: 0; text-align: left; }
#tint:hover, #tint:active { background: transparent; }
#tint:focus { outline: none; }
#tint:focus-visible { outline: 2px solid var(--page-ink); outline-offset: 6px; }
/* my mouse pops up under the doodle for 2s, then it's gone till reload */
.mast-show { position: relative; display: block; }
/* tip of the arrow sits right under the 2nd o, clicking up at it */
.mast-show #mouse { --m: clamp(32px, 5vw, 60px); position: absolute; top: calc(89% - .08 * var(--m) + 6px); left: calc(47.5% - .27 * var(--m)); width: var(--m); max-width: none; height: auto; aspect-ratio: 1; pointer-events: none; animation: mouse-out .6s ease 2s forwards; }
@media (prefers-reduced-motion: reduce) { .mast-show #mouse { animation: mouse-out 0s 2s forwards; } }
@keyframes mouse-out { to { opacity: 0; visibility: hidden; } }
.tint-name { margin: 0; min-height: 1.5em; font: 12px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--page-ink); }
.masthead canvas { width: 100%; max-width: 100%; height: auto; aspect-ratio: 3; display: block; }
.mast-word { font: 700 clamp(20px, 3.2vw, 34px)/1 var(--text); letter-spacing: -.01em; }
.mast-top { justify-self: start; }
.mast-bottom { justify-self: end; }

/* Setup */
.setup { display: flex; flex-direction: column; gap: 14px; }
.opts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 22px 28px;
  padding: 20px;
  border: 1.5px solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
}
.opt { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips small { margin-left: 6px; font: 9.5px var(--mono); letter-spacing: .1em; text-transform: uppercase; opacity: .65; }
.speed { display: flex; align-items: center; gap: 12px; }
.speed input { flex: 1; min-width: 0; accent-color: var(--ink); }
.speed output { font: 13px var(--mono); min-width: 6ch; }

/* Studio */
.studio { flex-direction: row; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.studio .board { width: 100%; margin-inline: auto; }
/* On phones, keep the whole board on screen so you never scroll while drawing */
@media (max-width: 820px) { .studio .board { width: min(100%, calc((100svh - 190px) * var(--ratio, 1))); } }
/* Large: drawing board takes the full width, frames and preview move below the tools */
.studio[data-size="large"] { grid-template-columns: minmax(0, 1fr); }
.studio[data-size="large"] > .pane:nth-child(2) { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 820px) { .studio[data-size="large"] > .pane:nth-child(2) { grid-template-columns: minmax(0, 1fr); } }
.pane { min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-direction: column; gap: 8px; }
.row-head { display: flex; justify-content: space-between; align-items: baseline; }
.studio .strip { --cols: 3; }

.preview { display: flex; flex-direction: column; gap: 12px; padding: 18px; border: 1.5px solid var(--ink); border-radius: 18px; background: var(--paper); }
.player { display: block; width: 100%; height: auto; }
.preview .player { max-width: 260px; border: 1.5px solid var(--ink); border-radius: 10px; }
.readout { margin: 0; font: 12.5px var(--mono); color: var(--mute); }

/* Examples */
.examples { display: flex; flex-direction: column; gap: 16px; }
.example-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.example { display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1.5px solid var(--ink); border-radius: 16px; background: var(--paper); min-width: 0; }
.example .player { border-radius: 8px; }
.example-foot { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.example-foot b { font: 400 22px var(--display); }
.example-note { margin: 0; font-size: 12px; line-height: 1.4; color: var(--mute); }

footer { font-size: 13px; color: var(--page-mute); }

@media (max-width: 820px) {
  .studio { grid-template-columns: 1fr; }
}

/* Top bar */
.top-links { display: flex; align-items: center; gap: 16px; }
.ex-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 16px; }

/* Footer: "by Michael" stamp + legal */
:root { --link: #1f5eff; }
.site-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 20px 32px; padding-top: 24px; border-top: 1.5px solid var(--page-ink); }
.legal-row { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--page-mute); min-width: 0; }
.legal-links { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.legal-links a { color: var(--page-ink); }
.stamp { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; color: var(--page-ink); text-decoration: none; border-radius: 8px; }
.stamp canvas { display: block; width: 190px; max-width: 100%; height: auto; }
.stamp { order: 2; margin-left: auto; }
@media (max-width: 560px) { .site-foot { flex-direction: column; align-items: stretch; } }

/* Download / Email me */
select {
  font: 500 13.5px var(--text);
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  padding: 7px 12px;
}

/* Email me screen */
.mail {
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100svh - 24px);
  padding: 0;
  border: 1.5px solid var(--ink);
  border-radius: 22px;
  background: var(--paper);
  color: var(--ink);
  overflow: auto;
}
.mail::backdrop { background: rgba(242, 234, 217, .82); backdrop-filter: blur(3px); }
.mail-card { position: relative; display: grid; grid-template-columns: 240px 1fr; gap: 28px; padding: 28px; }
.mail-pic { align-self: start; }
.mail-pic canvas { border: 1.5px solid var(--ink); border-radius: 12px; }
.mail-body { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.mail-body h2 { outline: none; }
.mail-sub { margin: 0; color: var(--mute); }
.mail-x { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; padding: 0; font-size: 20px; line-height: 1; }
.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field input, .field textarea {
  font: 15px var(--text); color: var(--ink);
  padding: 10px 12px; border: 1.5px solid var(--ink); border-radius: 10px; background: #fff;
}
.field textarea { resize: vertical; }
.pick { position: relative; }
.pick input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.pick span { display: inline-block; font: 500 13.5px var(--text); padding: 7px 14px; border: 1.5px solid var(--ink); border-radius: 999px; background: #fff; }
.pick input:checked + span { background: var(--ink); color: #fff; }
.pick input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }
.gift-toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.gift-toggle input { width: 18px; height: 18px; accent-color: var(--ink); }
.gift { display: flex; flex-direction: column; gap: 12px; padding: 14px; border: 1.5px dashed var(--ink); border-radius: 14px; }
.mail-err { margin: 0; min-height: 1.2em; font-size: 13.5px; color: #b3261e; }
.mail-err:empty { display: none; }
.mail-fine { margin: 0; font-size: 12px; color: var(--mute); }
.mail-fine a { color: inherit; }
@media (max-width: 640px) {
  .mail-card { grid-template-columns: 1fr; gap: 18px; padding: 22px 18px; }
  .mail-pic { max-width: 150px; }
}

/* the fun part: card pops up, fields come in one by one, doodle wiggles */
@media (prefers-reduced-motion: no-preference) {
  .mail[open] { animation: pop .42s cubic-bezier(.2, 1.3, .4, 1); }
  .mail[open]::backdrop { animation: fade .3s ease-out; }
  .mail[open] .mail-body > * { animation: rise .45s ease-out backwards; }
  .mail[open] .mail-body > :nth-child(2) { animation-delay: .05s; }
  .mail[open] .mail-body > :nth-child(3) { animation-delay: .1s; }
  .mail[open] .mail-body > :nth-child(4) { animation-delay: .15s; }
  .mail[open] .mail-body > :nth-child(5) { animation-delay: .2s; }
  .mail[open] .mail-body > :nth-child(n+6) { animation-delay: .25s; }
  .mail[open] .mail-pic { animation: tilt .6s cubic-bezier(.2, 1.4, .4, 1) .1s backwards; }
  .mail[open] .mail-body > .gift { animation: rise .3s ease-out; }
  .mail-card[data-step="done"] .mail-pic { animation: fly 1.1s cubic-bezier(.5, 0, .3, 1) forwards; }
}
@keyframes pop { from { opacity: 0; transform: translateY(24px) scale(.96); } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes tilt { from { opacity: 0; transform: rotate(-8deg) scale(.85); } }
@keyframes fly {
  30% { transform: rotate(-6deg) scale(.9); }
  100% { transform: translate(60px, -40px) rotate(10deg) scale(.55); opacity: .9; }
}

/* page colors you get by clicking the title. white boxes keep their own black ink */
html[data-tint] { --page-mute: #45403a; }
html[data-tint="matcha"] { --bg: #b7de74; }
html[data-tint="rhodochrosite"] { --bg: #e9b9b3; }
html[data-tint="lapis"] { --bg: #34497e; }
html[data-tint="orpiment"] { --bg: #ecd38f; }
html[data-tint="verdigris"] { --bg: #315c56; }
html[data-tint="almandine"] { --bg: #4a1e2b; }
html[data-tint="lapis"], html[data-tint="verdigris"], html[data-tint="almandine"] { --page-ink: #f7f2e8; --page-mute: #e6e0d3; }
.opts, .preview, .example, .board, .frame, .mail { --page-ink: var(--ink); --page-mute: var(--mute); color: var(--ink); }
button:not(.masthead), select { --page-ink: var(--ink); --page-mute: var(--mute); }

/* my little d up in the corner, scrolls away with the page */
.d-logo { position: absolute; top: 14px; left: max(16px, env(safe-area-inset-left, 0px)); width: auto; height: 34px; pointer-events: none; }

/* no copying text off the page, except the preview and your own typing */
body { -webkit-user-select: none; user-select: none; }
.preview, .readout, input, textarea, select { -webkit-user-select: text; user-select: text; }

/* studio spots. on phones the save/send stuff drops below frames + preview */
.studio { grid-template-areas: "draw side" "act side"; grid-template-rows: auto 1fr; row-gap: 14px; }
.studio > .pane:first-child { grid-area: draw; }
.studio > .pane:nth-child(2) { grid-area: side; }
.studio > .pane-act { grid-area: act; }
.studio[data-size="large"] { grid-template-areas: "draw" "act" "side"; grid-template-rows: auto; }
.studio[data-size="large"] > .pane:nth-child(2) { margin-top: 10px; }
@media (max-width: 820px) {
  .studio, .studio[data-size="large"] { grid-template-areas: "draw" "side" "act"; grid-template-rows: auto; row-gap: 24px; }
  .studio[data-size="large"] > .pane:nth-child(2) { margin-top: 0; }
}

/* phones: fat-finger friendly taps, and 16px fields so iOS doesn't zoom in */
@media (max-width: 820px) {
  button:not(#tint), select, .pick span, .field input { min-height: 44px; }
  .chips button { min-width: 44px; }
  .sizes button { width: 44px; height: 44px; }
  .top a { display: inline-block; padding: 12px 0; margin: -12px 0; }
  .speed input { height: 44px; }
  input, select, textarea, .field input, .field textarea { font-size: 16px; }
}
