/* How Things Work: layout on top of /tree/tree.css. Uses the kt tokens only.
   The canvas is z-index 0 (styles.css puts every canvas at 1); every panel is above it. */

.kt-stage canvas { position: relative; z-index: 0; cursor: pointer; }
.kt-stage canvas.drag { cursor: ns-resize; }

/* top left: where you are, the title, Play or How does it work */
.htw-brand { left: 14px; top: calc(var(--kt-top) + 12px); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.htw-brand .kt-title b { font-size: 32px; }
.htw-modes { width: 100%; }
.htw-modes button { min-height: 38px; font-size: 14px; font-weight: 600; }
.htw-modes button[aria-pressed="true"] { background: var(--kt-accent); color: var(--kt-accent-ink); }

/* top right: the buttons */
.htw-actions { right: 14px; top: calc(var(--kt-top) + 12px); display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 27vw; }
.htw-actions .kt-btn { min-height: 38px; font-size: 14px; }
.htw-actions .kt-btn[aria-pressed="true"] { background: var(--kt-accent); color: var(--kt-accent-ink); border-color: transparent; }
.htw-actions #foundTxt { font: 600 12px var(--kt-mono); color: inherit; opacity: .8; }

/* bottom: the controls sheet (Play) or the step card (How does it work) */
.htw-sheet, .htw-step { left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--kt-bottom-inset)); width: min(820px, calc(100vw - 28px)); padding: 12px 14px; }
.htw-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }
.htw-row + .htw-row { margin-top: 8px; }
.htw-ctl { min-height: 44px; font-size: 15px; font-weight: 600; gap: 8px; touch-action: none; user-select: none; -webkit-user-select: none; }
.htw-ctl kbd, .htw-dial kbd, .htw-chip kbd { font: 600 11px var(--kt-mono); padding: 2px 6px; border-radius: 6px; background: rgba(0, 0, 0, .22); color: inherit; opacity: .75; }
.kt-btn.primary kbd { background: rgba(0, 0, 0, .14); }
.htw-dial { display: flex; flex-direction: column; gap: 2px; min-width: 190px; flex: 1; max-width: 300px; font-size: 14px; font-weight: 600; }
.htw-dial .t { display: flex; align-items: center; gap: 6px; }
.htw-dial b { font-size: 16px; color: var(--kt-warm); }
.htw-dial .kt-range { height: 34px; accent-color: var(--kt-warm); }
.htw-choice { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.htw-choice > .t { font: 600 11px/1.2 var(--kt-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--kt-dim); }
.htw-choice .opts { display: flex; flex-wrap: wrap; gap: 6px; }
.htw-chip { min-height: 36px; font-size: 14px; gap: 6px; }
.htw-chip.wrong { border-style: dashed; }
.htw-chip[aria-pressed="true"] { background: var(--kt-warm); color: #2a1c00; border-color: transparent; }

.htw-step { display: flex; flex-direction: column; gap: 8px; }
.htw-step .kt-kicker { display: flex; justify-content: space-between; align-items: center; }
.htw-step h2 { margin: 0; font-size: 22px; line-height: 1.15; }
.htw-step p { margin: 0; font-size: 16px; line-height: 1.45; }
.htw-dots { display: flex; gap: 5px; }
.htw-dots button { width: 30px; height: 26px; border-radius: 8px; border: 1px solid var(--kt-line); background: var(--kt-faint); cursor: pointer; font: 600 12px var(--kt-mono); color: var(--kt-dim); padding: 0; }
.htw-dots button[aria-current="step"] { background: var(--kt-accent); color: var(--kt-accent-ink); border-color: transparent; }
.htw-nav { display: flex; gap: 8px; }
.htw-nav .kt-btn { min-height: 44px; font-size: 16px; }
.htw-nav #nextBtn { flex: 1; font-weight: 700; }

/* cards, parts list, quiz */
/* desktop: the card sits under the brand, top left, so it stays off the picture's column; phone: full width at the bottom */
.kt-card { left: 16px; right: auto; z-index: 22; top: calc(var(--kt-top) + var(--htw-top, 150px) + 10px); bottom: auto; max-height: calc(100vh - var(--kt-top) - var(--htw-top, 150px) - 40px - var(--kt-bottom-inset)); }
.kt-card .does { font-weight: 600; color: var(--kt-accent); }
.kt-card .htw-sayrow { margin: -4px 0 8px; }
.kt-card .htw-sayrow .kt-btn { min-height: 30px; font-size: 12px; }
.htw-parts { display: flex; flex-wrap: wrap; gap: 6px; }
.htw-parts .kt-btn { min-height: 32px; font-size: 12px; padding: 0 10px; }
.htw-parts .kt-btn.new::after { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--kt-warm); margin-left: 2px; }
.kt-modal h3 .htw-say { margin-left: 8px; vertical-align: middle; min-height: 28px; font-size: 12px; }
.htw-how li, .kt-modal ul li { margin: 0 0 8px; line-height: 1.5; font-size: 15px; }
.htw-quiz .q { font-size: 19px; font-weight: 600; margin: 10px 0 14px; }
.htw-quiz .opt { display: block; width: 100%; text-align: left; margin: 0 0 8px; padding: 12px 14px; min-height: 48px; border-radius: 12px; border: 1px solid var(--kt-line); background: var(--kt-glass); cursor: pointer; font-size: 15px; }
.htw-quiz .opt.right { border-color: var(--kt-good); background: rgba(94, 224, 138, .18); }
.htw-quiz .opt.wrong { border-color: var(--kt-bad); background: rgba(255, 93, 108, .16); }
.htw-quiz .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 8px; }
.kt-toasts { top: calc(var(--kt-top) + 14px); left: 44%; z-index: 36; }
.kt-toast.warn { border-color: var(--kt-warn); }

@media (min-width: 1800px) and (min-height: 1000px) { .htw-brand, .htw-actions, .htw-sheet, .htw-step, .kt-card { zoom: 1.25; } }

/* phone: a slim brand up top, the actions become a scrolling row inside the sheet */
@media (max-width: 900px) {
  .htw-brand { left: 8px; right: 8px; max-width: none; padding: 7px 10px; gap: 6px; flex-direction: row; align-items: center; flex-wrap: nowrap; }
  .htw-brand .kt-kicker { display: none; }
  .htw-brand .kt-title { margin: 0; flex: 1; min-width: 0; font-size: 0; overflow: hidden; }
  .htw-brand .kt-title b { font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .htw-modes { width: auto; flex: none; }
  .htw-modes button { min-height: 34px; font-size: 12.5px; white-space: nowrap; padding: 0 9px; }
  .htw-actions { left: 8px; right: 8px; top: auto; bottom: calc(8px + var(--kt-bottom-inset)); max-width: none; flex-wrap: wrap; justify-content: center; gap: 5px; padding: 0; }
  .htw-actions .kt-btn { min-height: 34px; font-size: 12.5px; padding: 0 10px; flex: none; }
  .htw-sheet, .htw-step { left: 8px; right: 8px; width: auto; transform: none; bottom: calc(var(--htw-actions-h, 73px) + 14px + var(--kt-bottom-inset)); padding: 10px 10px; max-height: 44vh; overflow-y: auto; }
  .htw-ctl { min-height: 40px; font-size: 14px; padding: 0 12px; }
  .htw-ctl kbd, .htw-dial kbd, .htw-chip kbd { display: none; }
  .htw-row.main { flex-wrap: nowrap; }
  .htw-dial { min-width: 0; flex: 1 1 110px; max-width: none; font-size: 13px; }
  .htw-choice .opts { gap: 5px; }
  .htw-chip { min-height: 32px; font-size: 13px; padding: 0 9px; }
  .kt-toasts { top: calc(var(--kt-top) + var(--htw-top, 60px) + 6px); left: 50%; }
  .htw-step h2 { font-size: 18px; }
  .htw-step p { font-size: 14.5px; line-height: 1.35; }
  .htw-nav .kt-btn { min-height: 40px; font-size: 15px; }
  .kt-card { left: 8px; right: 8px; width: auto; top: auto; bottom: calc(8px + var(--kt-bottom-inset)); max-height: 70vh; }
}
/* a phone on its side (short and wide): the picture on the left, one column of panels on the right */
@media (max-height: 520px) and (min-aspect-ratio: 5/4) {
  :root { --htw-col: 300px; }
  .htw-brand { left: auto; right: 8px; top: calc(var(--kt-top) + 6px); width: var(--htw-col); max-width: none; padding: 6px 8px; flex-direction: row; flex-wrap: nowrap; align-items: center; gap: 6px; }
  .htw-brand .kt-kicker { display: none; }
  .htw-brand .kt-title { margin: 0; flex: 1; min-width: 0; font-size: 0; overflow: hidden; }
  .htw-brand .kt-title b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .htw-modes { width: auto; flex: none; }
  .htw-modes button { min-height: 28px; font-size: 11.5px; white-space: nowrap; padding: 0 7px; }
  .htw-actions { left: auto; right: 8px; top: auto; bottom: calc(6px + var(--kt-bottom-inset)); width: var(--htw-col); max-width: none; flex-wrap: wrap; justify-content: center; gap: 4px; padding: 0; }
  .htw-actions .kt-btn { min-height: 29px; font-size: 11.5px; padding: 0 8px; }
  .htw-sheet, .htw-step { left: auto; right: 8px; width: var(--htw-col); transform: none; top: calc(var(--kt-top) + 54px); bottom: calc(var(--htw-actions-h, 62px) + 12px + var(--kt-bottom-inset)); max-height: none; padding: 8px; overflow-y: auto; }
  .htw-row { gap: 5px; }
  .htw-row.main { flex-wrap: wrap; }
  .htw-ctl { min-height: 34px; font-size: 13px; padding: 0 10px; }
  .htw-chip { min-height: 28px; font-size: 12px; padding: 0 8px; }
  .htw-choice > .t { font-size: 10px; }
  .htw-dial { flex: 1 1 100px; font-size: 12px; }
  .htw-dial .kt-range { height: 26px; }
  .htw-step { gap: 5px; }
  .htw-step h2 { font-size: 15px; }
  .htw-step p { font-size: 12.5px; line-height: 1.3; }
  .htw-dots button { width: 24px; height: 22px; font-size: 11px; }
  .htw-nav .kt-btn { min-height: 34px; font-size: 14px; }
  .kt-card { left: auto; right: 8px; width: var(--htw-col); top: calc(var(--kt-top) + 6px); bottom: calc(6px + var(--kt-bottom-inset)); max-height: none; padding: 12px; }
  .kt-card h2 { font-size: 17px; }
  .kt-card p { font-size: 13.5px; }
  body.htw-card-open .htw-sheet, body.htw-card-open .htw-step, body.htw-card-open .htw-actions, body.htw-card-open .htw-brand { visibility: hidden; }   /* the card takes the whole column */
  .kt-toasts { left: 8px; right: auto; transform: none; top: calc(var(--kt-top) + 8px); width: min(360px, calc(100vw - var(--htw-col) - 32px)); }
  .kt-modal .kt-glass { padding: 14px 16px; }
}

/* modals keep their buttons above the first-visit notice, and the How modal scrolls inside with Got it always in view */
.kt-modal { padding-bottom: calc(16px + var(--kt-bottom-inset)); }
#howModal .kt-glass { display: flex; flex-direction: column; min-height: 0; }
#howModal .kt-glass > p:last-child { margin: 12px 0 0; flex: none; }
#howBody { flex: 1 1 auto; min-height: 0; overflow: auto; scrollbar-width: thin; scrollbar-gutter: stable; padding-right: 6px; }
#howBody h3 { margin-top: 10px; }
.htw-tabs { flex: none; margin-bottom: 4px; }
.htw-tabs button { min-height: 36px; font-size: 14px; font-weight: 600; }
.htw-tabs button[aria-pressed="true"] { background: var(--kt-accent); color: var(--kt-accent-ink); }
.htw-fade { position: sticky; bottom: 0; height: 26px; margin-top: -26px; background: linear-gradient(to bottom, transparent, var(--kt-glass-hi)); pointer-events: none; }
