:root {
  --ink: #f3e9d2;
  --ink-dim: #b9ad94;
  --panel: rgba(12, 18, 28, 0.86);
  --panel-line: rgba(120, 200, 235, 0.28);
  --cyan: #56d6ff;
  --ember: #ff7a2a;
  --green: #74cf5c;
  --serif: 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
  --sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #05070b; color: var(--ink);
  font-family: var(--sans);
  -webkit-user-select: none; user-select: none;
}

/* A fixed 1280x720 stage, scaled by script to fit the window. */
#stage {
  position: absolute; left: 0; top: 0;
  width: 1280px; height: 720px;
  transform-origin: 0 0;
  overflow: hidden; background: #0b0f17;
}
#game { position: absolute; inset: 0; width: 1280px; height: 720px; display: block; touch-action: none; }

.hidden { display: none !important; }

button {
  font: 600 15px var(--sans); color: var(--ink);
  background: rgba(20, 30, 44, 0.9);
  border: 1px solid var(--panel-line); border-radius: 6px;
  padding: 7px 14px; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}
button:hover { background: rgba(36, 54, 76, 0.95); border-color: var(--cyan); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
button.primary { background: linear-gradient(#2b8fc0, #1c6a94); border-color: #7fdcff; color: #fff; }
button.primary:hover { background: linear-gradient(#37a5db, #2380b0); }
button.quiet { background: none; border-color: transparent; color: var(--ink-dim); font-weight: 400; font-size: 13px; }
button.quiet:hover { color: var(--ink); border-color: var(--panel-line); background: none; }
button:disabled { opacity: 0.4; cursor: default; }
kbd {
  font: 600 11px var(--sans); padding: 2px 6px; margin-left: 8px;
  border: 1px solid rgba(255, 255, 255, 0.35); border-radius: 4px; background: rgba(0, 0, 0, 0.25);
}

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud button, #hud .tip, #hud .dry { pointer-events: auto; }
.hud-top {
  position: absolute; left: 0; right: 0; top: 0; height: 52px;
  display: flex; align-items: center; gap: 18px; padding: 0 14px;
  background: linear-gradient(rgba(6, 10, 16, 0.92), rgba(6, 10, 16, 0.62) 70%, rgba(6, 10, 16, 0));
}
.hud-title { font: 700 19px var(--serif); letter-spacing: 0.3px; white-space: nowrap; }
#hud-num { color: var(--ember); margin-right: 10px; }
.gauges { flex: 1; min-width: 0; display: flex; justify-content: center; gap: 18px; }
.gauge { display: flex; align-items: center; gap: 7px; font-size: 13px; min-width: 0; }
.gauge-label { color: var(--ink-dim); text-transform: uppercase; letter-spacing: 1px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.gauge-num { width: 40px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar { width: 120px; flex: 0 1 120px; min-width: 50px; height: 12px; border-radius: 7px; background: rgba(0, 0, 0, 0.55); border: 1px solid rgba(255, 255, 255, 0.18); overflow: hidden; }
.fill { height: 100%; width: 100%; border-radius: 6px; transition: width 0.2s linear; }
.fill.water { background: linear-gradient(#8fe6ff, #2aa3e6); }
.fill.green { background: linear-gradient(#a6ec86, #4faa3b); }
.fill.green.low { background: linear-gradient(#ffb35c, #e0531c); }
.fill.hero { background: linear-gradient(#ffe9a8, #e9b23c); }
.fill.hero.low { background: linear-gradient(#ff8a5c, #d8331c); }
.hud-buttons { display: flex; gap: 8px; }
.hud-buttons button { padding: 5px 11px; font-size: 13px; }

.tip {
  position: absolute; left: 16px; bottom: 16px; max-width: 420px;
  padding: 10px 14px; font-size: 14px; line-height: 1.45;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 8px;
  transition: opacity 0.6s;
}
.tip.faded { opacity: 0; pointer-events: none !important; }
.valve {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  font-size: 17px; padding: 11px 22px; border-radius: 26px;
  background: linear-gradient(#2b8fc0, #1c6a94); border-color: #7fdcff; color: #fff;
  box-shadow: 0 0 18px rgba(86, 214, 255, 0.35);
}
.valve:hover { background: linear-gradient(#37a5db, #2380b0); }
.valve:active { transform: translateX(-50%) translateY(1px); }
.valve.open { background: linear-gradient(#4b5563, #333c48); border-color: #9aa7b6; box-shadow: none; }
.valve.empty { opacity: 0.45; }
.dry {
  position: absolute; left: 50%; bottom: 74px; transform: translateX(-50%);
  padding: 8px 14px; background: var(--panel); border: 1px solid var(--ember); border-radius: 8px; font-size: 14px;
}
.dry button { margin-left: 10px; padding: 4px 10px; font-size: 13px; }

/* ---------- full screens ---------- */
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; }

#screen-title { justify-content: flex-start; background: linear-gradient(rgba(5, 8, 14, 0.15), rgba(5, 8, 14, 0.7)); }
#screen-title .logo { width: 330px; margin-top: 46px; filter: drop-shadow(0 8px 26px rgba(0, 0, 0, 0.7)); }
.tagline { font: italic 700 30px var(--serif); margin-top: -2px; text-shadow: 0 2px 10px #000; letter-spacing: 1px; }
.menu { display: flex; flex-direction: column; gap: 12px; margin-top: 34px; width: 250px; }
.menu button { font-size: 19px; padding: 12px; font-family: var(--serif); letter-spacing: 0.5px; }
.footnote { position: absolute; bottom: 22px; font: italic 16px var(--serif); color: var(--ink); text-shadow: 0 1px 6px #000; opacity: 0.9; }

#screen-story { background: #000; }
.slide { position: absolute; inset: 0; background-size: cover; background-position: center; opacity: 0; transition: opacity 1.4s ease-in-out; }
.slide.show { opacity: 1; }
.caption-wrap { position: absolute; left: 0; right: 0; bottom: 0; padding: 90px 200px 46px; background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.82)); text-align: center; }
.caption { font: 24px/1.5 var(--serif); text-shadow: 0 2px 8px #000; transition: opacity 0.7s; }
.caption.out { opacity: 0; }
.continue { position: absolute; right: 26px; bottom: 20px; background: none; border: none; font: 36px 'Brush Script MT', 'Segoe Script', cursive; color: #fff; text-shadow: 0 2px 8px #000; }
.continue:hover { background: none; color: var(--cyan); }
.skip { position: absolute; right: 22px; top: 18px; background: rgba(0, 0, 0, 0.4); font-size: 13px; }

#screen-levels { background: linear-gradient(rgba(6, 9, 15, 0.86), rgba(6, 9, 15, 0.94)); padding-top: 40px; }
#screen-levels h1 { font: 700 36px var(--serif); margin: 0 0 26px; }
.level-grid { display: grid; grid-template-columns: repeat(5, 208px); gap: 16px; }
.level-card {
  height: 150px; padding: 12px 14px; text-align: left; position: relative;
  display: flex; flex-direction: column; justify-content: space-between;
  background-size: cover; background-position: center; border-radius: 10px; overflow: hidden;
}
.level-card::before { content: ''; position: absolute; inset: 0; background: linear-gradient(rgba(8, 12, 20, 0.5), rgba(8, 12, 20, 0.88)); transition: background 0.15s; }
.level-card:hover::before { background: linear-gradient(rgba(8, 12, 20, 0.3), rgba(8, 12, 20, 0.8)); }
.level-card > * { position: relative; }
.level-card .n { font: 700 34px var(--serif); color: var(--ember); line-height: 1; }
.level-card .nm { font: 700 17px var(--serif); }
.level-card .st { font-size: 20px; letter-spacing: 3px; color: #ffd45a; }
.level-card .st i { font-style: normal; color: rgba(255, 255, 255, 0.22); }
.level-card.locked { filter: grayscale(1) brightness(0.75); opacity: 0.85; }
.level-card.locked .st { font-size: 13px; letter-spacing: 0; color: var(--ink-dim); }
.levels-foot { margin-top: 26px; width: 1104px; display: flex; align-items: center; justify-content: space-between; }
.star-total { font: 700 18px var(--serif); color: #ffd45a; }

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(4, 6, 10, 0.62); }
.panel { min-width: 430px; max-width: 560px; padding: 28px 34px; text-align: center; background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px; box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6); }
.panel h2 { font: 700 32px var(--serif); margin: 0 0 12px; }
.panel p { font: 17px/1.55 var(--serif); margin: 0 0 22px; color: var(--ink); }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--ember); margin-bottom: 6px; }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
.stars { font-size: 54px; letter-spacing: 12px; margin: 4px 0 10px; height: 66px; }
.stars span { display: inline-block; color: rgba(255, 255, 255, 0.16); transform: scale(0.6); transition: transform 0.35s cubic-bezier(0.2, 1.6, 0.4, 1), color 0.35s; }
.stars span.on { color: #ffd45a; transform: scale(1); text-shadow: 0 0 18px rgba(255, 200, 70, 0.7); }
.stats { font-size: 15px; line-height: 1.9; margin-bottom: 18px; color: var(--ink); }
.stats .ok { color: var(--green); font-weight: 700; }
.stats .no { color: var(--ink-dim); }
.help { text-align: left; font-size: 15px; line-height: 2; margin: 6px 0 20px; }
.help b { color: var(--cyan); }
