:root {
  /* the night look, as every Deepwing game (this product's own); the light look is chosen with the switch beside Home */
  --bg: #141a24;
  --bg2: #222c3b;
  --ink: #e8edf5;
  --inkDim: #9aa8bd;
  --line: #34425a;
  --accent: #f98c2e;
  --accentInk: #10151e;
  --sel: #33415a;
  --now: #ffd166;
  --stageBg: #0b0f16;
  --shade: rgba(16, 22, 32, 0.92);
  --toastBg: #fdfaf2;
  --toastInk: #141a24;
  --danger: #ff8a80;
  --star: #ffd166;
}
:root[data-theme="light"] {
  --bg: #eef2f7;
  --bg2: #dbe3ee;
  --ink: #10151e;
  --inkDim: #45526a;
  --line: #a9b6c9;
  --accent: #c2560a;
  --accentInk: #ffffff;
  --sel: #c9d6e8;
  --now: #b97400;
  --stageBg: #1b2431;
  --shade: rgba(238, 242, 247, 0.94);
  --toastBg: #10151e;
  --toastInk: #ffffff;
  --danger: #b42318;
  --star: #b97400;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  color: var(--ink); user-select: none; -webkit-user-select: none; overflow: hidden;
}
#app { height: 100%; display: flex; flex-direction: column; max-width: min(100%, 900px); margin: 0 auto; }

#hdr { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
#hdr .pill { background: var(--bg2); border: 2px solid var(--line); border-radius: 999px; padding: 6px 11px; font-weight: 800; font-size: 15px; min-width: 44px; min-height: 44px; display: flex; align-items: center; cursor: pointer; justify-content: center; color: inherit; font-family: inherit; }
#hdrHome { border: none; background: var(--accent); color: var(--accentInk); font-size: 18px; }
#hdrStatus { flex: 1; min-width: 0; text-align: center; font-weight: 800; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }

.scr { flex: 1; display: none; flex-direction: column; overflow-y: auto; padding: 6px 14px 18px; gap: 10px; min-height: 0; }
.scr.on { display: flex; }
.scrTitle { color: var(--ink); font-size: 22px; }

#scr-menu { align-items: center; text-align: center; justify-content: center; }
#scr-menu h1 { font-size: clamp(28px, 8vw, 44px); color: var(--ink); }
#scr-menu .sub { color: var(--inkDim); font-weight: 600; }
.menuGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
button.big { width: 100%; border-radius: 16px; min-height: 52px; font-size: 18px; font-weight: 800; background: var(--bg2); color: var(--ink); border: 3px solid var(--line); cursor: pointer; font-family: inherit; padding: 6px 10px; }
button.big:active { transform: translateY(2px); }
button.big.primary { background: var(--accent); border-color: var(--accent); color: var(--accentInk); }
button.big.danger { border-color: var(--danger); color: var(--danger); min-height: 52px; }
button.big:disabled { opacity: 0.5; cursor: default; }
#statsLine { color: var(--inkDim); font-weight: 700; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.seg button { flex: 1; min-height: 44px; min-width: 64px; border-radius: 12px; border: 3px solid var(--line); background: var(--bg); color: var(--ink); font: 800 15px inherit; font-family: inherit; cursor: pointer; }
.seg button.sel { border-color: var(--accent); background: var(--sel); }

/* levels */
.world { display: flex; flex-direction: column; gap: 6px; }
.world h3 { font-size: 17px; }
.lvRow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.lv { min-height: 60px; border-radius: 14px; border: 3px solid var(--line); background: var(--bg2); color: var(--ink); font-family: inherit; font-weight: 800; font-size: 17px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.lv span { font-size: 12px; color: var(--star); letter-spacing: 1px; }
.lv:disabled { opacity: 0.45; cursor: default; }
.lv.cur { border-color: var(--accent); }

/* playing: the board, then the program row, the cards and the jobs */
#scr-play { padding: 0 6px 6px; gap: 6px; }
#stageWrap { position: relative; flex: 1; min-height: 170px; border-radius: 14px; overflow: hidden; background: var(--stageBg); }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#stat { position: absolute; left: 0; right: 0; top: 6px; text-align: center; font-weight: 800; font-size: 15px; color: var(--ink); text-shadow: 0 0 6px var(--bg), 0 0 2px var(--bg); pointer-events: none; padding: 0 10px; }
#hint { position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; font-weight: 800; font-size: 15px; color: var(--ink); text-shadow: 0 0 6px var(--bg), 0 0 2px var(--bg); pointer-events: none; padding: 0 10px; }
#glFail { position: absolute; inset: 12px; display: flex; align-items: center; justify-content: center; text-align: center; background: var(--shade); color: var(--ink); border-radius: 14px; padding: 16px; font-weight: 700; }
#glFail[hidden] { display: none; }
#fpsNow { position: absolute; top: 6px; left: 8px; font: 700 12px ui-monospace, monospace; color: var(--ink); background: var(--shade); border-radius: 6px; padding: 2px 6px; pointer-events: none; }
#controls { display: flex; flex-direction: column; gap: 6px; padding-bottom: env(safe-area-inset-bottom); }
#prog { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; min-height: 48px; padding: 4px; border-radius: 12px; border: 2px dashed var(--line); background: var(--bg); }
.slot { min-height: 44px; min-width: 0; border-radius: 10px; border: 2px solid var(--line); background: var(--bg2); color: var(--ink); font-family: inherit; font-size: 20px; font-weight: 800; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.slot.empty { border-style: dotted; background: transparent; color: var(--inkDim); cursor: default; font-size: 14px; }
.slot.now { border-color: var(--now); box-shadow: 0 0 0 3px var(--now); }
.slot.rep { font-size: 15px; }
#palette, #acts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
#acts { grid-template-columns: 2fr 1fr 1fr 1fr; }
.card, .act { min-height: 54px; min-width: 0; border-radius: 14px; border: 3px solid var(--line); background: var(--bg2); color: var(--ink); font-family: inherit; font-size: 22px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px; }
.card span, .act span { font-size: 12px; font-weight: 800; white-space: nowrap; }
.card:disabled, .act:disabled { opacity: 0.4; cursor: default; }
.card.off { visibility: hidden; }
.act.go { border-color: var(--accent); }
.act.on { border-color: var(--accent); border-style: dashed; }
@media (min-aspect-ratio: 5/4) {
  #scr-play { flex-direction: row; }
  #controls { width: 300px; flex: none; justify-content: center; }
}

/* done, help and settings */
#doneStars { font-size: 52px; text-align: center; letter-spacing: 6px; color: var(--star); }
.card2 { background: var(--bg2); border: 2px solid var(--line); border-radius: 16px; padding: 12px 14px; line-height: 1.45; display: flex; flex-direction: column; gap: 8px; }
.card2 h2 { font-size: 19px; }
.setRow { display: flex; flex-direction: column; gap: 6px; }
.setNote { color: var(--inkDim); font-weight: 600; font-size: 14px; }

#toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--toastBg); color: var(--toastInk); padding: 10px 16px; border-radius: 14px; font-weight: 800; opacity: 0; transition: opacity 0.2s; pointer-events: none; max-width: 90%; text-align: center; z-index: 10; }
#toast.on { opacity: 1; }
#footer { display: flex; justify-content: center; padding: 2px 0 calc(2px + env(safe-area-inset-bottom)); }
@media (prefers-reduced-motion: reduce) { button.big:active { transform: none; } }
