/* ============================================================
   TOWER DEFENSE — UI STYLESHEET
   The entire HUD look lives in this file. Reskin freely: the
   game logic only depends on the element IDs (see js/ui.js).
   ============================================================ */

:root {
  --bg:        #14161c;
  --panel:     #20242f;
  --panel-2:   #2a2f3d;
  --border:    #3a4152;
  --text:      #e8eaf0;
  --text-dim:  #9aa1b4;
  --gold:      #e8b64c;
  --accent:    #4aa3c0;
  --good:      #5ad05a;
  --bad:       #e2574c;
  --radius:    8px;
  --chrome-h:  52px;   /* height of the site-chrome (Main menu) bar */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

#app { display: flex; flex-direction: column; gap: 10px; padding: 10px; max-width: 1720px; margin: 0 auto; }

/* ============================================================
   HOME SCREEN
   ============================================================ */
#home {
  min-height: calc(100vh - var(--chrome-h));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(226, 87, 76, 0.25), transparent 60%),
    radial-gradient(900px 500px at 90% 110%, rgba(74, 163, 192, 0.18), transparent 60%),
    var(--bg);
}
#home.hidden { display: none; }
.home-inner { width: 100%; max-width: 920px; display: flex; flex-direction: column; gap: 26px; }

.home-hero { text-align: center; display: flex; flex-direction: column; gap: 8px; }
.home-emoji { font-size: 60px; line-height: 1; }
.home-hero h1 {
  font-size: 44px; letter-spacing: 0.5px;
  background: linear-gradient(90deg, #f4c56a, #e2574c 60%, #c94b8f);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.home-sub { color: var(--text-dim); font-size: 16px; max-width: 620px; margin: 0 auto; line-height: 1.5; }

.home-h2 { text-align: center; font-size: 15px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text-dim); margin-bottom: 14px; }
#homeStep2 { display: flex; flex-direction: column; }

#modeCards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
#levelCards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

.mode-card, .level-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
  display: flex; flex-direction: column; gap: 8px;
}
.mode-card:hover, .level-card:hover {
  transform: translateY(-3px);
  border-color: var(--gold);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.mode-card .mode-icon { font-size: 34px; }
.mode-card h3 { font-size: 20px; }
.mode-card .mode-tag { color: var(--gold); font-weight: 600; font-size: 13px; }
.mode-card p { color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.mode-card .mode-enzymes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip {
  font-size: 11px; padding: 3px 8px; border-radius: 20px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
}

.level-card { align-items: center; text-align: center; padding: 16px; }
.level-card .level-emoji { font-size: 40px; }
.level-card h3 { font-size: 16px; }
.level-card .level-enzymes { color: var(--text-dim); font-size: 12px; line-height: 1.4; }
.level-num { font-size: 11px; color: var(--text-dim); letter-spacing: 1px; text-transform: uppercase; }

.linklike {
  align-self: flex-start;
  background: none; border: none; color: var(--accent);
  cursor: pointer; padding: 4px 0; font-size: 13px; margin-bottom: 6px;
}
.linklike:hover { text-decoration: underline; }
.home-foot { text-align: center; color: var(--text-dim); font-size: 12px; }

/* ---------- Site chrome bar (chermistry.com "Main menu" tab) ----------
   Matches the shared exhibit chrome used across chermistry.com: a dark bar
   with a brass border, a gold pixel "← MAIN MENU" button, and the page title.
   Sits above the whole page (home + game), sticky to the top. */
#siteChrome {
  position: sticky; top: 0; z-index: 45;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 9px 16px;
  background: linear-gradient(180deg, #11161e, #0c0f14);
  border-bottom: 3px solid #8a6f3c;
}
.chrome-back {
  font-family: 'MinecraftFont', ui-monospace, monospace;
  font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  text-decoration: none; color: #d9a441;
  background: rgba(217, 164, 65, 0.12);
  border: 2px solid #8a6f3c; padding: 7px 12px;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.chrome-back:hover, .chrome-back:focus-visible { background: #d9a441; color: #3a2c08; }
.chrome-ttl {
  font-family: 'MinecraftFont', ui-monospace, monospace;
  font-size: 13px; letter-spacing: 0.03em; color: #efe3c8;
}
/* sound on/off — pushed to the right of the chrome bar */
.chrome-sound {
  margin-left: auto; flex: none;
  background: rgba(217, 164, 65, 0.12); border: 2px solid #8a6f3c;
  color: #d9a441; font-size: 15px; line-height: 1;
  padding: 5px 10px; cursor: pointer;
}
.chrome-sound:hover, .chrome-sound:focus-visible { background: #d9a441; }
.chrome-sound.off { opacity: 0.55; }
@media (max-width: 520px) { .chrome-ttl { display: none; } }

/* Admin unlock corner (gates the E path editor) */
#adminCorner {
  position: fixed; right: 14px; bottom: 14px; z-index: 30;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
#btnAdmin {
  background: var(--panel); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 20px; padding: 5px 14px; font-size: 12px; cursor: pointer;
}
#btnAdmin:hover { color: var(--text); border-color: var(--accent); }
#btnAdmin.on { color: var(--gold); border-color: var(--gold); }
#adminForm {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px; display: grid; grid-template-columns: 1fr auto auto; gap: 6px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}
#adminForm input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 5px 9px; font-size: 13px; width: 150px;
}
#adminForm button {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 5px 10px; font-size: 12px; cursor: pointer;
}
#adminForm button:hover { border-color: var(--accent); }
#adminMsg { grid-column: 1 / -1; color: #e2574c; font-size: 11.5px; min-height: 14px; }

#modeBadge {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 12px; font-size: 12px; color: var(--gold);
}
#btnMenu { border-color: #7a4040; }

/* ---------- Top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
}
.brand { font-weight: 700; letter-spacing: 0.4px; margin-right: 6px; }
.stat { background: var(--panel-2); padding: 4px 10px; border-radius: 6px; font-weight: 600; }
#phaseLabel { color: var(--text-dim); font-style: italic; }
.spacer { flex: 1; }

/* ---------- Layout ---------- */
main { display: flex; gap: 10px; align-items: flex-start; }

#canvasWrap { position: relative; flex: 1; min-width: 0; display: flex; justify-content: center; }
#gameCanvas {
  display: block;
  /* auto + max constraints keep the aspect ratio for both landscape
     and tall portrait maps, and always fit the viewport height */
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 110px - var(--chrome-h));
  background: #24321f;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: crosshair;
}

/* ---------- Sidebar ---------- */
#sidebar {
  width: 270px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
#sidebar h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); }

button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 14px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }

#btnWave {
  background: #2d5a3d;
  border-color: #3f7a54;
  font-weight: 700;
  padding: 11px;
  font-size: 15px;
}
#btnWave:hover:not(:disabled) { background: #356b48; border-color: var(--good); }

#autoWaveLabel { color: var(--text-dim); display: flex; align-items: center; gap: 6px; cursor: pointer; }

#msg { min-height: 20px; color: var(--gold); font-weight: 600; text-align: center; }

/* ---------- Shop ---------- */
#shop { display: flex; flex-direction: column; gap: 8px; }
.shop-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  user-select: none;
}
.shop-item:hover { border-color: var(--accent); }
.shop-item.selected { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.shop-item.unaffordable { opacity: 0.45; }
.shop-item canvas { flex-shrink: 0; border-radius: 6px; background: #1a2418; }
.shop-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.shop-name { font-weight: 700; }
.shop-name .cost { color: var(--gold); float: right; }
.shop-desc { color: var(--text-dim); font-size: 12px; }
.shop-stats { font-size: 12px; color: var(--text-dim); }
.shop-target { color: var(--good); text-transform: capitalize; }
.shop-key { color: var(--text-dim); font-size: 11px; border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; margin-right: 4px; }

/* ---------- Selected tower panel ---------- */
#towerPanel {
  background: var(--panel-2);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
#towerPanel.hidden { display: none; }
#twName { color: var(--gold); font-size: 14px !important; text-transform: none !important; letter-spacing: 0 !important; }
#twStats { font-size: 13px; color: var(--text); line-height: 1.6; white-space: pre-line; }
.panelButtons { display: flex; gap: 8px; }
.panelButtons button { flex: 1; }
#btnSell { border-color: #7a4040; }
#btnSell:hover { border-color: var(--bad); }

/* ---------- Help ---------- */
#helpBox { color: var(--text-dim); font-size: 12px; display: flex; flex-direction: column; gap: 6px; }
#helpBox ul { list-style: none; display: flex; flex-direction: column; gap: 3px; }
#helpBox b { color: var(--text); }

/* ---------- On-field tower popup (upgrade / sell at the tower) ---------- */
#towerPopup {
  position: absolute;
  display: flex;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 6px;
  z-index: 5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
#towerPopup.hidden { display: none; }
#towerPopup button { font-size: 12px; padding: 4px 9px; white-space: nowrap; }
#popUpgrade { border-color: #3f7a54; }
#popUpgrade:hover:not(:disabled) { border-color: var(--good); }
#popSell { border-color: #7a4040; }
#popSell:hover { border-color: var(--bad); }

/* ---------- Overlay (game over / victory) ---------- */
#overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 12, 16, 0.75);
  border-radius: var(--radius);
  z-index: 10;
}
#overlay.hidden { display: none; }
#overlayBox {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 40px;
  text-align: center;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
}
#overlayTitle { font-size: 28px; }
#overlayText { color: var(--text-dim); white-space: pre-line; }
.overlayButtons { display: flex; gap: 10px; justify-content: center; }
#btnContinue { background: #2d5a3d; border-color: #3f7a54; font-weight: 700; }

/* per-mode Tutorial + Theory buttons, side by side under each mode card */
.mode-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.tut-btn, .theory-btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; cursor: pointer;
}
.tut-btn:hover { border-color: var(--accent); color: var(--accent); }
.theory-btn:hover { border-color: var(--gold); color: var(--gold); }

/* level-select cleared tick */
.level-tick { color: #6fdc8c; font-weight: 700; font-size: 11px; }
.level-card.done { border-color: #3f7a54; }

/* ---------- Reusable modal (Tutorial / Theory) ---------- */
#modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(6, 8, 14, 0.72);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-box {
  position: relative; width: 100%; max-width: 760px; max-height: 88vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 22px 26px; box-shadow: 0 18px 60px rgba(0,0,0,0.6);
}
#modalClose {
  position: absolute; top: 12px; right: 12px; width: 32px; height: 32px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; cursor: pointer; font-size: 15px;
}
#modalClose:hover { border-color: var(--gold); color: var(--gold); }
#modalTitle { font-size: 22px; margin: 0 40px 14px 0; color: var(--gold); }

/* tutorial cards */
.tut-intro { color: var(--text-dim); font-size: 14px; margin: 0 0 14px; line-height: 1.5; }
.tut-h { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin: 18px 0 10px; }
.tut-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tut-card {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px;
}
.tut-icon { flex: none; width: 72px; height: 72px; border-radius: 10px;
  background: rgba(255,255,255,0.04); display: flex; align-items: center; justify-content: center; }
.tut-icon canvas { width: 72px; height: 72px; }
.tut-body h4 { margin: 2px 0 5px; font-size: 15px; }
.tut-body p { margin: 0 0 4px; font-size: 12.8px; color: var(--text-dim); line-height: 1.45; }
.tut-tag { font-size: 10.5px; font-weight: 600; color: var(--accent);
  border: 1px solid var(--border); border-radius: 20px; padding: 1px 8px; margin-left: 4px; white-space: nowrap; }
.tut-action { color: var(--text) !important; }
.tut-action b { color: var(--gold); }

/* theory panel */
#modalBody.theory h3 { font-size: 15px; color: var(--accent); margin: 18px 0 8px; }
#modalBody.theory h3:first-child { margin-top: 4px; }
#modalBody.theory ul { margin: 0 0 6px 18px; padding: 0; }
#modalBody.theory li { font-size: 13.5px; line-height: 1.5; margin-bottom: 4px; color: var(--text); }
#modalBody.theory .flow { font-weight: 700; color: var(--gold); background: var(--panel-2);
  padding: 8px 12px; border-radius: 8px; font-size: 13.5px; }
#modalBody.theory .tbl-wrap { overflow-x: auto; }
#modalBody.theory table { border-collapse: collapse; width: 100%; font-size: 12.8px; margin: 4px 0; }
#modalBody.theory th { text-align: left; background: var(--panel-2); color: var(--gold); padding: 6px 9px; }
#modalBody.theory td { border-top: 1px solid var(--border); padding: 6px 9px; color: var(--text); }
#modalBody.theory .remember { background: rgba(232,182,76,0.1); border: 1px solid var(--gold);
  border-radius: 8px; padding: 9px 12px; font-size: 13px; margin: 12px 0 4px; }

/* ---------- Map note (organ digestion rule) ---------- */
#mapNote {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  max-width: 92%; text-align: center;
  background: rgba(15, 19, 28, 0.86); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 14px; font-size: 13px; color: var(--text);
  box-shadow: 0 6px 20px rgba(0,0,0,0.4); pointer-events: none;
}
#mapNote .note-i { color: var(--accent); font-weight: 700; margin-right: 4px; }

/* ---------- Grand finale (anus + jumping turd) ---------- */
#finale {
  position: fixed; inset: 0; z-index: 70;
  background: radial-gradient(circle at 50% 40%, #2a0f14, #0a0406);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.finale-stage { position: relative; width: min(92vw, 720px); aspect-ratio: 1448 / 1086; }
#finaleBg { width: 100%; height: 100%; object-fit: contain; border-radius: 14px;
  box-shadow: 0 12px 50px rgba(0,0,0,0.6); }
#finaleTurd {
  position: absolute; left: 50%; top: 47%; width: 26%;
  transform: translate(-50%, -20%) scale(0.1); opacity: 0;
}
#finaleTurd.jump { animation: turdJump 1.15s cubic-bezier(.2,.7,.3,1) 0.15s forwards; }
@keyframes turdJump {
  0%   { transform: translate(-50%, 10%) scale(0.12); opacity: 0; }
  35%  { opacity: 1; }
  60%  { transform: translate(-50%, -125%) scale(1.06); opacity: 1; }
  78%  { transform: translate(-50%, -108%) scale(0.97); }
  100% { transform: translate(-50%, -116%) scale(1); opacity: 1; }
}
/* overlaid inside the lower part of the anus scene (near-solid panel so it
   stays readable over the pink), leaving the hole + jumping turd visible above */
#finaleCard {
  position: absolute; left: 50%; bottom: 4%; transform: translateX(-50%);
  width: min(86%, 520px); text-align: center;
  background: rgba(22, 25, 33, 0.92); border: 1px solid var(--gold); border-radius: 14px;
  padding: 14px 20px 16px; box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
#finaleCard h1 { font-size: 23px; margin: 0 0 6px;
  background: linear-gradient(90deg, #f4c56a, #e2574c 70%, #c94b8f);
  -webkit-background-clip: text; background-clip: text; color: transparent; }
#finaleText { color: var(--text); font-size: 13.5px; line-height: 1.45; margin: 0 0 12px; }
.finale-btns { display: flex; gap: 10px; justify-content: center; }
.finale-btns button { background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 9px 18px; font-size: 14px; cursor: pointer; }
.finale-btns button:hover { border-color: var(--gold); color: var(--gold); }
#finalePlay { background: #2d5a3d; border-color: #3f7a54; font-weight: 700; }

@media (max-width: 680px) {
  .tut-grid { grid-template-columns: 1fr; }
  .finale-stage { width: 96vw; }
  #finaleCard { width: 92%; padding: 11px 14px 12px; }
  #finaleCard h1 { font-size: 19px; }
  #finaleText { font-size: 12.5px; margin-bottom: 10px; }
}

/* Utility: always wins over element/ID display rules (e.g. #app, #homeStep2)
   so toggling .hidden reliably hides anything. */
.hidden { display: none !important; }

/* ---------- Narrow screens ---------- */
@media (max-width: 1000px) {
  main { flex-direction: column; }
  #sidebar { width: 100%; }
}

/* ---------- Home screen on phones ---------- */
@media (max-width: 680px) {
  #home { padding: 20px 14px; }
  .home-hero h1 { font-size: 32px; }
  .home-emoji { font-size: 46px; }
  .home-sub { font-size: 14px; }
  #modeCards, #levelCards { grid-template-columns: 1fr; }
  .level-card { flex-direction: row; justify-content: flex-start; text-align: left; gap: 12px; }
  .level-card .level-emoji { font-size: 30px; }
}
