/* =============================================================================
 * Lumen Path - styles/main.css
 * -----------------------------------------------------------------------------
 * A dark, low-chroma shell so the beams are the brightest thing on screen.
 * Everything in here is deliberately quiet: the canvas is the interface, and
 * the chrome exists to stay out of its way.
 *
 * Layout is a full-viewport stage with the HUD floating over it. Every control
 * for a piece lives on the bench itself, so the only chrome is the HUD and the
 * tray -- and the renderer measures both and fits the stage around them. On a
 * portrait phone the HUD packs into two rows and the stage turns sideways; on
 * a landscape phone the tray becomes a rail down the right-hand edge.
 * ========================================================================== */

:root {
  /* Workshop palette: dark walnut panels, brass accents -- chosen to sit on
   * the wooden bench rather than float over it in cold blue. */
  --bg: #0a0705;
  --panel: rgba(23, 17, 13, 0.86);
  --panel-solid: #18120e;
  --line: rgba(232, 202, 160, 0.14);
  --line-strong: rgba(236, 206, 166, 0.30);
  --text: #f4ede5;
  --text-dim: #c0af9c;
  --text-faint: #8f7f6e;
  --accent: #e8b25c;
  --accent-warm: #ffd27a;
  --good: #8fe6a2;
  --bad: #ff8270;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  touch-action: manipulation;
  /* A long press on the bench must not select text or open a callout. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
input, textarea, select { -webkit-user-select: text; user-select: text; }

#app { position: fixed; inset: 0; }

.noscript {
  position: fixed; inset: 0; display: grid; place-content: center;
  text-align: center; padding: 2rem; color: var(--text);
}

/* ===========================================================================
 * Stage
 * ======================================================================== */
.stage-wrap { position: absolute; inset: 0; }

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: default;
}

/* ===========================================================================
 * HUD
 * ======================================================================== */
.hud {
  position: absolute;
  left: 0; right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  pointer-events: none;
  z-index: 5;
}
.hud > * { pointer-events: auto; }
.hud-top { top: 0; padding-top: max(12px, env(safe-area-inset-top)); }
.hud-bottom {
  bottom: 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  justify-content: center;
}

.hud-left, .hud-right { display: flex; align-items: center; gap: 10px; }
/* On a narrow phone the right-hand button cluster must wrap rather than run
   off the edge of the screen. */
.hud-right { flex-wrap: wrap; justify-content: flex-end; row-gap: 6px; }

.level-id {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 14px;
  backdrop-filter: blur(10px);
  max-width: 46vw;
}
.level-name { font-weight: 650; font-size: 15px; letter-spacing: 0.01em;
              display: flex; align-items: center; gap: 8px; min-width: 0; }
.boss-chip {
  flex: none;
  font-size: 9px; font-weight: 750; letter-spacing: 0.12em; text-transform: uppercase;
  color: #1a0f00; background: var(--accent-warm);
  padding: 2px 6px; border-radius: 4px;
  box-shadow: 0 0 12px rgba(255, 196, 107, 0.45);
}
.level-sub {
  font-size: 12px; color: var(--text-dim); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 18px; line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: background 120ms, border-color 120ms, transform 80ms;
}
.icon-btn:hover:not(:disabled) { background: rgba(52, 40, 30, 0.92); border-color: var(--line-strong); }
.icon-btn:active:not(:disabled) { transform: scale(0.94); }
.icon-btn:disabled { opacity: 0.32; cursor: default; }
.icon-btn.small { width: 28px; height: 28px; font-size: 15px; }

.par-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  backdrop-filter: blur(10px);
  font-variant-numeric: tabular-nums;
}
.par-item { display: flex; align-items: baseline; gap: 5px; font-size: 12px; }
.par-k { color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.07em; font-size: 10px; }
.par-v { font-weight: 650; font-family: var(--mono); }
.par-v.good { color: var(--good); }
.par-v.over { color: var(--accent-warm); }
.par-label { color: var(--text-dim); font-size: 12px; letter-spacing: 0.05em; }

.stars { display: inline-flex; gap: 1px; }
.star { color: rgba(150, 170, 200, 0.26); font-size: 14px; line-height: 1; }
.star.on { color: var(--accent-warm); text-shadow: 0 0 10px rgba(255, 196, 107, 0.55); }

/* ===========================================================================
 * Inventory tray
 * ======================================================================== */
.tray {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; flex-wrap: wrap;
  max-width: min(96vw, 1100px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}
.tray:empty { display: none; }

.tray-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 72px;
  padding: 8px 10px 6px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  transition: background 120ms, border-color 120ms, transform 80ms;
}
.tray-item:hover:not(:disabled) { background: rgba(232, 178, 92, 0.10); }
.tray-item:active:not(:disabled) { transform: translateY(1px); }
.tray-item.armed {
  border-color: var(--accent);
  background: rgba(232, 178, 92, 0.16);
  box-shadow: 0 0 0 1px rgba(232, 178, 92, 0.3), 0 0 22px rgba(232, 178, 92, 0.22);
}
.tray-item.spent { opacity: 0.3; cursor: default; }
.tray-ico { color: var(--accent); display: block; }
.tray-item.armed .tray-ico { color: #fff; }
.tray-name { font-size: 11px; color: var(--text-dim); }
.tray-count { font-size: 11px; font-family: var(--mono); color: var(--text); font-weight: 650; }
.tray-hint, .tray-empty {
  font-size: 12px; color: var(--text-faint); padding: 0 10px; align-self: center;
}

/* ===========================================================================
 * Status strip (timed levels, multiplayer)
 * ======================================================================== */
.status-strip {
  position: absolute;
  left: 50%;
  top: calc(var(--inset-top, 64px) + 4px);
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 12px;
  backdrop-filter: blur(10px);
  pointer-events: none;
  z-index: 4;
}
.strip-label { color: var(--text-dim); letter-spacing: 0.05em; text-transform: uppercase; font-size: 10px; }
.strip-val { font-family: var(--mono); font-weight: 650; }
.strip-bar {
  display: block; width: 140px; height: 6px;
  background: rgba(255, 255, 255, 0.10);
  border-radius: 3px; overflow: hidden;
}
.strip-bar i {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--good));
  transition: width 90ms linear;
}

/* ===========================================================================
 * Form rows (multiplayer and editor sheets)
 * ======================================================================== */
.prop-row {
  display: grid;
  grid-template-columns: 74px 1fr;
  grid-template-areas: "label value" "input input";
  align-items: center;
  gap: 4px 8px;
  margin-bottom: 12px;
}
.prop-row.column { grid-template-columns: 1fr; grid-template-areas: "label" "input"; }
.prop-label { grid-area: label; font-size: 11px; color: var(--text-faint);
              text-transform: uppercase; letter-spacing: 0.07em; }
.prop-row select, .prop-row .text-input { grid-area: input; }

select, .text-input, textarea, input[type="number"] {
  width: 100%;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 7px 10px;
  font-family: inherit;
  font-size: 13px;
}
select:focus, .text-input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.wide-btn {
  display: block; width: 100%; text-align: center;
  margin-top: 8px; padding: 9px 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text); font-family: inherit; font-size: 13px; cursor: pointer;
}
.wide-btn:hover { background: rgba(255, 255, 255, 0.11); }
.wide-btn.danger { color: var(--bad); border-color: rgba(255, 122, 122, 0.3); }
.wide-btn.danger:hover { background: rgba(255, 122, 122, 0.12); }
.filelabel { position: relative; overflow: hidden; }
.filelabel input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.readout-line { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; padding: 3px 0; }
.rk { color: var(--text-faint); }
.rv { font-family: var(--mono); }

/* ===========================================================================
 * Overlay screens
 * ======================================================================== */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(4, 6, 12, 0.72);
  backdrop-filter: blur(7px);
  overflow-y: auto;
  animation: fade 180ms ease-out;
}
.overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
  background: var(--panel-solid);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: var(--shadow);
  animation: rise 220ms cubic-bezier(0.2, 0.9, 0.3, 1);
}
.sheet.wide { width: min(940px, 100%); }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

.sheet-head { position: relative; padding: 22px 24px 12px; }
.sheet-head h2 { margin: 0; font-size: 22px; font-weight: 660; letter-spacing: -0.01em; }
.sheet-sub { margin: 6px 0 0; color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.sheet-close { position: absolute; top: 16px; right: 16px; }
.sheet-body { padding: 6px 24px 8px; overflow-y: auto; flex: 1; }
.sheet-lead { color: var(--text-dim); font-size: 13px; line-height: 1.6; margin: 0 0 14px; }
.sheet-actions {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 14px 24px 20px; border-top: 1px solid var(--line);
}

.big-btn {
  flex: 1 1 auto; min-width: 116px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit; font-size: 14px; font-weight: 550;
  cursor: pointer;
  transition: background 130ms, transform 80ms, border-color 130ms;
}
.big-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); border-color: var(--line-strong); }
.big-btn:active:not(:disabled) { transform: translateY(1px); }
.big-btn:disabled { opacity: 0.45; cursor: default; }
.big-btn.primary {
  background: linear-gradient(180deg, rgba(232, 178, 92, 0.24), rgba(232, 178, 92, 0.12));
  border-color: rgba(232, 178, 92, 0.5);
  color: #fff4e2;
}
.big-btn.primary:hover { background: rgba(232, 178, 92, 0.3); }
.big-btn.ghost { background: transparent; color: var(--text-dim); }

/* ---- Title ------------------------------------------------------------- */
.screen-title .sheet-actions { flex-direction: column; }
.screen-title .big-btn { flex: none; width: 100%; }
.title-art { margin: 6px 0 12px; opacity: 0.95; }
.title-stats { text-align: center; color: var(--text-faint); font-size: 12px; }

/* ---- Level select ------------------------------------------------------ */
.chapter { margin-bottom: 26px; }
.chapter.locked { opacity: 0.5; }
.chapter-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 14px;
  border-left: 3px solid var(--line-strong);
  padding: 2px 0 2px 12px; margin-bottom: 12px;
}
.chapter-head h3 { margin: 0; font-size: 16px; font-weight: 650; }
.chapter-blurb { margin: 3px 0 0; font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.chapter-meta { text-align: right; white-space: nowrap; }
.chapter-teaches {
  display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--text-faint);
}
.lock-note { display: block; font-size: 11px; color: var(--accent-warm); margin-top: 4px; }

.level-grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
}
.level-card {
  position: relative;
  display: flex; flex-direction: column; gap: 5px;
  padding: 10px 12px;
  min-height: 78px;
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit; cursor: pointer;
  transition: background 130ms, border-color 130ms, transform 80ms;
}
.level-card:hover:not(:disabled) { background: rgba(232, 178, 92, 0.1); border-color: var(--accent); }
.level-card:active:not(:disabled) { transform: translateY(1px); }
.level-card.disabled { opacity: 0.35; cursor: default; }
.level-card.solved { border-color: rgba(107, 255, 171, 0.3); }
.level-card.boss { background: rgba(255, 196, 107, 0.07); }
.level-num { font-family: var(--mono); font-size: 11px; color: var(--text-faint); }
.level-title { font-size: 13px; font-weight: 550; line-height: 1.25; flex: 1; }
.level-tag { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; }
.boss-flag {
  position: absolute; top: 8px; right: 10px;
  font-size: 9px; letter-spacing: 0.12em; color: var(--accent-warm);
}

/* ---- Win --------------------------------------------------------------- */
.win-stars { text-align: center; margin: 4px 0 10px; }
.win-stars .star { font-size: 38px; }
.win-note { text-align: center; color: var(--text-dim); font-size: 13px; margin: 0 0 16px; }
.win-table {
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px;
}

/* ---- Settings ---------------------------------------------------------- */
.setting-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.setting-row input[type="checkbox"] { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); }
.setting-row select { width: auto; min-width: 116px; }
.setting-label { display: block; font-size: 14px; }
.setting-note { display: block; font-size: 12px; color: var(--text-faint); line-height: 1.5; margin-top: 3px; }
.setting-actions { margin-top: 18px; display: grid; gap: 8px; }
.warn-note {
  margin: 14px 0 0; padding: 10px 12px; font-size: 12px; line-height: 1.55;
  color: var(--accent-warm);
  background: rgba(255, 196, 107, 0.08);
  border: 1px solid rgba(255, 196, 107, 0.24);
  border-radius: var(--radius-sm);
}

.keyhelp { margin-top: 22px; }
.keyhelp h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase;
              letter-spacing: 0.08em; color: var(--text-faint); }
.keyhelp dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; font-size: 12px; }
.keyhelp dt { font-family: var(--mono); color: var(--accent); white-space: nowrap; }
.keyhelp dd { margin: 0; color: var(--text-dim); }

/* ---- Daily ------------------------------------------------------------- */
.daily-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; margin-bottom: 14px;
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--line); border-radius: 10px;
}
.daily-date { font-family: var(--mono); font-size: 15px; }
.daily-count { font-size: 12px; color: var(--text-dim); font-family: var(--mono); }
.leaderboard { margin-top: 16px; }
.leaderboard h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase;
                  letter-spacing: 0.08em; color: var(--text-faint); }
.board-note { font-size: 12px; color: var(--text-faint); line-height: 1.6; margin: 0; }
.board-list { list-style: none; margin: 0; padding: 0; }
.board-list li {
  display: flex; gap: 10px; align-items: baseline;
  padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px;
}
.board-rank { font-family: var(--mono); color: var(--text-faint); width: 36px; }
.board-name { flex: 1; }
.board-score { font-family: var(--mono); color: var(--text-dim); font-size: 12px; }

/* ---- Editor ------------------------------------------------------------ */
.editor-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.editor-cols h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase;
                  letter-spacing: 0.08em; color: var(--text-faint); }
.palette-group { margin-bottom: 12px; }
.palette-items { display: flex; flex-wrap: wrap; gap: 6px; }
.palette-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text); font-size: 12px; font-family: inherit; cursor: pointer;
}
.palette-item:hover { background: rgba(232, 178, 92, 0.12); border-color: var(--accent); }
.palette-item .ico { color: var(--accent); display: flex; }

.inv-editor { display: grid; gap: 4px; }
.inv-row {
  display: grid; grid-template-columns: 22px 1fr 62px; align-items: center; gap: 8px;
  font-size: 12px; padding: 3px 0;
}
.inv-row .ico { color: var(--text-dim); display: flex; }
.inv-row input { padding: 4px 6px; text-align: right; }

.validate {
  margin-top: 16px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(0, 0, 0, 0.24);
}
.validate.ok { border-color: rgba(107, 255, 171, 0.32); }
.validate.bad { border-color: rgba(255, 196, 107, 0.32); }
.validate h4 { margin: 0 0 6px; }
.v-problem { margin: 4px 0; font-size: 12px; color: var(--bad); line-height: 1.5; }
.v-warn { margin: 4px 0; font-size: 12px; color: var(--accent-warm); line-height: 1.5; }

.code-box { width: 100%; font-family: var(--mono); font-size: 11px; resize: vertical; word-break: break-all; }

/* ===========================================================================
 * Toasts
 * ======================================================================== */
.toasts {
  position: absolute; left: 50%;
  bottom: calc(var(--inset-bottom, 96px) + 10px);
  transform: translateX(-50%);
  display: flex; flex-direction: column-reverse; gap: 8px;
  z-index: 30; pointer-events: none;
  width: min(440px, 90vw);
}
.toast {
  padding: 10px 16px;
  background: rgba(18, 24, 38, 0.95);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  font-size: 13px; line-height: 1.45; text-align: center;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px);
  transition: opacity 260ms, transform 260ms;
}
.toast.in { opacity: 1; transform: none; }
.toast.good { border-color: rgba(107, 255, 171, 0.45); color: #d8ffe9; }
.toast.bad { border-color: rgba(255, 122, 122, 0.45); color: #ffdede; }

/* ===========================================================================
 * Responsive
 * ======================================================================== */
@media (max-width: 900px) {
  .level-sub { display: none; }
  .editor-cols { grid-template-columns: 1fr; gap: 12px; }
}

/* ---------------------------------------------------------------------------
 * Phones, portrait and narrow.
 *
 * Two compact HUD rows: identity on top, score and actions underneath. The
 * tray is a single row that scrolls sideways instead of wrapping, so its
 * height never changes and the stage is never re-fitted mid-game.
 * ------------------------------------------------------------------------ */
@media (max-width: 620px) {
  body { font-size: 14px; }
  .hud { padding: 6px 8px; gap: 6px; }
  .hud-top { flex-wrap: wrap; row-gap: 6px; }
  .hud-left { flex: 1 1 100%; min-width: 0; gap: 6px; }
  .hud-right { flex: 1 1 100%; justify-content: space-between; flex-wrap: nowrap; gap: 5px; }
  .level-id { flex: 1; min-width: 0; max-width: none; padding: 6px 10px; }
  .level-name { font-size: 14px; }
  .level-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .icon-btn { width: 36px; height: 36px; font-size: 16px; flex: none; }
  .par-box { padding: 5px 8px; gap: 7px; flex: 1 1 auto; min-width: 0; overflow: hidden; }
  .par-item { font-size: 11px; }

  .hud-bottom { padding: 6px 8px max(8px, env(safe-area-inset-bottom)); }
  .tray {
    flex-wrap: nowrap; justify-content: flex-start;
    overflow-x: auto; overscroll-behavior-x: contain;
    max-width: calc(100vw - 16px);
    gap: 5px; padding: 6px; border-radius: 12px;
    scrollbar-width: none;
  }
  .tray::-webkit-scrollbar { display: none; }
  .tray-item { flex: 0 0 auto; min-width: 58px; padding: 7px 8px 5px; }
  .tray-name, .tray-hint, .tray-empty { display: none; }

  .sheet { border-radius: 14px; }
  .sheet-head { padding: 16px 16px 10px; }
  .sheet-body { padding: 4px 16px 6px; }
  .sheet-actions { padding: 12px 16px 16px; }
  .level-grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
  .status-strip { padding: 5px 12px; }
  .strip-bar { width: 92px; }
}

/* Most phones in portrait: five buttons and the score will not all fit at
   full size, so the stars (also shown on the win screen) step aside first. */
@media (max-width: 420px) {
  .par-box .stars { display: none; }
  .icon-btn { width: 34px; height: 34px; }
  .hud-right { gap: 4px; }
}
@media (max-width: 340px) {
  .icon-btn { width: 31px; height: 31px; font-size: 14px; }
  .par-k { display: none; }
}

/* ---------------------------------------------------------------------------
 * Portrait phones on levels that cannot turn the stage (pendulums): a hint,
 * never a gate. Visibility is set from JavaScript.
 * ------------------------------------------------------------------------ */
.rotate-hint {
  position: absolute;
  left: 50%;
  top: calc(var(--inset-top, 96px) + 40px);
  transform: translateX(-50%);
  display: flex;
  align-items: center; gap: 8px;
  padding: 7px 14px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 12px; color: var(--text-dim);
  white-space: nowrap;
  backdrop-filter: blur(10px);
  pointer-events: none;
  z-index: 4;
}
.rotate-hint[hidden] { display: none; }
.rotate-hint span { font-size: 15px; }

/* ---------------------------------------------------------------------------
 * Phones, landscape.
 *
 * Height is the scarce dimension, so the HUD collapses to a single row and the
 * tray moves off the bottom edge entirely, into a rail down the right. The
 * renderer notices the rail (it measures the tray's flex direction) and fits
 * the stage to its left.
 * ------------------------------------------------------------------------ */
@media (max-height: 520px) and (orientation: landscape) {
  .hud { padding: 5px 8px; gap: 6px; }
  .hud-top {
    flex-wrap: nowrap;
    padding-top: max(5px, env(safe-area-inset-top));
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }
  .hud-left { min-width: 0; flex: 1 1 auto; }
  .hud-right { flex-wrap: nowrap; gap: 5px; }
  .level-id { padding: 5px 10px; min-width: 0; max-width: 34vw; }
  .level-name { font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .level-sub { display: none; }
  .icon-btn { width: 34px; height: 34px; font-size: 15px; }
  .par-box { padding: 4px 8px; gap: 6px; }

  .hud-bottom {
    top: calc(var(--inset-top, 50px) - 2px);
    bottom: 0; left: auto; right: 0;
    flex-direction: column; justify-content: center; align-items: center;
    padding: 4px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) 4px;
  }
  .tray {
    flex-direction: column; flex-wrap: nowrap;
    max-height: 100%; overflow-y: auto; overscroll-behavior-y: contain;
    gap: 4px; padding: 5px; border-radius: 12px;
    scrollbar-width: none;
  }
  .tray::-webkit-scrollbar { display: none; }
  .tray-item { flex: 0 0 auto; min-width: 56px; padding: 6px 6px 4px; }
  .tray-name, .tray-hint, .tray-empty { display: none; }

  .overlay { padding: 10px; }
  .sheet { max-height: calc(100vh - 20px); }
  .sheet-head { padding: 12px 16px 6px; }
  .sheet-head h2 { font-size: 18px; }
  .sheet-actions { padding: 10px 16px 12px; }
  .title-art { display: none; }
  .screen-title .sheet-actions { flex-direction: row; flex-wrap: wrap; }
  .screen-title .big-btn { flex: 1 1 40%; width: auto; padding: 9px 12px; }
  .win-stars .star { font-size: 28px; }
  .toasts { left: calc(50% - var(--inset-right, 0px) / 2); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
