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

/* Knock on Wood: a woodworker's specimen wall in warm lamplight. The shelf (woods, ledges, brass plates) is one
   canvas (#wall); the index card, stamp, filing box and buttons are DOM so the text is real and crisp. */
:root {
  --font: "Geist", system-ui, -apple-system, sans-serif;
  --hand: "Caveat", "Bradley Hand", "Segoe Print", cursive;
  --ink: #efe6d2;
  --panel: rgba(20, 28, 25, 0.78);
  --line: rgba(240, 220, 180, 0.2);
  --cw: min(calc(100vw - 56px), 344px);
  --ln: 27px;
}

*,*::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); color: var(--ink); background: #0f1816; touch-action: none;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}
canvas#wall { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; touch-action: none; }

/* ------------------------------------------------------------ layout */
.stage {
  position: fixed; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; pointer-events: none;
  padding: calc(max(12px, env(safe-area-inset-top)) + 40px) max(14px, env(safe-area-inset-left)) calc(max(14px, env(safe-area-inset-bottom)) + 38px) max(14px, env(safe-area-inset-right));
}
.stage > * { pointer-events: auto; }
.desk { flex: none; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 7px; }
.shelf { flex: 1 1 0; min-height: 0; width: 100%; pointer-events: none; }
.boxrow { flex: none; position: relative; display: flex; align-items: center; justify-content: flex-end; gap: 10px; width: 100%; padding-left: 96px; height: 54px; margin-top: 6px; }

@media (orientation: landscape) and (min-width: 700px) {
  .stage {
    display: grid; grid-template-columns: clamp(262px, 31vw, 420px) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); align-items: start; column-gap: 16px;
    padding-top: calc(max(10px, env(safe-area-inset-top)) + 34px); padding-bottom: calc(max(14px, env(safe-area-inset-bottom)) + 60px);
  }
  .desk { grid-column: 1; grid-row: 1; min-width: 0; }
  .shelf { margin-bottom: 18px; }
  .shelf { grid-column: 2; grid-row: 1 / span 2; height: 100%; align-self: stretch; }
  .boxrow { grid-column: 1; grid-row: 2; align-self: start; justify-content: center; padding-left: 0; }
  :root { --cw: min(calc(31vw - 8px), 400px); }
}

/* ------------------------------------------------------------ the desk: a felt mat and one index card */
.mat {
  position: relative; padding: 13px; border-radius: 12px; width: calc(var(--cw) + 26px); flex: none;
  background:
    radial-gradient(120% 140% at 30% 0%, rgba(255, 233, 180, 0.13), transparent 60%),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.012) 0 2px, rgba(0,0,0,0.02) 2px 4px),
    linear-gradient(180deg, #1e3a30, #162b24);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 1px 0 rgba(255, 255, 255, 0.07) inset, 0 20px 36px -12px rgba(0, 0, 0, 0.75);
}
.mat::before { content: ""; position: absolute; inset: 13px; border-radius: 4px; border: 1.5px dashed rgba(240, 226, 196, 0.16); background: rgba(0, 0, 0, 0.12); }
.card {
  position: relative; width: var(--cw); aspect-ratio: 2.0; border-radius: 3px 3px 5px 5px; transform: rotate(-1.2deg);
  background:
    radial-gradient(90% 120% at 12% 0%, rgba(255, 255, 255, 0.55), transparent 55%),
    radial-gradient(60% 50% at 100% 100%, rgba(150, 120, 70, 0.14), transparent 70%),
    repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--ln) - 1px), rgba(74, 126, 190, 0.34) calc(var(--ln) - 1px), rgba(74, 126, 190, 0.34) var(--ln)) 0 31px / 100% 100% no-repeat,
    #f6efdc;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 2px 0 rgba(0, 0, 0, 0.12), 0 10px 18px -6px rgba(0, 0, 0, 0.65), 0 2px 5px rgba(0, 0, 0, 0.4);
  will-change: transform;
}
.card::before { content: ""; position: absolute; left: 0; right: 0; top: 30px; height: 1.5px; background: rgba(205, 70, 70, 0.55); }
.card__hdr {
  position: absolute; left: 12px; top: 8px; font: 600 9px/1 var(--font); letter-spacing: 0.3em; color: rgba(140, 120, 90, 0.7);
}
.card__text {
  position: absolute; left: 12px; right: 12px; top: 31px; height: calc(var(--ln) * 3 + 2px); margin: 0; padding: 0; border: 0; outline: none; resize: none; overflow: hidden;
  background: transparent; color: #1f2a52; font: 700 24px/var(--ln) var(--hand); letter-spacing: 0.01em;
  caret-color: #1f2a52; -webkit-user-select: text; user-select: text; touch-action: manipulation; border-radius: 3px;
  padding-top: 0; text-shadow: 0 0 0.4px rgba(31, 42, 82, 0.6);
}
.card__text::placeholder { color: rgba(31, 42, 82, 0.4); }
.card__text:focus { background: rgba(255, 255, 255, 0.28); box-shadow: 0 0 0 2px rgba(74, 126, 190, 0.35); }
.card__foot { position: absolute; left: 12px; right: 12px; bottom: 7px; height: 26px; display: flex; align-items: center; gap: 10px; }
.meter { position: relative; display: flex; align-items: center; gap: 6px; flex: none; }
.meter i { width: 12px; height: 12px; border-radius: 50%; border: 1.6px solid rgba(60, 60, 70, 0.4); background: transparent; transition: background 0.08s, border-color 0.08s, transform 0.14s cubic-bezier(.3,1.6,.5,1); }
.meter i.on { background: #2a2c3a; border-color: #2a2c3a; transform: scale(1.12); }
.meter b { position: absolute; left: 0; right: 0; bottom: -7px; height: 2px; border-radius: 2px; background: rgba(60, 60, 70, 0.14); overflow: hidden; opacity: 0; transition: opacity 0.15s; }
.meter b u { display: block; height: 100%; width: 100%; background: #c0453c; transform-origin: 0 50%; }
.meter.live b { opacity: 1; }
.meter.live b u { animation: fuse 2s linear forwards; }
@keyframes fuse { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.card__note { margin: 0; flex: 1; min-width: 0; font: 700 19px/1 var(--hand); color: #b3282e; transform: rotate(-1.5deg); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0; transition: opacity 0.2s; }
.card__note.show { opacity: 1; }

.stamp { position: absolute; left: 7%; width: 86%; top: 25%; opacity: 0; transform: rotate(-8deg); mix-blend-mode: multiply; pointer-events: none; }
.stamp.on { opacity: 0.9; }
.stamper { position: absolute; left: 50%; top: 38%; width: 34%; margin-left: -17%; transform-origin: 50% 100%; opacity: 0; pointer-events: none; z-index: 4; filter: drop-shadow(0 14px 8px rgba(0, 0, 0, 0.5)); }
.card.is-wobble { animation: wobble 0.9s ease-in-out; }
@keyframes wobble { 0%,100% { transform: rotate(-1.2deg); } 12% { transform: rotate(2.6deg) translateX(4px); } 28% { transform: rotate(-3.4deg) translateX(-5px); } 46% { transform: rotate(1.8deg) translateX(3px); } 64% { transform: rotate(-2deg) translateX(-2px); } 82% { transform: rotate(0.2deg); } }
.card.is-tick { animation: tick 0.18s ease-out; }
@keyframes tick { 0% { transform: rotate(-1.2deg) translateY(0); } 40% { transform: rotate(-1.5deg) translateY(2px); } 100% { transform: rotate(-1.2deg) translateY(0); } }

/* ------------------------------------------------------------ chips, hint */
.hint { margin: 2px 0 0; width: min(94vw, 460px); max-width: 100%; text-align: center; min-height: 1.5em; font-size: 0.62rem; font-weight: 600; letter-spacing: 0.13em; text-transform: uppercase; line-height: 1.5; color: rgba(240, 226, 196, 0.66); text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9); transition: opacity 0.25s; }
.hint.swap { opacity: 0; }
.chips { display: flex; gap: 8px; flex-wrap: nowrap; justify-content: center; }
.pill, .boxrow .opt-share.opt-share {
  appearance: none; cursor: pointer; font-family: var(--font); display: inline-flex; align-items: center; gap: 6px; height: 34px; margin: 0; padding: 0 12px 0 10px; white-space: nowrap;
  border-radius: 999px; font-size: 0.74rem; font-weight: 600; letter-spacing: 0.01em; opacity: 1; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 6px 14px rgba(0, 0, 0, 0.45); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease; touch-action: manipulation;
}
.pill svg { width: 14px; height: 14px; flex: none; }
.pill:hover, .boxrow .opt-share.opt-share:hover { background: rgba(40, 54, 48, 0.92); border-color: rgba(240, 220, 180, 0.4); text-decoration: none; }
.pill:active, .boxrow .opt-share.opt-share:active { transform: scale(0.96); }
.pill:focus-visible, .boxrow .opt-share.opt-share:focus-visible, .sound-btn:focus-visible, .box:focus-visible, .hit:focus-visible { outline: 2px dashed rgba(255, 224, 160, 0.95); outline-offset: 2px; }
.share-host { display: inline-flex; } .share-host:empty { display: none; }

/* ------------------------------------------------------------ the filing box */
.box { appearance: none; border: 0; padding: 0; background: none; cursor: pointer; position: relative; width: 132px; height: 52px; flex: none; touch-action: manipulation; font-family: var(--font); color: inherit; }
.box__cards { position: absolute; left: 8px; right: 8px; bottom: 30px; height: 20px; display: block; }
.box__cards i { position: absolute; bottom: 0; width: 38%; height: 18px; background: linear-gradient(180deg, #f6efdc, #ddd2b6); border-radius: 2px 2px 0 0; box-shadow: 0 0 0 0.5px rgba(0,0,0,.28), 0 -1px 0 rgba(255,255,255,.7) inset; }
.box__front {
  position: absolute; left: 0; right: 0; bottom: 0; height: 34px; border-radius: 3px 3px 6px 6px; display: grid; place-items: center;
  background:
    repeating-linear-gradient(90deg, rgba(90, 50, 18, 0.0) 0 11px, rgba(90, 50, 18, 0.18) 11px 12px, rgba(255, 220, 160, 0.07) 12px 14px, rgba(90, 50, 18, 0.0) 14px 31px),
    linear-gradient(180deg, #c99a5d 0%, #a97638 40%, #82541f 100%);
  box-shadow: 0 1px 0 rgba(255, 235, 190, 0.5) inset, 0 -2px 0 rgba(0,0,0,.25) inset, 0 8px 16px rgba(0, 0, 0, 0.6);
}
.plate {
  display: flex; align-items: baseline; gap: 7px; padding: 3px 9px 3px 8px; border-radius: 3px;
  background: linear-gradient(180deg, #e6c779, #b48a3b 55%, #cfa955); box-shadow: 0 1px 0 rgba(255, 245, 210, 0.7) inset, 0 -1px 0 rgba(70, 45, 8, .5) inset, 0 1px 2px rgba(0,0,0,.5);
  color: #3a2808; text-shadow: 0 1px 0 rgba(255, 240, 190, 0.55);
}
.plate small { font: 600 6.5px/1 var(--font); letter-spacing: 0.1em; }
.plate b { font: 600 17px/1 var(--font); font-variant-numeric: tabular-nums; display: inline-block; min-width: 1ch; }
.plate b.bump { animation: bump 0.4s cubic-bezier(.3,1.6,.5,1); }
@keyframes bump { 0% { transform: translateY(-9px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }

.peek { position: absolute; left: 50%; bottom: 62px; transform: translateX(-50%); width: 232px; z-index: 20; text-align: center; filter: drop-shadow(0 14px 20px rgba(0,0,0,.65)); }
.peek[hidden] { display: none; }
.peek__card {
  position: relative; min-height: 78px; padding: 14px 12px 10px; border-radius: 3px; transform: rotate(1.4deg); cursor: pointer;
  background: repeating-linear-gradient(to bottom, transparent 0, transparent 21px, rgba(74,126,190,.3) 21px, rgba(74,126,190,.3) 22px) 0 10px / 100% 100% no-repeat, #f6efdc;
}
.peek__t { margin: 0; font: 700 20px/22px var(--hand); color: #1f2a52; text-align: left; position: relative; z-index: 1; overflow-wrap: anywhere; }
.peek__stamp { position: absolute; right: 8px; bottom: 6px; font: 800 12px/1 var(--font); letter-spacing: 0.14em; color: #c0212b; border: 2px solid #c0212b; border-radius: 3px; padding: 3px 5px; transform: rotate(-9deg); opacity: 0.8; mix-blend-mode: multiply; z-index: 2; }
.peek__n { margin: 6px 0 0; font: 600 9px/1 var(--font); letter-spacing: .16em; text-transform: uppercase; color: rgba(240,226,196,.8); text-shadow: 0 1px 6px #000; }

/* ------------------------------------------------------------ knock targets over the shelf */
.hits { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
.hit { position: absolute; appearance: none; border: 0; padding: 0; margin: 0; background: transparent; cursor: pointer; pointer-events: auto; touch-action: none; border-radius: 6px; -webkit-tap-highlight-color: transparent; }

/* ------------------------------------------------------------ chrome */
.sound-btn {
  appearance: none; position: fixed; z-index: 12; cursor: pointer; padding: 0; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right));
  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 6px 16px rgba(0, 0, 0, 0.45); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); transition: transform 0.12s ease, opacity 0.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; }
.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(240, 226, 196, 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(max(12px, env(safe-area-inset-top)) + 13px); left: max(18px, env(safe-area-inset-left)); }
.frame__corner--tr { top: calc(max(12px, env(safe-area-inset-top)) + 13px); right: calc(max(12px, env(safe-area-inset-right)) + 54px); }
.frame__corner--bl { bottom: max(18px, env(safe-area-inset-bottom)); left: max(18px, env(safe-area-inset-left)); }
.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: rgba(255, 236, 190, 0.98); border-bottom-color: rgba(255, 236, 190, 0.5); }
.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: 380px) { :root { --cw: min(calc(100vw - 44px), 330px); } .pill, .boxrow .opt-share.opt-share { font-size: 0.7rem; padding: 0 10px 0 8px; } .chips { gap: 6px; } }
@media (orientation: landscape) and (max-height: 500px) and (min-width: 700px) {
  :root { --ln: 24px; }
  .card__text { font-size: 21px; }
  .hint { font-size: 0.56rem; letter-spacing: 0.1em; }
  .pill, .boxrow .opt-share.opt-share { height: 30px; font-size: 0.68rem; padding: 0 9px 0 8px; }
  .boxrow { height: 50px; margin-top: 2px; gap: 8px; }
  .mat { padding: 9px; width: calc(var(--cw) + 18px); }
  .mat::before { inset: 9px; }
  .desk { gap: 5px; }
}
@media (prefers-reduced-motion: reduce) {
  .card.is-wobble, .card.is-tick { animation: none; }
  .meter.live b u { animation-duration: 2s; }
  .plate b.bump { animation: none; }
  .pill, .sound-btn, .hint { transition: none; }
}

/* short phones in portrait (375x667): a slimmer card so the shelf keeps room */
@media (orientation: portrait) and (max-height: 740px) {
  :root { --cw: min(calc(100vw - 64px), 300px); --ln: 24px; }
  .card { aspect-ratio: 2.2; }
  .card__text { font-size: 21px; }
  .mat { padding: 8px; width: calc(var(--cw) + 16px); }
  .mat::before { inset: 8px; }
  .desk { gap: 5px; }
  .pill, .boxrow .opt-share.opt-share { height: 30px; font-size: 0.7rem; }
  .boxrow { height: 46px; margin-top: 2px; }
  .stage { padding-top: calc(max(12px, env(safe-area-inset-top)) + 36px); }
}
