/* Sketchy.
 *
 * Chrome is dark, the sheet is light — the drawing should be the brightest thing
 * on the screen. Layout rules inherited from the rest of the ecosystem: on a phone
 * nothing scrolls, the page is one viewport tall, and the controls slide up as a
 * sheet over the sheet rather than pushing it around. On a wide screen those same
 * controls sit in a band under the top bar, with the explainer first.
 *
 * The tabs are the whole interaction model: only the Draw tab paints, the rest
 * select or adjust. That is why there is no separate mode switch to hunt for.
 *
 * `user-select: none` on the controls is deliberate: tapping a shape on a phone
 * must not start a text selection, and a long press on the canvas must never open
 * the selection handles mid-stroke.
 */

[hidden] { display: none !important; }

* { box-sizing: border-box; }

:root {
  --bg: #0b0d16;
  --panel: #141726;
  --panel-2: #1c2033;
  --line: #2a2f47;
  --ink: #e8ecf5;
  --ink-dim: #9aa3bd;
  --accent: #d8b48c;
  --accent-ink: #241a10;
  --select: #7ef0d0;
  --danger: #e08a7a;
  --radius: 12px;
  --topbar-h: 52px;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body.sketchy {
  display: grid;
  /* Named bands, because the order differs by device: the controls sit under the top
     bar on a wide screen and *below* the artwork on a phone. Either way the stage row
     is `1fr`, so the sheet absorbs whatever the controls leave and the whole artwork
     is always on screen — the controls can never cover it. */
  grid-template-rows: var(--topbar-h) auto 1fr;
  grid-template-areas: "top" "controls" "stage";
  height: 100dvh;
}

/* ------------------------------------------------------------------ topbar -- */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  user-select: none;
  -webkit-user-select: none;
}
.home-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  color: var(--ink-dim);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}
.home-btn:hover { color: var(--ink); border-color: var(--accent); }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-mark { color: var(--accent); font-size: 20px; line-height: 1; }
.brand-text { display: flex; flex-direction: column; font-weight: 600; letter-spacing: .01em; }
.brand-text small {
  font-weight: 400; font-size: 11px; color: var(--ink-dim);
  letter-spacing: .06em; text-transform: lowercase;
}
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

button.ghost {
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
button.ghost:hover { border-color: var(--accent); }
button.ghost:disabled { opacity: .4; cursor: not-allowed; border-color: var(--line); }
.panel-toggle { display: none; }

/* ---------------------------------------------------------------- controls -- */
.controls {
  grid-area: controls;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  /* At most half the viewport: the artwork is the point, the controls are the
     instrument panel. The panels scroll internally instead of growing. */
  max-height: 50vh;
  user-select: none;
  -webkit-user-select: none;
}

.explain { flex: none; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.explain-lead { margin: 0; max-width: 88ch; color: var(--ink-dim); }
.explain-lead strong { color: var(--ink); }
.link-btn {
  flex: none;
  padding: 4px 10px;
  font: inherit;
  font-size: 12.5px;
  color: var(--accent);
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.link-btn:hover { border-color: var(--accent); }
.mode-hint {
  flex: none;
  padding: 3px 10px;
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 999px;
}

.howto {
  flex: none;
  display: none;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink-dim);
}
.howto.is-open { display: block; }
.howto ul { margin: 0; padding-left: 18px; display: grid; gap: 7px; max-width: 100ch; }
.howto strong { color: var(--ink); }
.howto em { color: var(--accent); font-style: normal; }
.howto kbd {
  padding: 1px 5px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 12px;
  color: var(--ink);
}

/* -------------------------------------------------------------------- tabs -- */
.tabs {
  flex: none;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--line);
  -webkit-overflow-scrolling: touch;
}
.tab {
  flex: none;
  padding: 7px 14px 9px;
  font: inherit;
  font-size: 13px;
  color: var(--ink-dim);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.panel { display: none; flex-direction: column; gap: 10px; }
/* Only the open panel scrolls, so the explainer and the tabs stay put. */
.panel.is-active { display: flex; flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.panel-hint { margin: 0; max-width: 92ch; font-size: 13px; color: var(--ink-dim); }
.empty-note { margin: 0; padding: 10px 2px; font-size: 13px; color: var(--ink-dim); }

.control-row { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.row-label {
  flex: none;
  width: 62px;
  padding-top: 8px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.stack { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn {
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.btn.subtle {
  color: var(--ink);
  background: var(--panel-2);
  border-color: var(--line);
}
.btn.subtle:hover, .btn:hover { filter: brightness(1.08); }
.btn.danger { color: #2a1410; background: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* -------------------------------------------------------------- the brushes -- */
/* The group label and its buttons share one flowing line, so "Shapes" and
   "Texture" do not each cost a whole row of the control band. */
.brushes { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.brush-group {
  flex: none;
  margin-right: 2px;
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  opacity: .65;
}
.brush-row { display: contents; }
.brush-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px 6px 8px;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.brush-btn svg { width: 18px; height: 18px; flex: none; stroke: var(--accent); }
.brush-btn:hover { border-color: var(--accent); }
.brush-btn.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.brush-btn.is-active svg { stroke: var(--accent-ink); }

/* -------------------------------------------------------------- the palettes -- */
.palettes { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.palette-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px 5px 6px;
  font: inherit;
  font-size: 11.5px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
}
.palette-chip:hover { border-color: var(--accent); }
.palette-chip.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.palette-strip { display: block; flex: none; width: 34px; height: 16px; border-radius: 5px; }
.palette-label { color: var(--ink-dim); white-space: nowrap; }
.palette-chip.is-active .palette-label { color: var(--ink); }

.drift { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-dim); }
.drift input { accent-color: var(--accent); width: 18px; height: 18px; }

/* --------------------------------------------------------------- the colours -- */
.colour-controls { flex: 1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.colour-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 8px;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.colour-btn:hover { border-color: var(--accent); }
.colour-chip {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, .35);
  display: inline-block;
}
.swatches { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 6px;
  cursor: pointer;
}
.swatch:hover { transform: translateY(-1px); }

/* --------------------------------------------------------------- the sliders -- */
.sliders { gap: 18px; }
.slider { display: flex; flex-direction: column; gap: 6px; min-width: 150px; flex: 1; }
.slider > span, .field > span, .field-label {
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.slider output { color: var(--ink); }
.slider input[type="range"], .field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 26px;
}

/* ------------------------------------------------------------ the elements -- */
.element-list { display: flex; flex-direction: column; gap: 6px; max-height: 34vh; overflow-y: auto; }
.element-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.element-row.is-active { border-color: var(--select); box-shadow: 0 0 0 1px var(--select) inset; }
.element-pick {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 6px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
}
.el-icon {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  font-size: 13px;
  color: var(--accent);
}
.el-icon svg { width: 20px; height: 20px; stroke: var(--accent); fill: none; }
.el-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.element-del {
  flex: none;
  width: 34px;
  height: 34px;
  font-size: 15px;
  color: var(--ink-dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}
.element-del:hover { color: var(--danger); border-color: var(--danger); }
.switch { flex: none; display: flex; align-items: center; padding: 0 2px; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------------------------------------------------------------- stencil -- */
.chip-row { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 7px 12px;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.cutout-prompt {
  padding: 10px 12px;
  background: rgba(224, 138, 122, .12);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
}
.cutout-prompt p { margin: 0 0 8px; font-size: 13px; color: var(--ink); }

/* ------------------------------------------------------------------ frame -- */
/* Every tile is the same shape: a fixed 7:5 preview with its name underneath. The
   previews are drawn by the same library that draws the real frame, so a tile cannot
   flatter a design it will not deliver. */
.border-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  align-content: start;
}
.border-cell {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  padding: 6px;
  font: inherit;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  overflow: hidden;
}
.border-cell canvas {
  display: block;
  width: 100%;
  aspect-ratio: 7 / 5;
  height: auto;
  border-radius: 6px;
}
.border-cell:hover { border-color: var(--accent); }
.border-cell.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.border-label {
  display: block;
  width: 100%;
  font-size: 10.5px;
  line-height: 1.2;
  color: var(--ink-dim);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.border-cell.is-active .border-label { color: var(--ink); }
.border-cell.is-plain { justify-content: center; }
/* the "no frame" tile is the same size as the rest, so the grid stays even */
.border-cell.is-plain canvas { opacity: .25; }

/* ------------------------------------------------------- the line preview -- */
.line-preview {
  flex: none;
  padding: 3px 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.line-preview canvas { display: block; width: 150px; height: 34px; border-radius: 6px; }

/* ---------------------------------------------------- element thumbnails -- */
.el-thumb {
  flex: none;
  display: block;
  width: 54px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
}

/* -------------------------------------------------------- the save dialog -- */
.save-card { width: min(460px, 100%); }
.save-note { font-size: 12px; color: var(--ink-dim); }
.save-cloud { display: flex; flex-direction: column; gap: 9px; margin: 12px 0 4px; }
#artwork-name {
  width: 100%;
  padding: 9px 11px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.artwork-when { flex: none; font-size: 11px; color: var(--ink-dim); padding-right: 4px; }
.frame-margin { min-width: 220px; }

/* a fixable paper, and a nudge when someone tries to change it anyway */
.format-chip:disabled { opacity: .42; cursor: not-allowed; }

/* Full screen. The Fullscreen API is the real thing where it exists; where it does not
   (iPhone Safari, or a refusal), the app fills the window itself rather than leaving
   the button dead. */
body.sketchy.is-immersive { grid-template-rows: 1fr; grid-template-areas: "stage"; }
body.is-immersive .topbar, body.is-immersive .controls { display: none; }
.immersive-exit { display: none; }
body.is-immersive .immersive-exit {
  display: block;
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: 10px;
  z-index: 40;
  padding: 9px 13px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: rgba(20, 23, 38, .86);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
#format-note.is-shake { animation: note-shake .6s ease-in-out; color: var(--accent); }
@keyframes note-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

/* ----------------------------------------------------------------- canvas -- */
.format-row { flex: 1; display: flex; flex-wrap: wrap; gap: 8px; }
.format-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  width: 74px;
  padding: 8px 4px 6px;
  font: inherit;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.format-chip:hover { border-color: var(--accent); }
.format-chip.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.format-box { display: block; background: var(--accent); border-radius: 3px; opacity: .8; }
.format-label { font-size: 11px; color: var(--ink-dim); }
.format-chip.is-active .format-label { color: var(--ink); }

/* ------------------------------------------------------------- text fields -- */
#text-content, #text-font {
  width: 100%;
  padding: 9px 11px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
#text-content { resize: vertical; min-height: 46px; }
.field-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 120px; }
.field.grow { flex: 1; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented button {
  padding: 7px 12px;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink-dim);
  background: var(--panel-2);
  border: none;
  border-right: 1px solid var(--line);
  cursor: pointer;
}
.segmented button:last-child { border-right: none; }
.segmented button:hover { color: var(--ink); }
.segmented button.is-active { color: var(--accent-ink); background: var(--accent); }
.rot-out { font-size: 13px; color: var(--ink); min-width: 44px; text-align: right; }

/* ----------------------------------------------------------------- the sheet -- */
.stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  min-height: 0;
}
#canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;          /* a stroke must never scroll the page */
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
body[data-mode="select"] #canvas,
body[data-mode="adjust"] #canvas { cursor: default; }
body[data-mode="move"] #canvas { cursor: grabbing; }

/* The mark-size meter. It sat bottom-right and was too small to read on a phone;
   it is now a legible gauge in the top-left, clear of the selection bar. */
.speed-meter {
  position: absolute;
  left: 12px;
  top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 13px;
  background: rgba(11, 13, 22, .74);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  backdrop-filter: blur(6px);
  pointer-events: none;
  /* It only matters mid-stroke, and over a wide sheet it sits on the paper, so it
     recedes when idle instead of ticking away in the corner of the drawing. */
  opacity: .5;
  transition: opacity .28s ease-out;
}
.speed-meter.is-live { opacity: 1; }
.speed-label { color: var(--ink); }
.speed-track {
  width: 150px;
  height: 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.speed-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width .06s linear;
}

/* ---------------------------------------------------------- the select bar -- */
.selectbar {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--panel-2);
  border: 1px solid var(--select);
  border-radius: 14px;
  user-select: none;
  -webkit-user-select: none;
}
.selectbar-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.selectbar-name { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selectbar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.nudge { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.nudge button {
  width: 44px;
  height: 40px;
  font-size: 16px;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}
.nudge button:hover { border-color: var(--accent); }
.selectbar-actions .btn { padding: 10px 13px; }

/* ------------------------------------------------------------ colour popup -- */
.colour-popup {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(6, 8, 14, .72);
  backdrop-filter: blur(3px);
}
.colour-popup.is-open { display: flex; }
.colour-card {
  width: min(330px, 100%);
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
  user-select: none;
  -webkit-user-select: none;
}
.colour-card h2 { margin: 0 0 12px; font-size: 14px; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-dim); }
.wheel-float { position: relative; width: 200px; height: 200px; margin: 0 auto; touch-action: none; cursor: crosshair; }
#wheel { width: 200px; height: 200px; border-radius: 50%; display: block; }
.wheel-marker {
  position: absolute;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .5);
  pointer-events: none;
}
.wheel-bar {
  position: relative;
  height: 18px;
  margin: 14px 0 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #111 0%, #fff 100%);
  border: 1px solid var(--line);
  cursor: pointer;
  touch-action: none;
}
.wheel-bar-fill {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: 50%;
  width: 6px;
  margin-left: -3px;
  border-radius: 3px;
  background: var(--ink);
  border: 1px solid rgba(0, 0, 0, .6);
  pointer-events: none;
}
.popup-swatches { justify-content: center; margin-bottom: 12px; }
.colour-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wheel-preview { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); }

/* ------------------------------------------------------------------- 404 -- */
body.plain { display: block; overflow: auto; background: var(--bg); }
.notfound { max-width: 520px; margin: 18vh auto 0; padding: 0 20px; text-align: center; }
.notfound h1 { font-size: 22px; margin-bottom: 6px; }
.notfound p { color: var(--ink-dim); }

/* ------------------------------------------------------------------ phone -- */
@media (max-width: 900px) {
  body.sketchy { grid-template-rows: var(--topbar-h) 1fr auto; }
  .panel-toggle { display: inline-block; }
  /* Every action has to fit beside the Controls button on a 412px phone, and the
     Controls button is the only way into the panel — it must never be the one that
     gets pushed off the edge. */
  .topbar { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .brand-text { display: none; }
  .brand-mark { font-size: 22px; }
  button.ghost, .home-btn { padding: 7px 10px; font-size: 12.5px; }
  /* Icon-only: the title attributes carry the names, and the words stop competing
     with the artwork for width. */
  .btn-text { display: none; }
  .topbar-actions .ghost { font-size: 17px; line-height: 1; }

  /* On a phone the panel is a band *below* the artwork rather than a sheet over it:
     it can take half the screen at most, and the stage takes the rest, so the whole
     sheet stays visible while you work. */
  .controls {
    display: none;
    max-height: 50dvh;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    border-bottom: none;
    border-radius: 16px 16px 0 0;
    overflow-y: auto;
  }
  .controls.is-open { display: flex; }
  body.sketchy { grid-template-areas: "top" "stage" "controls"; }
  /* Six tabs have to fit 412px without horizontal scrolling, or the Canvas tab
     (formats, paper, palettes) is easy to miss. */
  .tabs { position: sticky; top: 0; z-index: 2; background: var(--panel); }
  .tab { padding: 7px 9px 9px; font-size: 12.5px; }
  .panel.is-active { flex: none; overflow: visible; }

  .row-label { width: 100%; padding-top: 0; }
  .control-row { gap: 8px; }
  .sliders { gap: 14px; }
  .slider { min-width: 100%; }
  /* bigger touch targets: a fingertip is not a mouse pointer */
  .slider input[type="range"], .field input[type="range"] { height: 34px; }
  .brush-btn .brush-name { display: none; }
  .brush-btn { padding: 10px; }
  .brushes { display: block; }
  .brush-group { display: block; margin: 4px 0 5px; }
  .brush-row {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .palette-chip { padding: 7px 10px 7px 6px; }
  .element-list { max-height: 46vh; }
  .element-pick { padding: 11px 6px; }
  .element-del { width: 40px; height: 40px; }
  .chip { padding: 10px 14px; }
  .btn { padding: 11px 15px; }
  .swatch { width: 28px; height: 28px; }
  .line-preview canvas { width: 120px; height: 30px; }
  .el-thumb { width: 60px; height: 40px; }
  .colour-btn { padding: 9px 14px 9px 9px; }

  /* The gauge is the one readout you look at while drawing, so it grows here. */
  .speed-meter { left: 10px; top: 10px; padding: 9px 14px; font-size: 12.5px; gap: 10px; }
  .speed-track { width: 132px; height: 12px; }
  .speed-label { font-size: 12px; }

  .selectbar { padding: 9px; }
  .nudge { width: 100%; }
  .nudge button { width: 100%; height: 46px; }
  .border-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
}
