:root {
  --tile: #c9d6cc;
  --steel-hi: #eef0ee;
  --steel-lo: #b4bab7;
  --steel-edge: #7f8784;
  --enamel: #17324d;
  --enamel-text: #f4f1e6;
  --text: #1d2422;
  --ink-sharpie: rgba(24, 23, 28, .92);
  --ink-ballpoint: rgba(26, 56, 165, .9);
  --ink-lipstick: rgba(186, 24, 54, .92);
  --ink-moss: rgba(20, 96, 54, .92);
  --ink-grape: rgba(98, 36, 140, .92);
  --ink-scratch: #fbfcf7;
  --ui: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --note-width: 340px;
  --kb: 0px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--tile);
  color: var(--text);
  font-family: var(--ui);
}

#wall {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overflow: clip; /* stops browsers scrolling the wall to chase the caret */
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background-color: var(--tile);
}
#wall.dragging { cursor: grabbing; }

#world {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
}

/* ---------- writing ---------- */
.note, #composer {
  position: absolute;
  transform-origin: 0 0;
  line-height: 1.12;
  --base: 30px;
  font-size: calc(var(--base) * var(--hand, 1));
}
.note {
  width: max-content;
  max-width: var(--note-width);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: pointer;
}
.s-s { --base: 21px; }
.s-m { --base: 30px; }
.s-l { --base: 48px; }

.f-marker { font-family: 'Permanent Marker', cursive; --hand: 1; }
.f-scrawl { font-family: 'Rock Salt', cursive; --hand: .78; line-height: 1.5; }
.f-pen    { font-family: 'Reenie Beanie', cursive; --hand: 1.45; line-height: .95; }
.f-neat   { font-family: 'Caveat', cursive; --hand: 1.2; }
.f-shaky  { font-family: 'Covered By Your Grace', cursive; --hand: 1.15; }

.c-sharpie   { color: var(--ink-sharpie); }
.c-ballpoint { color: var(--ink-ballpoint); }
.c-lipstick  { color: var(--ink-lipstick); }
.c-moss      { color: var(--ink-moss); }
.c-grape     { color: var(--ink-grape); }
.c-scratch   { color: var(--ink-scratch); text-shadow: 0 1px 0 rgba(40, 50, 45, .75), 0 -1px 0 rgba(40, 50, 45, .2); }

.note.fresh { animation: scrawl .55s ease-out; }
@keyframes scrawl {
  from { clip-path: inset(-20% 100% -20% -5%); }
  to   { clip-path: inset(-20% -5% -20% -5%); }
}
.note.gone { opacity: 0; transition: opacity .4s; }
.note.spot { animation: spot 1.6s ease-out; }
@keyframes spot {
  0%, 40% { filter: drop-shadow(0 0 7px rgba(255, 214, 64, .95)); }
  100% { filter: none; }
}

.flag {
  position: absolute;
  top: -22px;
  right: 0;
  display: none;
  padding: 1px 7px;
  border: 1px solid var(--steel-edge);
  border-radius: 3px;
  background: var(--steel-hi);
  color: var(--text);
  font: 500 14px/1.3 var(--ui);
  letter-spacing: .03em;
  text-shadow: none;
  cursor: pointer;
}
.flag:hover { background: #fff; }
.note.sel .flag { display: block; }
@media (hover: hover) { .note:hover .flag { display: block; } }

#composer { z-index: 5; transition: left .16s ease-out, top .16s ease-out; }
#composer[hidden] { display: none; }
#ink {
  display: block;
  width: var(--note-width);
  padding: 0;
  margin: 0;
  border: 0;
  outline: 1.5px dashed rgba(29, 36, 34, .45);
  outline-offset: 6px;
  border-radius: 2px;
  background: transparent;
  color: inherit;
  caret-color: currentColor;
  font: inherit;
  line-height: inherit;
  text-shadow: inherit;
  resize: none;
  overflow: hidden;
  overflow-wrap: anywhere;
}
#ink::placeholder { color: inherit; opacity: .45; }

/* ---------- the enamel sign ---------- */
.sign {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 16px;
  z-index: 10;
  padding: 7px 16px 8px;
  border: 2px solid var(--enamel-text);
  outline: 2px solid var(--enamel);
  border-radius: 6px;
  background: var(--enamel);
  color: var(--enamel-text);
  box-shadow: 0 2px 5px rgba(0, 0, 0, .35);
  pointer-events: none;
}
.sign h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .09em;
  line-height: 1.1;
  text-transform: uppercase;
}
.sign p {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .05em;
  opacity: .85;
}

#hint {
  position: fixed;
  top: 26px;
  left: 50%;
  z-index: 9;
  margin: 0;
  padding: 5px 12px;
  border-radius: 4px;
  background: rgba(23, 50, 77, .9);
  color: var(--enamel-text);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: .03em;
  white-space: nowrap;
  transform: translateX(-50%);
  transition: opacity .4s;
  pointer-events: none;
}
#hint.gone { opacity: 0; }

/* ---------- brushed steel fittings ---------- */
.controls, #tray {
  position: fixed;
  z-index: 10;
  border: 1px solid var(--steel-edge);
  border-radius: 7px;
  background: linear-gradient(170deg, var(--steel-hi), var(--steel-lo));
  box-shadow: 0 2px 6px rgba(0, 0, 0, .3), inset 0 1px 0 rgba(255, 255, 255, .8);
}
.controls {
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  gap: 6px;
  padding: 6px;
}

button {
  min-height: 40px;
  min-width: 40px;
  padding: 0 12px;
  border: 1px solid var(--steel-edge);
  border-radius: 4px;
  background: linear-gradient(#fafbfa, #d7dbd9);
  color: var(--text);
  font: 700 18px/1 var(--ui);
  letter-spacing: .03em;
  cursor: pointer;
}
button:hover { background: #fff; }
button:active { transform: translateY(1px); }
button.primary {
  border-color: var(--enamel);
  background: var(--enamel);
  color: var(--enamel-text);
}
button.primary:hover { background: #21476c; }
button:disabled { opacity: .55; cursor: default; }
:is(button, label):focus-visible, input:focus-visible + span {
  outline: 2px solid var(--enamel);
  outline-offset: 2px;
}

#tray {
  left: 50%;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + var(--kb));
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 8px 18px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 9px 14px 11px;
  transform: translateX(-50%);
}
#tray[hidden] { display: none; }
#tray fieldset {
  display: flex;
  gap: 5px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
#tray legend {
  padding: 0 0 3px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #48514e;
}
#tray label { position: relative; display: block; cursor: pointer; }
#tray input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.pick {
  display: grid;
  place-items: center;
  height: 38px;
  min-width: 38px;
  padding: 0 7px;
  border: 1px solid var(--steel-edge);
  border-radius: 4px;
  background: #f4f6f4;
  font-size: 22px;
  line-height: 1;
}
input:checked + .pick {
  border-color: var(--enamel);
  box-shadow: inset 0 0 0 2px var(--enamel);
  background: #fff;
}
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, .35);
}
#sizes .pick { font: 700 17px/1 var(--ui); }
#fonts .pick.f-pen { font-size: 29px; }
#fonts .pick.f-scrawl { font-size: 15px; }

.actions { display: flex; align-items: center; gap: 7px; }
#left {
  min-width: 2.2em;
  text-align: right;
  font-size: 17px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: #48514e;
}
#left.low { color: #a8142f; font-weight: 700; }

body.composing .controls { display: none; }
.short { display: none; }

#toast {
  position: fixed;
  top: 76px;
  left: 50%;
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 8px 14px;
  border-radius: 4px;
  background: var(--enamel);
  color: var(--enamel-text);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: .02em;
  text-align: center;
  transform: translateX(-50%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}
#toast[hidden] { display: none; }

@media (max-width: 720px) {
  .sign { padding: 5px 11px 6px; left: 12px; }
  .sign h1 { font-size: 18px; }
  .sign p { font-size: 13px; }
  #hint { top: auto; bottom: 76px; font-size: 16px; }
  #tray { width: calc(100vw - 16px); max-width: none; padding: 7px; gap: 6px 10px; justify-content: space-between; }
  #tray legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #tray fieldset { gap: 4px; }
  .pick { height: 34px; min-width: 34px; padding: 0 4px; font-size: 19px; }
  #fonts .pick.f-pen { font-size: 25px; }
  #fonts .pick.f-scrawl { font-size: 12px; }
  #sizes { order: 1; }
  #fonts { order: 2; }
  .actions { order: 3; margin-left: auto; }
  #left:not(.low) { display: none; }
  .actions button { min-height: 34px; padding: 0 10px; }
  .long { display: none; }
  .short { display: inline; }
}

@media (prefers-reduced-motion: reduce) {
  .note.fresh, .note.spot { animation: none; }
  .note.gone, #hint, #composer { transition: none; }
}
