/* Light Detangler. Colours, type and brackets come from shared/tokens.css.
   The Start and Finish cards and the buttons come from shared/frame.css. */
html, body { margin: 0; height: 100%; background: var(--ink); overscroll-behavior: none; }
body {
  font-family: var(--font-sans);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }

#app {
  position: relative;
  max-width: 480px;
  height: 100vh; height: 100dvh;
  margin: 0 auto;
  background: var(--ink);
  overflow: hidden;
  touch-action: none;
}
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#stage.dragging { cursor: grabbing; }
#stage:focus { outline: none; }
#stage:focus-visible { outline: 3px solid var(--green); outline-offset: -3px; }
#safe { position: absolute; visibility: hidden; pointer-events: none; padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px); }

/* HUD: notepad chips over the dark room */
#hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; flex-wrap: nowrap; gap: 8px; align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 68px 0 12px;
  pointer-events: none;
}
.chip {
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 44px; padding: 0 14px;
  background: var(--paper); color: var(--ink);
  border-radius: var(--radius-button);
  font-family: var(--font-mono); font-weight: 600; font-size: 15px; letter-spacing: .04em;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.hud-sep { width: 2px; height: 18px; background: var(--hairline); }
.hud-tangles.clear { box-shadow: inset 0 -3px 0 var(--green); }
/* the HUD stays on one row down to 360px wide */
@media (max-width: 400px) {
  .chip { font-size: 13px; padding: 0 12px; gap: 8px; }
}

/* Hint: a notepad button bottom right, beside the power strip and below where any bulb can go */
.hint-btn {
  position: absolute; z-index: 3;
  right: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  width: 52px; height: 56px; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; border-radius: var(--radius-button);
  background: var(--paper); color: var(--ink); cursor: pointer;
  font-family: var(--font-mono); font-weight: 600; font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  touch-action: manipulation;
  animation: pop .35s cubic-bezier(.3, 1.4, .5, 1);
}
.hint-btn:active { transform: translateY(1px); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

.sound-btn {
  position: absolute; z-index: 5;
  top: calc(env(safe-area-inset-top, 0px) + 8px); right: 12px;
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border: 0; border-radius: var(--radius-button);
  background: var(--paper); color: var(--ink); cursor: pointer;
}
.sound-btn:focus-visible, .btn:focus-visible, .btn-secondary:focus-visible, .hint-btn:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }
.icon { display: block; background: currentColor; -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat; }
.icon-sound { width: 24px; height: 24px; --icon: url("art/icon-sound-off.svg"); }
.sound-btn[aria-pressed="true"] .icon-sound { --icon: url("art/icon-sound-on.svg"); }
.icon-hint { width: 22px; height: 22px; --icon: url("art/icon-hint.svg"); }
.icon-back { width: 24px; height: 24px; --icon: url("art/icon-back.svg"); }
/* back to the arcade: tap once for "Leave?", again to go */
#hud { flex-wrap: wrap; row-gap: 6px; }
.leave-btn { position: relative; flex: none; justify-content: center; width: 48px; padding: 0; text-decoration: none; pointer-events: auto; touch-action: manipulation; }
.leave-btn .leave-text { display: none; position: absolute; z-index: 6; left: 0; top: calc(100% + 6px); padding: 6px 10px; white-space: nowrap; border-radius: var(--radius-button); background: var(--paper); color: var(--ink); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.leave-btn.confirm { box-shadow: inset 0 0 0 3px var(--green); }
.leave-btn.confirm .leave-text { display: block; }
.leave-btn:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }
.card .btn-secondary { margin-top: 12px; }

/* Between levels: a notepad strip across the top, so the lit strand stays in view */
.between {
  position: absolute; z-index: 4; left: 12px; right: 68px;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  display: flex; align-items: center; gap: 12px;
  padding: 8px 8px 8px 16px;
  background: var(--paper); border-radius: var(--radius-card);
  animation: drop .4s cubic-bezier(.2, 1.2, .4, 1);
}
.between .bracket { width: 20px; height: 20px; }
.between .kicker { margin: 0; font-size: 12px; color: var(--ink-dark); }
.between-text { flex: 1; min-width: 0; }
.between-time { margin: 2px 0 0; font-family: var(--font-display); font-size: 26px; line-height: 1; }
.btn.btn-next { width: auto; min-width: 96px; min-height: 52px; font-size: 22px; padding: 0 16px; }
.between-buttons { display: flex; gap: 8px; }
.btn-secondary.btn-done { margin: 0; min-height: 52px; padding: 0 16px; border: 0; border-radius: var(--radius-button); cursor: pointer; touch-action: manipulation; }
/* Endless: Done sits beside Next, so the buttons take their own row under the text */
.between.endless { flex-wrap: wrap; row-gap: 8px; padding: 10px 10px 10px 16px; }
.between.endless .between-text { flex-basis: 100%; }
.between.endless .between-buttons { flex: 1; }
.between.endless .between-buttons > * { flex: 1; min-width: 0; }
@keyframes drop { from { transform: translateY(-120%); } }
/* on Next the strip lifts away while the lights go out */
.between.leaving { animation: lift .25s cubic-bezier(.5, 0, .8, .4) forwards; pointer-events: none; }
@keyframes lift { to { transform: translateY(-130%); } }
@keyframes fade-out { to { opacity: 0; } }
/* a back-to-arcade button in the HUD stays visible between levels; keep the strip clear of it */
#hud:has(.leave-btn) ~ .between { left: 68px; }

/* Start and finish screens */
.screen {
  position: absolute; inset: 0; z-index: 6;
  display: flex; align-items: safe center; justify-content: center;
  overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  padding: 24px 16px;
  background: var(--frame-backdrop);
  transition: opacity .25s ease;
}
.screen.closing { opacity: 0; pointer-events: none; }
/* Spiky on the Start card. Body art is 140 × 92 units; --u is one unit in px.
   Head: 100 units wide over x 20..120, chin on y 30. The knot centres on (73, 60). */
.host { --u: 1.25px; position: relative; width: calc(140 * var(--u)); height: calc(92 * var(--u) + 48.3 * var(--u)); margin: 12px auto 16px; }
.host img { position: absolute; display: block; }
.host-body { left: 0; bottom: 0; width: calc(140 * var(--u)); }
.host-head { left: calc(20 * var(--u)); top: 0; width: calc(100 * var(--u)); }
.host-end { --u: .72px; margin: 10px auto 8px; }
.host-tangle { width: calc(64 * var(--u)); left: calc((73 - 32) * var(--u)); top: calc((48.3 + 60 - 22.8) * var(--u)); }

#endScore .tenths { font-size: .55em; }

/* 5 / 10 / 15 / Endless switch on the Start card (from Cookie Rush's Classic / Cozy); Endless gets the wider slot */
.mode { display: grid; grid-template-columns: 1fr 1fr 1fr 1.9fr; gap: 4px; margin: 0 0 12px; padding: 4px; border-radius: var(--radius-button); background: var(--paper-under); }
.mode button { min-width: 44px; min-height: 44px; padding: 0 4px; border: 0; border-radius: var(--radius-button); background: transparent; color: var(--ink-dark); font-family: var(--font-mono); font-weight: 600; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; cursor: pointer; touch-action: manipulation; }
.mode button[aria-checked="true"] { background: var(--white); color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); }
.mode button:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }

/* High scores (from Snowbank Standoff): on this device, plus the opt-in public scoreboard */
.scores { margin: 26px 0 0; padding: 18px 0 0; border-top: 2px dashed var(--ink-light); }
.scores-title { margin: 0; font-size: 12px; font-weight: 600; color: var(--ink-dark); }
.hs-form { margin: 12px 0 0; padding: 14px 14px 12px; background: var(--white); border: 2px solid var(--ink); border-radius: var(--radius-button); }
.hs-new { margin: 0 0 6px; font-size: 13px; }
.hs-label { display: block; font-size: 15px; font-weight: 600; margin: 0 0 8px; }
.hs-row { display: flex; gap: 10px; justify-content: center; }
.hs-input {
  width: 132px; min-height: 52px; padding: 0 8px;
  font-family: var(--font-mono); font-weight: 600; font-size: 26px; letter-spacing: .35em; text-indent: .35em;
  text-align: center; text-transform: uppercase;
  color: var(--ink); background: var(--paper);
  border: 2.5px solid var(--ink); border-radius: var(--radius-button);
  -webkit-user-select: text; user-select: text; touch-action: manipulation;
}
.hs-input:focus { outline: none; box-shadow: 0 0 0 3px var(--green); }
.hs-input::placeholder { color: var(--ink-mid); }
.hs-save { width: auto; min-height: 52px; padding: 0 20px; font-size: 20px; }
.hs-err { margin: 8px 0 0; font-size: 14px; font-weight: 600; color: var(--ink-dark); }
.hs-share { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 44px; margin: 8px 0 0; font-size: 15px; font-weight: 600; cursor: pointer; }
.hs-share input { width: 22px; height: 22px; margin: 0; accent-color: var(--green); cursor: pointer; }
.hs-save:disabled { opacity: .5; cursor: progress; }
.hs { margin: 14px 0 0; }
.hs-tabs { display: flex; justify-content: center; gap: 6px; margin: 0 0 8px; }
.hs-tabs button {
  min-height: 44px; padding: 0 12px;
  font-family: var(--font-mono); font-weight: 600; font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-dark); background: transparent; border: 2px solid transparent; border-radius: var(--radius-button); cursor: pointer;
}
.hs-tabs button[aria-selected="true"] { color: var(--ink); border-color: var(--ink); }
.hs-tabs button:focus-visible, .hs-share input:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }
.hs-title { margin: 0 0 6px; font-size: 11px; color: var(--ink-dark); }
.hs-list { list-style: none; margin: 0 auto; padding: 0; max-width: 220px; font-family: var(--font-mono); font-weight: 600; font-size: 16px; }
.hs-list li { display: grid; grid-template-columns: 24px 1fr auto; gap: 8px; padding: 3px 8px; border-radius: var(--radius-button); text-align: left; }
.hs-list li .r { color: var(--ink-dark); }
.hs-list li .n { letter-spacing: .2em; }
.hs-list li.is-new { background: var(--green-lightest); box-shadow: inset 3px 0 0 var(--green); }
.hs-list li.empty { display: block; text-align: center; color: var(--ink-dark); font-family: var(--font-sans); font-weight: 500; font-size: 14px; }

.todo { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 20px 0 20px; font-size: 24px; font-weight: 700; }
.tickbox { position: relative; flex: none; width: 40px; height: 40px; }
.tickbox img { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.tick { clip-path: inset(0 100% 0 0); }
.todo.ticked .tick { animation: draw .45s .35s cubic-bezier(.3, .7, .3, 1) forwards; }
@keyframes draw { to { clip-path: inset(0 0 0 0); } }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .todo.ticked .tick { animation: none; clip-path: none; }
  .hint-btn, .between { animation: none; }
  .between.leaving { animation: fade-out .25s ease forwards; }
}

/* Shown for a moment when a dark bulb is tapped */
.nudge {
  position: absolute; z-index: 4; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 84px); transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px); margin: 0; padding: 10px 14px;
  background: var(--paper); color: var(--ink); border-radius: var(--radius-button);
  font-size: 15px; font-weight: 600; text-align: center; pointer-events: none;
}

/* Short phones (375 x 667): the Start card fits without scrolling */
:root { --frame-score: 72px; }
@media (max-height: 700px) {
  :root { --frame-score: 56px; }
  .host { --u: 1px; margin: 6px auto 10px; }
  .host-end { --u: .6px; margin: 2px auto 6px; }
  .mode { margin-bottom: 8px; }
  .card .tip { margin-top: 10px; font-size: 15px; }
  .card .btn-secondary { margin-top: 10px; }
}
