/* Shared components: windows, dialogs, buttons, bubbles, chat, bars, chips, tiles, fields, taskbar, navbar, Henk, toasts. */

/* ---------- Window ---------- */
.win {
  position: relative;
  width: 100%;
  max-width: var(--win-max);
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  box-shadow: var(--shadow);
}

.win__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 4px 6px 4px 10px;
  background: var(--lav);
  border-bottom: var(--bw) solid var(--ink);
}

.win__icon { display: flex; }

.win__title {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-ui);
  font-size: var(--fs-s);
  line-height: 1.1;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.win__ctrls {
  display: flex;
  gap: 4px;
  flex: none;
}

.win__dot {
  width: 12px;
  height: 12px;
  background: var(--paper);
  border: var(--bw) solid var(--ink);
}

.win__dot--round { border-radius: 50%; }

.win__close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 28px;
  padding: 0;
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-s);
  line-height: 1;
}

.win__close { position: relative; }
.win__close::after { content: ""; position: absolute; inset: -11px -9px; } /* 44 px tap area, same look */
.win__close:active { background: var(--lav-l); }

.win__body {
  padding: 14px;
}

.win__body > * + * { margin-top: 12px; }

.win--pink .win__bar { background: var(--pink); }
.win--mint .win__bar { background: var(--mint); }
.win--yellow .win__bar { background: var(--yellow); }
.win--red .win__bar { background: var(--red); }
.win--wide { max-width: 640px; }
.win--flush .win__body { padding: 0; }

/* ---------- Buttons ---------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 6px 16px;
  font-family: var(--font-ui);
  font-size: var(--fs-s);
  line-height: 1.1;
  text-transform: uppercase;
  text-align: center;
  color: var(--ink);
  background: var(--lav);
  border: var(--bw) solid var(--ink);
  border-radius: 0;
  box-shadow: var(--shadow);
  text-decoration: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.btn:active, .btn.is-pressed {
  transform: translate(var(--sh), var(--sh));
  box-shadow: none;
}

.btn--pink { background: var(--pink); }
.btn--pink:active { background: var(--pink-d); }
.btn--mint { background: var(--mint); }
.btn--mint:active { background: var(--mint-d); }
.btn--paper { background: var(--paper); }
.btn--paper:active { background: var(--shade); }
.btn--yellow { background: var(--yellow); }
.btn--lav:active, .btn:not([class*="btn--"]):active { background: var(--lav-d); }

.btn--big {
  min-height: 56px;
  padding: 8px 22px;
  font-size: var(--fs-l);
}

.btn--block { display: flex; width: 100%; }

.btn--small {
  min-height: 36px;
  padding: 4px 10px;
  font-size: var(--fs-xs);
  box-shadow: 3px 3px 0 0 var(--ink);
}

.btn[disabled], .btn.is-disabled {
  color: var(--lav-d);
  background: var(--shade);
  border-color: var(--lav-d);
  box-shadow: none;
  cursor: not-allowed;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.btn-row--end { justify-content: flex-end; }

/* plain text-like link button */
.linkbtn {
  padding: 4px 2px;
  min-height: 32px;
  background: none;
  border: 0;
  font-family: var(--font-body);
  font-size: var(--fs-s);
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* ---------- Dialog (WARNING) ---------- */
.overlay-layer {
  position: absolute;
  inset: 0;
  z-index: var(--z-overlay);
  pointer-events: none;
}

.overlay-layer > * { pointer-events: auto; }

.dialog-wrap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--gutter);
  background: rgba(41, 42, 51, 0.22);
  z-index: var(--z-dialog);
}

.dialog-wrap.is-bare { background: none; }

.dialog {
  max-width: 360px;
  animation: pop-in var(--t-med) steps(4) both;
}

.dialog__content {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.dialog__text {
  flex: 1 1 auto;
  font-size: var(--fs-m);
}

.dialog__text strong { font-family: var(--font-ui); font-weight: 400; text-transform: uppercase; }

.dialog .btn-row { margin-top: 16px; }

/* ---------- Speech bubble ---------- */
.bubble {
  position: relative;
  padding: 10px 12px;
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  box-shadow: 3px 3px 0 0 var(--ink);
  font-size: var(--fs-m);
  line-height: 1.3;
}

.bubble--pink { background: var(--pink-l); }
.bubble--mint { background: var(--mint); }
.bubble--lav { background: var(--lav-l); }

/* pixel tail pointing down-left */
.bubble--tail-left::after {
  content: "";
  position: absolute;
  left: 14px;
  bottom: -12px;
  width: 12px;
  height: 12px;
  background:
    linear-gradient(var(--ink), var(--ink)) 0 0 / 3px 12px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 3px 6px / 3px 3px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 6px 3px / 3px 3px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 9px 0 / 3px 3px no-repeat,
    linear-gradient(var(--paper), var(--paper)) 3px 0 / 6px 6px no-repeat,
    linear-gradient(var(--paper), var(--paper)) 3px 6px / 0 0 no-repeat;
}

/* ---------- Chat ---------- */
.chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat__msg {
  max-width: 85%;
  padding: 8px 12px;
  border: var(--bw) solid var(--ink);
  background: var(--lav-l);
  font-size: var(--fs-m);
  line-height: 1.3;
  align-self: flex-start;
  animation: pop-in var(--t-fast) steps(3) both;
}

.chat__msg--out {
  align-self: flex-end;
  background: var(--mint);
}

.chat__msg--pink { background: var(--pink-l); }

.chat__typing {
  display: inline-flex;
  gap: 6px;
  align-self: flex-start;
  padding: 12px 14px;
  border: var(--bw) solid var(--ink);
  background: var(--paper);
}

.chat__typing span {
  width: 6px;
  height: 6px;
  background: var(--ink);
  animation: blink calc(900ms / var(--speed)) steps(1) infinite;
}

.chat__typing span:nth-child(2) { animation-delay: calc(300ms / var(--speed)); }
.chat__typing span:nth-child(3) { animation-delay: calc(600ms / var(--speed)); }

/* ---------- Loading bar (segmented) ---------- */
.loadbar {
  display: flex;
  gap: 3px;
  padding: 4px;
  border: var(--bw) solid var(--ink);
  background: var(--paper);
}

.loadbar__seg {
  flex: 1 1 0;
  height: 18px;
  background: var(--paper);
}

.loadbar__seg.is-on { background: var(--lav); }
.loadbar--pink .loadbar__seg.is-on { background: var(--pink); }

.loadbar__label {
  font-family: var(--font-ui);
  font-size: var(--fs-s);
  text-transform: uppercase;
}

/* ---------- Selection marquee (marching ants) ---------- */
.marquee {
  position: relative;
  padding: 8px;
  background:
    linear-gradient(90deg, var(--ink) 50%, transparent 0) 0 0 / 12px 3px repeat-x,
    linear-gradient(90deg, var(--ink) 50%, transparent 0) 0 100% / 12px 3px repeat-x,
    linear-gradient(0deg, var(--ink) 50%, transparent 0) 0 0 / 3px 12px repeat-y,
    linear-gradient(0deg, var(--ink) 50%, transparent 0) 100% 0 / 3px 12px repeat-y;
  animation: ants calc(600ms / var(--speed)) steps(4) infinite;
}

.marquee__handle {
  position: absolute;
  width: 9px;
  height: 9px;
  background: var(--paper);
  border: 3px solid var(--ink);
}

.marquee__handle--tl { left: -3px; top: -3px; }
.marquee__handle--tr { right: -3px; top: -3px; }
.marquee__handle--bl { left: -3px; bottom: -3px; }
.marquee__handle--br { right: -3px; bottom: -3px; }

/* ---------- Checkered bar + dividers ---------- */
.checker {
  height: 12px;
  border: var(--bw) solid var(--ink);
  background: conic-gradient(var(--ink) 25%, var(--paper) 0 50%, var(--ink) 0 75%, var(--paper) 0) 0 0 / 12px 12px;
}

.divider-dots {
  height: 3px;
  background: repeating-linear-gradient(90deg, var(--lav-d) 0 3px, transparent 3px 9px);
}

.divider-hearts {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
}

.divider-hearts__line {
  flex: 1 1 auto;
  height: 3px;
  background: repeating-linear-gradient(90deg, var(--ink) 0 3px, transparent 3px 9px);
}

/* ---------- Chips + tiles ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 4px 12px;
  font-family: var(--font-body);
  font-size: var(--fs-s);
  line-height: 1.15;
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  box-shadow: 3px 3px 0 0 var(--ink);
  cursor: pointer;
}

.chip:active { transform: translate(3px, 3px); box-shadow: none; }
.chip.is-on, .chip[aria-pressed="true"] { background: var(--pink); }
.chip--mint.is-on, .chip--mint[aria-pressed="true"] { background: var(--mint); }
.chip[disabled] { color: var(--lav-d); border-color: var(--lav-d); box-shadow: none; background: var(--shade); }

.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 84px;
  padding: 6px 4px;
  font-family: var(--font-body);
  font-size: var(--fs-s);
  line-height: 1.1;
  text-align: center;
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  box-shadow: 3px 3px 0 0 var(--ink);
  cursor: pointer;
  word-break: break-word;
  hyphens: auto;
}

.tile:active { transform: translate(3px, 3px); box-shadow: none; }
.tile.is-leuk { border-style: dashed; background: var(--lav-l); }
.tile.is-super { background: var(--pink); }

/* ---------- Segmented toggle ---------- */
.seg {
  display: flex;
  border: var(--bw) solid var(--ink);
  box-shadow: 3px 3px 0 0 var(--ink);
  background: var(--paper);
}

.seg__opt {
  flex: 1 1 0;
  min-height: 40px;
  padding: 4px 8px;
  font-family: var(--font-ui);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  background: none;
  border: 0;
  border-left: var(--bw) solid var(--ink);
  cursor: pointer;
}

.seg__opt:first-child { border-left: 0; }
.seg__opt[aria-pressed="true"], .seg__opt.is-on { background: var(--lav); }

/* ---------- Form fields ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field__label {
  font-family: var(--font-ui);
  font-size: var(--fs-s);
  text-transform: uppercase;
}

.input, .textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 10px;
  font-family: var(--font-body);
  font-size: max(18px, var(--fs-m)); /* >= 16px stops iOS from zooming in on focus */
  line-height: 1.2;
  color: var(--ink);
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  border-radius: 0;
  box-shadow: inset 3px 3px 0 0 var(--shade);
  -webkit-appearance: none;
  appearance: none;
}

.textarea { min-height: 96px; resize: none; }
.input:focus, .textarea:focus { outline: 3px dashed var(--ink); outline-offset: 2px; }

/* pixel checkbox */
.check {
  display: inline-flex;
  align-items: flex-start;
  gap: 10px;
  min-height: var(--tap);
  padding: 6px 0;
  cursor: pointer;
  font-size: var(--fs-m);
  line-height: 1.25;
}

.check__input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.check__box {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px; /* 3px borders + the 27px check sprite */
  height: 36px;
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  box-shadow: 3px 3px 0 0 var(--ink);
}

.check__box svg { visibility: hidden; }
.check__input:checked + .check__box { background: var(--mint); }
.check__input:checked + .check__box svg { visibility: visible; }
.check__input:focus-visible + .check__box { outline: 3px dashed var(--ink); outline-offset: 3px; }

/* ---------- Toasts ---------- */
.toast-layer {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(env(safe-area-inset-top) + var(--taskbar-h) + 8px);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: min(92vw, 380px);
  padding: 8px 12px;
  background: var(--yellow);
  border: var(--bw) solid var(--ink);
  box-shadow: 3px 3px 0 0 var(--ink);
  font-size: var(--fs-s);
  animation: pop-in var(--t-fast) steps(3) both;
}

.toast.is-out { animation: fade-out var(--t-fast) steps(3) both; }

/* ---------- Taskbar ---------- */
.taskbar {
  position: relative;
  z-index: var(--z-top);
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  min-height: var(--taskbar-h);
  padding: 4px 8px;
  background: var(--lav);
  border-bottom: var(--bw) solid var(--ink);
}

.tb-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}

.tb-progress__segs {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--paper);
  border: 2px solid var(--ink);
}

.tb-progress__seg {
  width: 8px;
  height: 12px;
  background: var(--paper);
}

.tb-progress__seg.is-on { background: var(--pink); }

.tb-progress__label {
  font-family: var(--font-ui);
  font-size: 13px; /* fixed: LEESBRIL enlarges content, not the taskbar */
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 419px) {
  .tb-progress__segs { display: none !important; }
}

.tb-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 36px;
  padding: 0;
  background: var(--paper);
  border: 2px solid var(--ink);
  flex: none;
  cursor: pointer;
}

.tb-btn:active { background: var(--lav-l); }
.tb-btn[aria-pressed="true"] { background: var(--yellow); }

.tb-badge {
  position: absolute;
  right: -6px;
  top: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 3px;
  font-family: var(--font-ui);
  font-size: 11px;
  line-height: 14px;
  text-align: center;
  color: var(--ink);
  background: var(--pink);
  border: 2px solid var(--ink);
}

.tb-clock {
  min-width: 52px;
  height: 36px;
  padding: 0 4px;
  font-family: var(--font-ui);
  font-size: var(--fs-xs);
  background: none;
  border: 0;
  flex: none;
  cursor: default;
}

.tb-notes {
  position: absolute;
  right: 8px;
  top: calc(100% + 6px);
  width: min(300px, calc(100vw - 16px));
  z-index: var(--z-top);
}

.tb-notes__list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--fs-s);
}

.tb-notes__list li + li {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 3px dotted var(--lav-d);
}

/* ---------- Thumb-zone navigation ---------- */
.nav-layer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-nav);
  pointer-events: none;
}

.navbar {
  display: flex;
  justify-content: center;
  pointer-events: auto;
  padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(247, 247, 251, 0), var(--wall) 30%);
}

.navbar__inner {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: var(--win-max);
}

.navbar__back { flex: 0 0 auto; min-width: 96px; }
.navbar__next { flex: 1 1 auto; }
.navbar__back[hidden] + .navbar__next { margin-left: 0; }

/* ---------- Henk the system cat ---------- */
.henk-layer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: var(--z-henk);
  pointer-events: none;
  display: flex;
  justify-content: center;
  padding: 0 var(--gutter);
}

.os.has-nav .henk-layer { bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); }

.henk {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  max-width: var(--win-max);
  pointer-events: none;
}

.henk__body {
  flex: none;
  padding: 0;
  background: none;
  border: 0;
  pointer-events: auto;
  cursor: pointer;
}

/* Henk who only drops by to talk (not pinned, no tap handler) lets taps through to what is under him,
   e.g. a calendar day; a pinned Henk can be petted. */
.henk:not(.is-pinned):not(.has-tap) .henk__body { pointer-events: none; }

.henk__bubble {
  flex: 0 1 auto;
  max-width: calc(100% - 64px);
  margin-bottom: 18px;
  pointer-events: none; /* never swallow taps on what's underneath; Henk's body stays tappable */
}

.henk.is-talking .henk__bubble { animation: pop-in var(--t-fast) steps(3) both; }
.henk.is-talking .henk__body { animation: bob calc(500ms / var(--speed)) steps(2) 2; }

/* small left-pointing tail on Henk's bubble */
.henk__bubble::before {
  content: "";
  position: absolute;
  left: -12px;
  bottom: 8px;
  width: 12px;
  height: 9px;
  background:
    linear-gradient(var(--ink), var(--ink)) 0 6px / 12px 3px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 3px 3px / 3px 3px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 6px 0 / 6px 3px no-repeat,
    linear-gradient(var(--paper), var(--paper)) 6px 3px / 6px 3px no-repeat;
}

/* ---------- Misc ---------- */
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 12px; align-items: center; }
.spacer { flex: 1 1 auto; }

.q-title {
  font-family: var(--font-body);
  font-size: var(--fs-l);
  line-height: 1.2;
  font-weight: 700;
}

.q-sub {
  font-size: var(--fs-s);
  color: var(--ink);
  opacity: 0.8;
}

.kbd-tile {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 32px;
  border: var(--bw) solid var(--ink);
  background: var(--paper);
  font-family: var(--font-ui);
  font-size: var(--fs-s);
}

.dev-panel {
  position: fixed;
  right: 8px;
  bottom: 8px;
  z-index: var(--z-dev);
  font-size: 14px;
}

.dev-panel__body {
  max-height: 60vh;
  width: min(320px, calc(100vw - 16px));
  overflow: auto;
}

.dev-panel pre {
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 12px;
  background: var(--shade);
  padding: 6px;
}
