/* Fake OS: desktop, wallpaper, windows, tabs, chat, taskbar, start menu, toasts. */

/* ---------- desktop + wallpaper ---------- */
.desktop {
  position: fixed;
  inset: 0 0 calc(var(--taskbar-h) + var(--ticker-h)) 0;
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 300px;
  gap: 14px;
  padding: 14px;
}

.wallpaper {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 70% 0%, var(--glow-room) 0%, transparent 60%),
    var(--bg);
}
/* Thin CRT scanlines: the room is lit by a cheap monitor. */
.wallpaper::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.022) 0 1px, transparent 1px 3px);
}
.wp-67 {
  position: absolute;
  left: -2vw;
  bottom: -9vh;
  font: 46vh/1 var(--font-stamp);
  color: transparent;
  -webkit-text-stroke: 2px var(--wp-text);
  transform: rotate(-8deg);
}
.sticker {
  position: absolute;
  padding: 5px 10px 6px;
  font: 700 12px/1 var(--font-mono);
  letter-spacing: 0.02em;
  color: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}
.sticker--acid { background: var(--acid); }
.sticker--hot { background: var(--hot); color: #fff; }
.sticker--warn { background: var(--warn); }
.sticker--paper { background: #e9e4d4; }
.s1 { left: 12px; bottom: 34%; transform: rotate(-7deg); }
.s2 { left: 6px; bottom: 21%; transform: rotate(4deg); font-size: 10px; }
.s3 { left: 22px; bottom: 9%; transform: rotate(-3deg); }
.s4 { right: 330px; top: 4px; transform: rotate(3deg); }
.s5 { right: 14px; bottom: 4px; transform: rotate(-2deg); }
.s6 { left: 46%; bottom: 2px; transform: rotate(2deg); }

.desk-icons {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.desk-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 92px;
  padding: 8px 4px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: none;
  text-align: center;
}
.desk-icon svg { width: 40px; height: 40px; }
.desk-icon span {
  font-size: 11.5px;
  line-height: 1.25;
  text-shadow: 0 1px 2px var(--ink);
  overflow-wrap: anywhere;
}
.desk-icon:hover { background: var(--acid-soft); border-color: var(--acid-2); }

/* ---------- windows ---------- */
.win {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-win);
  overflow: hidden;
}
.win-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  height: 34px;
  padding: 0 4px 0 10px;
  background: var(--surface-2);
  color: var(--muted);
  border-bottom: 2px solid var(--ink);
  user-select: none;
}
/* The focused window gets the accent, exactly like a real OS title bar. */
.win.is-focused > .win-bar { background: var(--acid); color: var(--acid-ink); }
.win-title {
  flex: 1;
  min-width: 0;
  font: 700 12.5px/1 var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.win-title-sub { font-weight: 500; opacity: 0.75; margin-left: 4px; }
.win-ico {
  flex: none;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 2px;
  background: linear-gradient(currentColor 0 0) 0 0 / 100% 3px no-repeat;
}
.win-ico--chat { border-radius: 50% 50% 50% 0; background: none; }
.win-ico--txt, .win-ico--cfg { background: linear-gradient(currentColor 0 0) 2px 3px / 6px 2px no-repeat, linear-gradient(currentColor 0 0) 2px 7px / 6px 2px no-repeat; }
.win-ctrls { display: flex; gap: 2px; }
.win-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 26px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: inherit;
}
.win-btn svg { width: 12px; height: 12px; }
.win-btn:hover { background: rgba(5, 7, 13, 0.15); }
.win-btn--close:hover { background: var(--hot); color: #fff; }

.win--main { grid-column: 2; }
.win--chat { grid-column: 3; }

.win--float {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  width: min(380px, calc(100vw - 24px));
  max-height: calc(100vh - var(--taskbar-h) - 90px);
  z-index: 30;
}

/* ---------- tab strip ---------- */
.tabs {
  display: flex;
  align-items: stretch;
  flex: none;
  height: 34px;
  background: var(--bg-2);
  border-bottom: 2px solid var(--ink);
}
.tabs-scroll {
  display: flex;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.tabs-scroll::-webkit-scrollbar { display: none; }
.tab {
  display: flex;
  align-items: center;
  flex: none;
  width: 168px;
  border-right: 1px solid var(--line);
  color: var(--muted);
}
.tab-main {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 4px 0 10px;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
}
.tab-label {
  font: 500 11px/1 var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tab-fav {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--muted);
}
.tab-fav[data-kind="doc"] { border-radius: 1px; height: 12px; }
.tab-fav[data-kind="exe"] { border-radius: 2px; border-color: var(--acid); }
.tab-fav[data-kind="folder"] { border-radius: 1px 3px 1px 1px; border-color: var(--warn); }
.tab-x {
  flex: none;
  width: 24px;
  height: 24px;
  margin-right: 3px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: inherit;
  font-size: 15px;
  line-height: 1;
}
.tab-x:hover { background: var(--surface-3); color: var(--text); }
.tab:hover { background: var(--surface); color: var(--text); }
/* Active tab merges into the window body, with a top edge marking it. */
.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: inset 0 3px 0 var(--acid);
}
.tab-count, .tab-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
  padding: 0 12px;
  font: 500 11px/1 var(--font-mono);
  color: var(--muted);
  border-left: 2px solid var(--ink);
  background: var(--surface-2);
}
.tab-count b, .tab-chip b { color: var(--hot); font-weight: 800; font-size: 13px; }
.tab-chip { display: none; border: 0; }

/* ---------- address bar ---------- */
.addr {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  height: 30px;
  padding: 0 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font: 500 11.5px/1 var(--font-mono);
}
.addr-label { color: var(--muted); }
.addr-path {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.win-body {
  position: relative;
  flex: 1;
  min-height: 0;
}
.view { height: 100%; }

/* ---------- launcher ---------- */
.view--launcher {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: clamp(18px, 4vh, 44px) clamp(16px, 4vw, 48px);
  overflow-y: auto;
}
.launch-kicker {
  font: 500 12px/1.4 var(--font-mono);
  color: var(--warn);
}
.launch-title {
  font: 800 clamp(26px, 3.6vw, 44px)/1.02 var(--font-ui);
  letter-spacing: -0.02em;
  max-width: 16ch;
}
.launch-list {
  display: flex;
  flex-direction: column;
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  background: var(--bg-2);
  max-width: 760px;
  margin-top: 6px;
}
.launch-list li + li { border-top: 1px solid var(--line); }
.launch-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  grid-template-areas: "ico name tag" "ico desc best";
  align-items: center;
  column-gap: 14px;
  row-gap: 3px;
  width: 100%;
  min-height: 64px;
  padding: 12px 16px;
  border: 0;
  background: none;
  text-align: left;
}
.launch-item:not(:disabled):hover { background: var(--surface-2); }
.launch-item:not(:disabled):hover .launch-name { color: var(--acid); }
.file-ico {
  grid-area: ico;
  width: 30px;
  height: 34px;
  border: 2px solid var(--ink);
  border-radius: 2px 9px 2px 2px;
  background: var(--acid);
}
.file-ico--doc { background: var(--surface-3); }
.launch-name { grid-area: name; font: 700 15px/1.2 var(--font-mono); overflow-wrap: anywhere; }
.launch-tag {
  grid-area: tag;
  justify-self: end;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font: 600 10.5px/1 var(--font-mono);
  color: var(--muted);
}
.launch-desc { grid-area: desc; color: var(--muted); font-size: 13.5px; }
.launch-best { grid-area: best; justify-self: end; font: 500 11px/1 var(--font-mono); color: var(--muted); white-space: nowrap; }
.launch-best b { color: var(--text); font-weight: 800; }
.launch-item.is-locked { opacity: 0.55; }
.launch-item.is-locked .launch-best { color: var(--hot); }
.launch-help { color: var(--muted); max-width: 60ch; font-size: 13.5px; }

/* ---------- dialogs ---------- */
.dialog-backdrop {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(5, 7, 13, 0.72);
}
.win--dialog { width: min(420px, 100%); }
.dialog-body { display: flex; flex-direction: column; gap: 12px; padding: 18px 20px 20px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.dialog-actions .btn { flex: 1 1 120px; }

.result-kicker { font: 500 12px/1.4 var(--font-mono); color: var(--warn); }
.result-score-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.result-score { font: 800 52px/1 var(--font-mono); letter-spacing: -0.04em; }
.result-stamp {
  font: 22px/1 var(--font-stamp);
  color: var(--hot);
  border: 3px solid var(--hot);
  padding: 6px 8px 4px;
  transform: rotate(-6deg);
}
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.result-stats div { padding: 8px 10px; }
.result-stats div + div { border-left: 1px solid var(--line); }
.result-stats dt { color: var(--muted); font-size: 11.5px; }
.result-stats dd { font: 700 16px/1.3 var(--font-mono); }
.result-quip { font-size: 15px; }

/* ---------- settings ---------- */
.settings { display: flex; flex-direction: column; gap: 16px; padding: 16px; overflow-y: auto; }
.settings fieldset { display: flex; flex-direction: column; gap: 8px; }
.settings legend {
  margin-bottom: 6px;
  font: 700 11px/1 var(--font-mono);
  color: var(--muted);
  text-transform: uppercase;
}
.field { display: grid; grid-template-columns: 56px minmax(0, 1fr) 44px; align-items: center; gap: 10px; }
.field output { font: 600 11.5px/1 var(--font-mono); text-align: right; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.settings .btn--warn { align-self: flex-start; }
.keys { line-height: 2; }

/* ---------- chat ---------- */
.chat-pinned {
  flex: none;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  font-size: 12.5px;
}
.pin-label {
  display: block;
  margin-bottom: 3px;
  font: 700 10px/1 var(--font-mono);
  color: var(--warn);
  text-transform: uppercase;
}
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.msg { font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.msg-u { display: block; font: 700 11px/1.4 var(--font-mono); color: var(--u, var(--acid)); }
.msg-t { color: var(--text); }
.chat-muted {
  flex: none;
  margin: 0 10px 10px;
  padding: 9px 10px;
  border: 1px dashed var(--line);
  border-radius: var(--r-sm);
  color: var(--muted);
  font-size: 12px;
}
.chat-close { display: none; }

.chat-ticker { display: none; }

/* ---------- taskbar ---------- */
.taskbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--taskbar-h);
  padding: 0 6px;
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: var(--taskbar);
  border-top: 2px solid var(--ink);
  box-shadow: 0 -1px 0 var(--line);
}
.start-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px 0 6px;
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-weight: 700;
}
.start-btn:hover, .start-btn[aria-expanded="true"] { background: var(--surface-3); }
.start-logo {
  display: grid;
  place-items: center;
  width: 30px;
  height: 24px;
  font: 13px/1 var(--font-stamp);
  color: var(--acid-ink);
  background: var(--acid);
  border: 2px solid var(--ink);
  transform: skewX(-8deg);
}
.task-wins { display: flex; gap: 4px; flex: 1; min-width: 0; overflow: hidden; }
.task-btn {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 220px;
  min-width: 0;
  height: 36px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font: 500 11.5px/1 var(--font-mono);
}
.task-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-btn:hover { background: var(--surface); color: var(--text); }
.task-btn.is-active { background: var(--surface-2); color: var(--text); border-color: var(--line); box-shadow: inset 0 -3px 0 var(--acid); }
.task-badge {
  margin-left: 6px;
  padding: 2px 5px;
  border-radius: 9px;
  background: var(--hot);
  color: #fff;
  font: 700 10px/1 var(--font-mono);
}
.tray { display: flex; align-items: center; gap: 2px; }
.tray-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--muted);
  font: 600 12px/1 var(--font-mono);
}
.tray-btn:hover { background: var(--surface); color: var(--text); }
.tray-btn svg { width: 20px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.tray-btn svg circle { fill: currentColor; stroke: none; }
#trayWifi .wifi-a { opacity: 0.25; }
#trayWifi.is-flaky { animation: wifi-flake 1.3s steps(1) 1; }
@keyframes wifi-flake { 0%, 40%, 80% { opacity: 0.2; } 20%, 60%, 100% { opacity: 1; } }
.tray-battery { color: var(--hot); }
.tray-battery svg { width: 26px; height: 14px; }
.tray-battery .batt-fill { fill: var(--hot); stroke: none; }
/* Slow fade, about once per 2.6 s: the "3% forever" joke, far below any flash threshold. */
.tray-battery span { animation: batt-low 2.6s ease-in-out infinite; }
@keyframes batt-low { 50% { opacity: 0.45; } }
.tray-clock { color: var(--text); font-size: 13px; padding: 0 10px; }

/* ---------- start menu ---------- */
.start-menu {
  position: fixed;
  left: 6px;
  bottom: calc(var(--taskbar-h) + 6px);
  z-index: 45;
  width: 280px;
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-win);
  overflow: hidden;
}
.start-head {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px;
  background: var(--hot);
  color: #fff;
  border-bottom: 2px solid var(--ink);
}
.start-user { font: 800 16px/1 var(--font-ui); }
.start-sub { font: 500 11px/1.2 var(--font-mono); opacity: 0.9; }
.start-menu ul { padding: 6px; }
.start-menu li button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  font-weight: 600;
  text-align: left;
}
.start-menu li button:not(:disabled):hover { background: var(--acid); color: var(--acid-ink); }
.start-menu li button:disabled { color: var(--muted); opacity: 0.7; }
.start-menu em { font: 600 10px/1 var(--font-mono); font-style: normal; color: var(--muted); }
.start-menu .sep { height: 1px; margin: 6px 4px; background: var(--line); }

/* ---------- toasts ---------- */
.toasts {
  position: fixed;
  right: 14px;
  bottom: calc(var(--taskbar-h) + var(--ticker-h) + 14px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(320px, calc(100vw - 28px));
  pointer-events: none;
}
.toast {
  padding: 10px 12px;
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: 4px 4px 0 var(--ink);
  animation: toast-in 220ms cubic-bezier(.2,.9,.3,1.2);
  pointer-events: auto;
}
.toast-title { display: block; margin-bottom: 2px; font: 700 11px/1.3 var(--font-mono); color: var(--acid); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast p { font-size: 13px; }
.toast.is-leaving { opacity: 0; transform: translateX(20px); transition: opacity 240ms, transform 240ms; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

/* ---------- responsive ---------- */
@media (max-width: 1279px) {
  .desktop { grid-template-columns: minmax(0, 1fr) 264px; }
  .desk-icons { display: none; }
  .win--main { grid-column: 1; }
  .win--chat { grid-column: 2; }
  .s4 { right: 290px; }
}

/* Chat becomes a drawer with a one-line ticker. */
@media (max-width: 1023px) {
  :root { --ticker-h: 38px; }
  .desktop { grid-template-columns: minmax(0, 1fr); padding: 10px; }
  .win--main { grid-column: 1; }
  .win--chat {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(var(--taskbar-h) + var(--ticker-h) + 8px);
    height: min(60vh, 480px);
    z-index: 35;
    transform: translateY(calc(100% + var(--ticker-h) + 24px));
    visibility: hidden;
    transition: transform 240ms cubic-bezier(.2,.8,.3,1), visibility 0s 240ms;
  }
  .win--chat.is-open { transform: none; visibility: visible; transition: transform 240ms cubic-bezier(.2,.8,.3,1); }
  .chat-close { display: grid; }
  .chat-ticker {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--taskbar-h);
    z-index: 36;
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--ticker-h);
    padding: 0 12px;
    border: 0;
    border-top: 2px solid var(--ink);
    background: var(--surface-2);
    text-align: left;
  }
  .ticker-name { flex: none; font: 700 10.5px/1 var(--font-mono); color: var(--warn); text-transform: uppercase; }
  .ticker-text { flex: 1; min-width: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ticker-text b { color: var(--u, var(--acid)); font: 700 11px/1 var(--font-mono); margin-right: 4px; }
  /* The ticker replaces the chat taskbar button on narrow screens. */
  .task-btn--chat { display: none; }
  .s4 { right: 14px; }
}

@media (max-width: 719px) {
  :root { --taskbar-h: 50px; }
  .desktop { padding: 6px; }
  .sticker, .wp-67 { display: none; }
  .win { box-shadow: 3px 3px 0 var(--ink); }
  .tabs { height: 32px; }
  .tabs-scroll, .tab-count { display: none; }
  .tab-chip { display: flex; flex: 1; justify-content: flex-start; background: var(--bg-2); }
  .addr { height: 28px; }
  .addr-label { display: none; }
  .win--float {
    top: 6px;
    left: 6px;
    right: 6px;
    bottom: calc(var(--taskbar-h) + var(--ticker-h) + 6px);
    width: auto;
    max-height: none;
    transform: none;
  }
  .launch-item { grid-template-columns: 30px minmax(0, 1fr); grid-template-areas: "ico name" "ico desc" "ico tag" "ico best"; }
  .launch-tag, .launch-best { justify-self: start; }
  .start-label { display: none; }
  .task-btn { padding: 0 8px; }
  .task-btn--main { max-width: 130px; }
  .tray-btn { padding: 0 6px; }
  .result-score { font-size: 42px; }
  .toasts { left: 8px; right: 8px; width: auto; }
}

/* ======================= Phase 2: story ======================= */

/* File icons (map + launcher). */
.file-ico--tab { background: #e9e4d4; }
.file-ico--folder { width: 28px; height: 22px; border-radius: 2px 6px 2px 2px; background: var(--warn); }
.file-ico--exe { background: var(--acid); }
.launch-item--story .launch-tag { color: var(--hot); border-color: var(--hot); }

/* ---------- story map (file explorer) ---------- */
.view--map {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: clamp(16px, 3vh, 36px) clamp(16px, 4vw, 48px);
  overflow-y: auto;
}
.map-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; max-width: 760px; }
.map-total { font: 500 12px/1 var(--font-mono); color: var(--muted); }
.map-total b { font-size: 20px; color: var(--warn); margin-left: 4px; }
.map-body { display: flex; flex-direction: column; gap: 14px; max-width: 760px; }
.map-folder {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font: 700 13px/1.2 var(--font-mono);
}
.map-clock { padding: 2px 6px; border: 1px solid var(--line); border-radius: var(--r-sm); font-size: 11px; color: var(--muted); }
.map-chname { font: 600 13px/1.2 var(--font-ui); color: var(--muted); }
.map-list {
  display: flex;
  flex-direction: column;
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  background: var(--bg-2);
}
.map-list li + li { border-top: 1px solid var(--line); }
.map-file {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  grid-template-areas: "ico name stars" "ico title meta";
  align-items: center;
  column-gap: 14px;
  row-gap: 2px;
  width: 100%;
  min-height: 56px;
  padding: 9px 16px;
  border: 0;
  background: none;
  text-align: left;
}
.map-file .file-ico { width: 26px; height: 30px; }
.map-name { grid-area: name; font: 700 14px/1.2 var(--font-mono); overflow-wrap: anywhere; }
.map-title { grid-area: title; font-size: 13px; color: var(--muted); }
.map-title em {
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: var(--r-sm);
  background: var(--acid);
  color: var(--acid-ink);
  font: 700 10px/1.4 var(--font-mono);
  font-style: normal;
}
.map-stars { grid-area: stars; justify-self: end; font-size: 18px; line-height: 1; letter-spacing: 2px; color: var(--warn); }
.map-meta { grid-area: meta; justify-self: end; font: 500 11px/1 var(--font-mono); color: var(--muted); white-space: nowrap; }
.map-meta--deny { grid-area: stars / stars / meta / meta; align-self: center; color: var(--hot); white-space: normal; text-align: right; max-width: 26ch; }
.map-file:not(:disabled):hover { background: var(--surface-2); }
.map-file:not(:disabled):hover .map-name { color: var(--acid); }
.map-file.is-boss .map-name { color: var(--hot); }
.map-file.is-current { background: var(--acid-soft); }
.map-file.is-locked { opacity: 0.5; }
.map-ch--hidden .map-list { border-style: dashed; border-color: var(--acid); }

/* ---------- result additions ---------- */
.result-stars { display: flex; gap: 6px; font-size: 40px; line-height: 1; }
.result-stars span { color: var(--surface-3); text-shadow: 2px 2px 0 var(--ink); }
.result-stars span.is-on { color: var(--warn); }
.result-objs { display: flex; flex-direction: column; gap: 2px; font: 500 12px/1.5 var(--font-mono); color: var(--muted); }
.result-objs .is-done { color: var(--acid); }

/* ---------- ending ---------- */
.win--ending { width: min(540px, 100%); max-height: 100%; overflow-y: auto; }
.ending-label { font: 700 11px/1 var(--font-mono); color: var(--hot); letter-spacing: 0.08em; }
.ending-title { font: clamp(24px, 4vw, 34px)/1.05 var(--font-stamp); color: var(--acid); margin: 0; }
.ending-lines { display: flex; flex-direction: column; gap: 6px; font-size: 14.5px; line-height: 1.45; }
.is-animated .ending-lines li { animation: line-in 420ms ease-out both; animation-delay: calc(var(--i) * 420ms + 200ms); }
@keyframes line-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- cutscene (bubble chat) ---------- */
.dialog-backdrop--cut { z-index: 25; }
.win--cut { display: flex; flex-direction: column; width: min(460px, 100%); max-height: 100%; }
.cut-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 220px;
  max-height: min(56vh, 460px);
  padding: 16px 14px;
  overflow-y: auto;
  background: var(--bg-2);
  cursor: pointer;
}
.cut-line { display: flex; align-items: flex-end; gap: 8px; max-width: 88%; }
.cut-line--me { align-self: flex-end; }
.cut-line--mid { align-self: center; max-width: 100%; }
.cut-av { flex: none; width: 34px; height: 34px; border: 2px solid var(--ink); border-radius: 50%; background: var(--surface-3); overflow: hidden; }
.cut-av svg, .cut-av img { display: block; width: 100%; height: 100%; object-fit: cover; }
.cut-line--boss .cut-av { width: 40px; height: 40px; border-radius: var(--r-sm); }
.cut-bub {
  padding: 7px 11px 8px;
  border: 2px solid var(--ink);
  border-radius: 10px 10px 10px 2px;
  background: var(--surface-2);
  font-size: 14.5px;
  line-height: 1.35;
}
.cut-line--me .cut-bub { border-radius: 10px 10px 2px 10px; background: var(--acid); color: var(--acid-ink); }
.cut-line--boss .cut-bub { border-color: var(--u); box-shadow: 3px 3px 0 var(--ink); }
.cut-name { display: block; margin-bottom: 2px; font: 700 11px/1.3 var(--font-mono); color: var(--u, var(--acid)); }
.cut-narr {
  padding: 6px 10px;
  border: 1px dashed var(--line);
  border-radius: var(--r-sm);
  font: 500 12.5px/1.45 var(--font-mono);
  color: var(--muted);
  text-align: center;
}
.cut-typing { display: flex; gap: 4px; padding: 10px 12px; align-self: flex-start; border: 2px solid var(--ink); border-radius: 10px; background: var(--surface-2); }
.cut-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: typing 0.9s ease-in-out infinite; }
.cut-typing span:nth-child(2) { animation-delay: 0.15s; }
.cut-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing { 50% { transform: translateY(-4px); opacity: 0.4; } }
.cut-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 10px 14px 14px; border-top: 1px solid var(--line); }
.cut-actions .btn { min-width: 96px; }

@media (max-width: 719px) {
  .map-file { grid-template-columns: 26px minmax(0, 1fr) auto; padding: 9px 12px; column-gap: 10px; }
  .map-meta--deny { grid-area: meta; font-size: 10.5px; }
  .map-chname { display: none; }
  .cut-log { max-height: none; flex: 1; }
  .win--cut { height: 100%; }
  .cut-actions .btn { flex: 1; min-height: 44px; }
  .result-stars { font-size: 32px; }
}

/* ======================= Phase 3: meta windows ======================= */

.win--wide { width: min(560px, calc(100vw - 24px)); }
.win-scroll { display: flex; flex-direction: column; gap: 12px; padding: 16px; overflow-y: auto; min-height: 0; }
.panel-h { display: flex; align-items: baseline; gap: 8px; font: 700 12px/1 var(--font-mono); color: var(--warn); text-transform: uppercase; margin-top: 4px; }
.panel-h small { font-weight: 500; color: var(--muted); text-transform: none; }
.panel-count { font: 500 13px/1 var(--font-mono); color: var(--muted); }
.panel-count b { font-size: 22px; color: var(--acid); }
.btn--ghost { background: transparent; box-shadow: none; border-style: dashed; color: var(--muted); min-height: 36px; }
.btn--ghost:hover { color: var(--text); background: var(--surface-2); }
.field--select select {
  min-height: 36px;
  padding: 0 8px;
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.result-aura { font: 700 13px/1 var(--font-mono); color: var(--warn); }

/* ---------- shop ---------- */
.shop-wallet { font: 500 13px/1 var(--font-mono); color: var(--muted); }
.shop-wallet b { font-size: 24px; color: var(--warn); }
.shop-list { display: flex; flex-direction: column; border: 2px solid var(--ink); border-radius: var(--r-md); background: var(--bg-2); }
.shop-list li + li { border-top: 1px solid var(--line); }
.shop-item { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px 12px; }
.shop-info b { font-size: 15px; }
.shop-info p { font-size: 13px; color: var(--muted); }
.shop-own { font: 600 11px/1 var(--font-mono); color: var(--acid); }
.shop-item .btn { min-width: 104px; }
.boost-g--big {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  background: var(--surface-3);
  font-size: 18px;
}
.swatch { display: grid; grid-template-columns: repeat(3, 1fr); width: 46px; height: 46px; border: 2px solid var(--ink); border-radius: var(--r-sm); overflow: hidden; }
.swatch i { display: block; }

/* ---------- dex ---------- */
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.dex-card {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  background: var(--bg-2);
  box-shadow: inset 0 3px 0 var(--c, var(--line));
}
.dex-pic { width: 64px; height: 64px; border: 2px solid var(--ink); border-radius: var(--r-sm); background: var(--surface-2); overflow: hidden; display: grid; place-items: center; font: 26px/1 var(--font-stamp); color: var(--muted); }
.dex-pic svg, .dex-pic img { width: 100%; height: 100%; object-fit: contain; display: block; }
.dex-card.is-unknown .dex-pic > * { opacity: 0.25; }
.dex-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.dex-name { font-size: 14px; line-height: 1.2; }
.dex-sp { font: 500 11px/1.3 var(--font-mono); color: var(--muted); }
.dex-aff { display: flex; justify-content: space-between; font: 600 10.5px/1 var(--font-mono); color: var(--acid); }
.bar--aff { height: 8px; }
.bar--aff .bar-fill { transition: none; }
.dex-lore { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; line-height: 1.35; }
.dex-lore li::before { content: "> "; color: var(--muted); }
.dex-lore .is-locked { color: var(--muted); }

/* ---------- achievements ---------- */
.ach-list { display: flex; flex-direction: column; gap: 6px; }
.ach { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 8px 10px; border: 2px solid var(--ink); border-radius: var(--r-sm); background: var(--bg-2); opacity: 0.55; }
.ach.is-on { opacity: 1; }
.ach-badge { display: grid; place-items: center; width: 40px; height: 40px; border: 2px solid var(--ink); border-radius: 50%; background: var(--surface-3); font: 800 12px/1 var(--font-mono); color: var(--muted); }
.ach.is-on .ach-badge { background: var(--warn); color: var(--ink); }
.ach b { font-size: 14px; }
.ach p { font-size: 12.5px; color: var(--muted); }
.ach-when { font: 600 11px/1 var(--font-mono); color: var(--muted); white-space: nowrap; }
.ach.is-on .ach-when { color: var(--acid); }

/* ---------- daily quest ---------- */
.quest-streak { font: 500 13px/1.3 var(--font-mono); color: var(--muted); }
.quest-streak b { font-size: 24px; color: var(--hot); }
.quest-list { display: flex; flex-direction: column; gap: 8px; }
.quest { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 10px 12px; border: 2px solid var(--ink); border-radius: var(--r-sm); background: var(--bg-2); }
.quest-box { display: grid; place-items: center; width: 22px; height: 22px; border: 2px solid var(--text); font: 800 14px/1 var(--font-mono); color: var(--acid); }
.quest-info { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.quest-info b { font-size: 14px; }
.bar--quest { height: 8px; }
.quest-n { font: 600 11px/1 var(--font-mono); color: var(--muted); }
.quest.is-claimed { opacity: 0.55; }
.quest.is-claimed .quest-info b { text-decoration: line-through; }
.quest-claimed { font: 700 11px/1 var(--font-mono); color: var(--acid); }
.quest .btn { min-width: 96px; }

/* ---------- share ---------- */
.share-body { align-items: stretch; }
.share-canvas { width: 100%; height: auto; aspect-ratio: 1; border: 2px solid var(--ink); border-radius: var(--r-sm); background: var(--bg-2); }

/* ---------- branching choice ---------- */
.cut-actions--choice { flex-direction: column; align-items: stretch; }
.cut-opt { flex-direction: column; align-items: flex-start; gap: 2px; min-height: 56px; padding: 8px 14px; text-align: left; }
.cut-opt b { font-size: 15px; }
.cut-opt small { font: 500 11.5px/1.3 var(--font-mono); opacity: 0.85; }

.toast--ach { border-color: var(--warn); }
.toast--ach .toast-title { color: var(--warn); }
.start-menu .task-badge { position: static; margin-left: auto; }

@media (max-width: 719px) {
  .shop-item { grid-template-columns: 40px minmax(0, 1fr); }
  .shop-item .btn { grid-column: 1 / -1; min-height: 44px; }
  .boost-g--big, .swatch { width: 40px; height: 40px; }
  .quest { grid-template-columns: 24px minmax(0, 1fr); }
  .quest .btn, .quest-claimed { grid-column: 1 / -1; }
  .quest .btn { min-height: 44px; }
  .dex-grid { grid-template-columns: 1fr; }
}

/* ======================= Tutorial + save ======================= */

/* The layer itself ignores the pointer so the board stays playable under it. */
.coach { position: fixed; inset: 0; z-index: 70; pointer-events: none; }
.coach-spot {
  position: fixed;
  border: 3px solid var(--acid);
  border-radius: var(--r-md);
  /* 2000px is enough for any screen; much larger spreads are dropped by some GPUs. */
  box-shadow: 0 0 0 2000px rgba(5, 7, 13, 0.6);
  transition: left 220ms ease, top 220ms ease, width 220ms ease, height 220ms ease;
}
.coach-card {
  position: fixed;
  width: min(330px, calc(100vw - 24px));
  pointer-events: auto;
  transition: left 220ms ease, top 220ms ease;
}
.coach-step { font: 600 11px/1 var(--font-mono); opacity: 0.85; padding-right: 8px; white-space: nowrap; }
.coach-body { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px 16px; }
.coach-title { margin: 0; font: 800 19px/1.15 var(--font-ui); }
.coach-text { font-size: 14.5px; line-height: 1.45; }
.coach-note { font: 600 12px/1.3 var(--font-mono); color: var(--hot); }
.coach-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.coach-actions .btn { flex: 1 1 120px; }
.coach-actions .coach-skip { flex: 0 0 100%; min-height: 32px; font-size: 12.5px; }
.coach-themes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; flex: 0 0 100%; }
.coach-theme {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 6px 8px;
  border: 2px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-2);
  font-weight: 650;
  text-align: left;
}
.coach-theme .swatch { width: 34px; height: 34px; flex: none; }
.coach-theme.is-on { border-color: var(--acid); box-shadow: inset 0 0 0 2px var(--acid); }

/* Tutorial: the two tiles to swap. */
.tile.is-guide .tile-in::after {
  content: "";
  position: absolute;
  inset: 2px;
  border: 3px solid var(--acid);
  border-radius: var(--r-md);
  background: var(--acid-soft);
  animation: guide-pulse 1.2s ease-in-out infinite;
}
@keyframes guide-pulse { 50% { transform: scale(0.88); } }
.reduce-fx .tile.is-guide .tile-in::after { animation: none; }

/* Save indicator in the tray: lights up after each save. */
.tray-save svg { width: 16px; height: 16px; }
.tray-save.is-saved { color: var(--acid); }
.save-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.save-actions .btn { flex: 1 1 120px; }
.settings fieldset > .btn { align-self: flex-start; }

@media (max-width: 719px) {
  .coach-card { width: calc(100vw - 16px); }
  .tray-save { display: none; }
}

/* ---------- credits ---------- */
.cred { gap: 16px; }
.cred-kicker { font: 500 12px/1.4 var(--font-mono); color: var(--warn); }
.cred-title { font: clamp(28px, 5vw, 40px)/1 var(--font-stamp); color: var(--acid); margin: -6px 0 0; }
.cred-sec { display: flex; flex-direction: column; gap: 8px; }
.cred-sec dl { display: flex; flex-direction: column; border: 2px solid var(--ink); border-radius: var(--r-sm); background: var(--bg-2); }
.cred-item { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr); gap: 12px; padding: 10px 12px; }
.cred-item + .cred-item { border-top: 1px solid var(--line); }
.cred-item dt { font: 500 12px/1.4 var(--font-mono); color: var(--muted); }
.cred-item dd { display: flex; flex-direction: column; gap: 3px; }
.cred-item dd b { font-size: 15px; }
.cred-item dd a { color: var(--acid); text-underline-offset: 3px; }
.cred-item dd span { font-size: 13px; color: var(--muted); line-height: 1.4; }
.cred-tracks { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.cred-tracks li { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px; }
.cred-tracks code { font: 600 12px/1.5 var(--font-mono); color: var(--acid); }
.cred-tracks span { color: var(--muted); }
.cred-preview { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cred-label { font: 600 11px/1 var(--font-mono); color: var(--muted); margin-right: 4px; }
.cred-sfx { min-height: 34px; padding: 0 10px; font: 600 12px/1 var(--font-mono); }
.cred-outro { font-size: 13.5px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 12px; }

@media (max-width: 719px) {
  .cred-item { grid-template-columns: 1fr; gap: 4px; }
  .cred-tracks li { grid-template-columns: 1fr; gap: 0; }
  .cred-sfx { min-height: 44px; }
}
