/* bored — black marker on a blank white page */
:root {
  --ink: #111111;
  --paper: #ffffff;
  --muted: #9a9a9a;
  --faint: #d6d6d6;
  --marker: "Permanent Marker", "Comic Sans MS", cursive;
  --hand: "Gaegu", "Comic Sans MS", cursive;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-l: env(safe-area-inset-left, 0px);

  /* hand-drawn marker shapes */
  --blob: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 40' preserveAspectRatio='none'><path d='M3 7 C 18 2, 52 5, 97 3 C 99 13, 97 27, 98 36 C 72 39, 35 36, 2 38 C 1 27, 3 17, 3 7 Z' fill='%23111'/></svg>");
  --blob-open: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 40' preserveAspectRatio='none'><path d='M3 7 C 18 2, 52 5, 97 3 C 99 13, 97 27, 98 36 C 72 39, 35 36, 2 38 C 1 27, 3 17, 3 7 Z' fill='%23fff' stroke='%23111' stroke-width='3' vector-effect='non-scaling-stroke'/></svg>");
  --dot: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40' preserveAspectRatio='none'><path d='M20 2 C 31 1, 39 9, 38 20 C 39 31, 30 39, 19 38 C 8 39, 1 30, 2 19 C 2 9, 9 2, 20 2 Z' fill='%23111'/></svg>");
  --dot-open: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40' preserveAspectRatio='none'><path d='M20 3 C 31 2, 38 9, 37 20 C 38 31, 30 38, 19 37 C 8 38, 2 30, 3 19 C 3 9, 9 3, 20 3 Z' fill='%23fff' stroke='%23111' stroke-width='2.5' vector-effect='non-scaling-stroke'/></svg>");
  --frame: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'><path d='M2 3 C 30 1, 70 3, 98 2 C 99 30, 97 70, 98 98 C 70 99, 30 97, 2 98 C 1 70, 3 30, 2 3 Z' fill='none' stroke='%23111' stroke-width='3' vector-effect='non-scaling-stroke'/><path d='M4 1 C 40 4, 60 0, 97 4 M1 96 C 30 99, 70 96, 99 99' fill='none' stroke='%23111' stroke-width='1.5' vector-effect='non-scaling-stroke' opacity='.6'/></svg>");
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--marker);
}

body {
  position: fixed;
  inset: 0;
  height: 100dvh;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; padding: 0; }
button:focus-visible { outline: 2px dashed var(--ink); outline-offset: 4px; }

/* ---------- marker blobs ---------- */
.blob {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 16px;
  background: var(--blob) 0 0 / 100% 100% no-repeat;
  color: #fff;
  font-family: var(--marker);
  font-size: 15px;
  letter-spacing: .04em;
  line-height: 1;
  white-space: nowrap;
  transform: rotate(var(--r, 0deg));
  transition: transform .12s ease;
}
.blob:hover { transform: rotate(var(--r, 0deg)) translateY(-2px) scale(1.03); }
.blob:active { transform: rotate(var(--r, 0deg)) scale(.94); }
.blob:disabled { opacity: .25; cursor: default; transform: rotate(var(--r, 0deg)); }
.blob.round { width: 42px; padding: 0; background-image: var(--dot); font-size: 19px; font-family: system-ui, sans-serif; font-weight: 700; }

/* ---------- black tape (toasts, prompts, nudges) ---------- */
.tape {
  background: var(--ink);
  color: #fff;
  font-family: var(--marker);
  font-size: 14px;
  letter-spacing: .03em;
  padding: 8px 18px;
  clip-path: polygon(1.5% 6%, 30% 0, 62% 7%, 98.5% 2%, 100% 50%, 97.5% 96%, 64% 100%, 30% 93%, 2% 100%, 0 52%);
}

/* ---------- stage ---------- */
#stage { position: absolute; inset: 0; }
#board, #live { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#live { touch-action: none; cursor: crosshair; }
body[data-tool="text"] #live { cursor: text; }
body[data-tool="eraser"] #live { cursor: cell; }

#textInput {
  position: absolute;
  display: none;
  margin: 0;
  padding: 0 2px;
  min-width: 40px;
  border: none;
  border-bottom: 2px dashed currentColor;
  outline: none;
  background: transparent;
  resize: none;
  overflow: hidden;
  white-space: pre;
  font-family: var(--hand);
  font-weight: 700;
  line-height: 1.1;
  z-index: 5;
  -webkit-user-select: text;
  user-select: text;
}

.empty-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  pointer-events: none;
  transition: opacity .5s ease, transform .5s ease;
}
.empty-hint.gone { opacity: 0; transform: scale(.96); }
.empty-big { margin: 0; font-family: var(--hand); font-weight: 700; font-size: clamp(46px, 9vw, 96px); color: var(--faint); line-height: 1; transform: rotate(-2deg); }
.empty-small { margin: 10px 0 0; font-family: var(--hand); font-weight: 700; font-size: clamp(18px, 2.6vw, 24px); color: #c4c4c4; }

/* ---------- top bar ---------- */
.topbar {
  position: absolute;
  top: calc(12px + var(--safe-t));
  left: calc(16px + var(--safe-l));
  right: calc(16px + var(--safe-r));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; flex-direction: column; min-width: 0; }
.logo { display: block; width: 138px; height: auto; aspect-ratio: 324 / 144; overflow: visible; fill: none; stroke: var(--ink); stroke-width: 11; stroke-linecap: round; stroke-linejoin: round; }
.logo .ul { stroke-width: 7; }
.timer { margin: -2px 0 0 6px; font-family: var(--hand); font-weight: 700; font-size: 16px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.share-btn { --r: 3deg; position: relative; height: 46px; padding: 0 20px; font-size: 18px; margin-top: 4px; }
.share-btn .zap { position: absolute; right: -14px; top: -12px; width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; }
.share-btn.ready { animation: shake 1.1s ease 2; }
@keyframes shake {
  0%, 100% { transform: rotate(3deg); }
  20% { transform: rotate(-7deg) scale(1.08); }
  40% { transform: rotate(8deg) scale(1.08); }
  60% { transform: rotate(-4deg); }
  80% { transform: rotate(5deg); }
}

/* ---------- side actions ---------- */
.side {
  position: absolute;
  right: calc(18px + var(--safe-r));
  bottom: calc(22px + var(--safe-b));
  display: grid;
  gap: 8px;
  z-index: 10;
}
.side .blob:nth-child(2) { --r: 8deg; }
.side .blob:nth-child(3) { --r: -6deg; }
.side .blob:nth-child(4) { --r: 4deg; }

/* ---------- prompt tape ---------- */
.prompt-tape {
  position: absolute;
  top: calc(96px + var(--safe-t));
  left: 50%;
  max-width: min(92vw, 520px);
  font-size: 16px;
  text-align: center;
  transform: translate(-50%, -8px) rotate(-2deg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 9;
}
.prompt-tape.show { opacity: 1; transform: translate(-50%, 0) rotate(-2deg); }
.prompt-tape small { opacity: .6; margin-right: 6px; }

/* ---------- toolbar ---------- */
.toolbar {
  position: absolute;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 10;
}
.tool.active { background-image: var(--blob-open); color: var(--ink); }
.style-btn { width: 50px; padding: 0; }
.swatch-dot { width: 22px; height: 22px; border-radius: 50% 45% 55% 48%; border: 2.5px solid #fff; background: var(--ink); }
.style-btn.active .swatch-dot { border-color: var(--ink); }
.swatch-dot.rainbow, .swatch.rainbow { background: conic-gradient(#ff3b5c, #ff8a00, #ffd500, #22c55e, #3a86ff, #8338ec, #ff3b5c); }

/* ---------- popover ---------- */
.popover {
  position: absolute;
  left: 50%;
  bottom: calc(76px + var(--safe-b));
  transform: translateX(-50%) rotate(-.6deg);
  width: min(300px, calc(100vw - 32px));
  padding: 14px 16px 16px;
  background: var(--paper) var(--frame) 0 0 / 100% 100% no-repeat;
  z-index: 11;
  animation: pop .16s ease;
}
.popover[hidden] { display: none; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 6px) rotate(-.6deg) scale(.97); } }
.pop-label { margin: 0 0 8px; font-size: 13px; letter-spacing: .08em; }
.pop-label:not(:first-child) { margin-top: 14px; }
.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; }
.swatch {
  aspect-ratio: 1;
  border-radius: 50% 44% 54% 47% / 47% 54% 44% 50%;
  border: 2.5px solid var(--ink);
  transition: transform .1s;
}
.swatch:hover { transform: scale(1.12) rotate(-6deg); }
.swatch.active { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5.5px var(--ink); }
.sizes { display: flex; align-items: center; gap: 8px; }
.size {
  position: relative;
  flex: 1;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--blob-open) 0 0 / 100% 100% no-repeat;
}
.size i { width: var(--d); height: var(--d); border-radius: 50% 44% 54% 47%; background: var(--ink); }
.size.active { background-image: var(--blob); }
.size.active i { background: #fff; }
.custom-color { cursor: pointer; font-size: 22px; }
.custom-color input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

/* ---------- nudge ---------- */
.nudge {
  position: absolute;
  left: 50%;
  bottom: calc(80px + var(--safe-b));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 8px 20px;
  font-size: 15px;
  white-space: nowrap;
  transform: translate(-50%, 20px) rotate(-1.5deg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease, transform .3s cubic-bezier(.2, 1.4, .4, 1);
  z-index: 9;
}
.nudge.show { opacity: 1; transform: translate(-50%, 0) rotate(-1.5deg); pointer-events: auto; }
.nudge button { background: #fff; color: var(--ink); padding: 6px 12px; font-size: 14px; letter-spacing: .04em; clip-path: polygon(3% 8%, 96% 0, 100% 90%, 0 100%); }
.nudge .nudge-x { background: none; color: #fff; padding: 4px 6px; font-family: system-ui, sans-serif; font-weight: 700; }

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(255, 255, 255, .78);
  backdrop-filter: blur(2px);
  z-index: 50;
  animation: fade .2s ease;
}
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.modal-card {
  position: relative;
  width: min(520px, calc(100vw - 32px));
  min-width: 0;
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  background: var(--paper) var(--frame) 0 0 / 100% 100% no-repeat;
  transform: rotate(-.4deg);
  animation: rise .25s cubic-bezier(.2, 1.2, .4, 1);
}
@keyframes rise { from { transform: translateY(24px) rotate(-.4deg) scale(.97); opacity: 0; } }
.modal-card h2 { margin: 0; padding-right: 48px; font-size: 24px; font-weight: 400; letter-spacing: .02em; line-height: 1.1; }
.modal-close { position: absolute; top: 12px; right: 12px; --r: 6deg; }
.preview-wrap {
  min-height: 0;
  min-width: 0;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 6px;
  background: var(--frame) 0 0 / 100% 100% no-repeat;
  overflow: hidden;
}
#previewImg { display: block; max-width: 100%; max-height: 40dvh; object-fit: contain; }
.caption-row { display: flex; gap: 10px; align-items: stretch; }
#caption {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: none;
  background: var(--frame) 0 0 / 100% 100% no-repeat;
  font: 700 18px/1.2 var(--hand);
  color: var(--ink);
  resize: none;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.shuffle { --r: -4deg; width: 50px; height: auto; padding: 0; font-size: 22px; font-family: system-ui, sans-serif; font-weight: 700; }
.share-actions { display: flex; gap: 8px; }
.share-actions > * { min-width: 0; }
.btn span { overflow: hidden; text-overflow: ellipsis; }
.btn { flex: 1; height: 50px; padding: 0 12px; font-size: 15px; }
.btn:nth-child(1) { --r: -1deg; }
.btn:nth-child(2) { --r: 1deg; }
.btn .brand-ico { width: 18px; height: 18px; fill: currentColor; flex: none; }
.btn-save { flex: 0 0 auto; padding: 0 16px; background-image: var(--blob-open); color: var(--ink); --r: -2deg; }
.share-hint { margin: 0; min-height: 1.2em; font-family: var(--hand); font-weight: 700; font-size: 16px; line-height: 1.2; color: #777; text-align: center; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: calc(16px + var(--safe-t));
  max-width: calc(100vw - 32px);
  text-align: center;
  white-space: normal;
  transform: translate(-50%, calc(-100% - 40px)) rotate(-1deg);
  opacity: 0;
  z-index: 100;
  transition: transform .3s cubic-bezier(.2, 1.3, .4, 1), opacity .2s;
}
.toast.show { transform: translate(-50%, 0) rotate(-1deg); opacity: 1; }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .side { bottom: calc(80px + var(--safe-b)); right: calc(14px + var(--safe-r)); }
  .popover { bottom: calc(74px + var(--safe-b)); }
  .nudge { left: calc(14px + var(--safe-l)); bottom: calc(80px + var(--safe-b)); max-width: calc(100vw - 86px); transform: translateY(20px) rotate(-1.5deg); }
  .nudge.show { transform: translateY(0) rotate(-1.5deg); }
  .logo { width: 116px; }
}
@media (max-width: 420px) {
  .hide-xs { display: none; }
  .toolbar { gap: 4px; }
  .tool { height: 40px; padding: 0 9px; font-size: 12.5px; }
  .style-btn { width: 44px; }
  .blob.round { width: 40px; height: 40px; font-size: 17px; }
  .share-btn { height: 42px; padding: 0 16px; font-size: 16px; }
  .btn { font-size: 12.5px; padding: 0 8px; gap: 6px; height: 46px; }
  .btn .brand-ico { display: none; }
  .modal-card { padding: 16px 14px; }
  .btn-save { padding: 0 12px; }
  .nudge { font-size: 13px; gap: 8px; padding-left: 14px; }
  .nudge .nudge-x { display: none; }
}
@media (max-height: 520px) {
  #previewImg { max-height: 30dvh; }
  .modal-card { gap: 8px; padding: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .share-btn.ready { animation: none; }
  * { transition-duration: .01ms !important; }
}
