/* ============================================================
   COG & THORN — The Winding War
   Visual identity: brass & verdigris clockwork vs. wildroot green
   ============================================================ */

:root {
  --brass: #d9a441;
  --brass-hi: #f4d27a;
  --brass-dk: #8a6420;
  --copper: #c46a3a;
  --ink: #14121f;
  --ink-2: #1d1a2e;
  --panel: rgba(24, 21, 40, 0.92);
  --panel-edge: rgba(217, 164, 65, 0.55);
  --cream: #f2e8d5;
  --cream-dim: #b8ad97;
  --green: #7cb342;
  --green-dk: #3f6b2e;
  --red: #e05545;
  --teal: #4fb3a9;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
  color: var(--cream);
  -webkit-user-select: none; user-select: none;
}

#page-frame {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1200px 700px at 50% 120%, rgba(79, 179, 169, 0.10), transparent 60%),
    radial-gradient(900px 500px at 50% -10%, rgba(217, 164, 65, 0.10), transparent 60%),
    var(--ink);
}

#game-shell {
  position: relative;
  aspect-ratio: 16 / 9;
  width: min(100vw - 20px, (100vh - 20px) * 16 / 9);
  min-width: 900px;
  min-height: 506px;
  border: 3px solid var(--brass-dk);
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    0 0 0 2px rgba(217, 164, 65, 0.25),
    0 24px 70px rgba(0, 0, 0, 0.65),
    inset 0 0 60px rgba(0, 0, 0, 0.35);
  background: #0d0c16;
}

#game {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
}

#vignette {
  position: absolute; inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 45%, transparent 62%, rgba(8, 7, 14, 0.55) 100%);
  z-index: 5;
}

.hidden { display: none !important; }

/* ================= TOP HUD ================= */

#hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  height: 64px;
  display: flex; align-items: center; gap: 14px;
  padding: 8px 14px;
  z-index: 10;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(13, 12, 22, 0.88), rgba(13, 12, 22, 0.0));
}

.base-panel {
  width: 240px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  padding: 6px 10px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.4);
}
.base-panel.right { text-align: right; }

.base-label {
  font-size: 12px; letter-spacing: 1px;
  color: var(--cream-dim);
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 4px;
}
.base-panel.right .base-label { justify-content: flex-end; }

.base-glyph {
  width: 12px; height: 12px; border-radius: 50%;
  display: inline-block;
}
.clock-glyph {
  background: radial-gradient(circle at 35% 35%, var(--brass-hi), var(--brass) 60%, var(--brass-dk));
  box-shadow: 0 0 6px rgba(217,164,65,0.8);
}
.thorn-glyph {
  background: radial-gradient(circle at 35% 35%, #b6e08a, var(--green) 60%, var(--green-dk));
  box-shadow: 0 0 6px rgba(124,179,66,0.8);
}

.hp-bar {
  position: relative;
  height: 14px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(217,164,65,0.35);
  border-radius: 7px;
  overflow: hidden;
}
.hp-fill {
  height: 100%; width: 100%;
  transition: width 0.18s ease-out;
}
.hp-fill.player {
  background: linear-gradient(to bottom, var(--brass-hi), var(--brass) 55%, var(--brass-dk));
}
.hp-fill.enemy {
  background: linear-gradient(to bottom, #b6e08a, var(--green) 55%, var(--green-dk));
}
.hp-fill.low { animation: hp-pulse 0.7s infinite; }
@keyframes hp-pulse { 50% { filter: brightness(1.6); } }

.hp-text {
  position: absolute; inset: 0;
  font-size: 11px; font-weight: bold;
  display: flex; align-items: center; justify-content: center;
  text-shadow: 0 1px 2px #000;
  letter-spacing: 1px;
}

#stage-banner {
  flex: 1;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  padding: 4px 10px;
}
#stage-name { font-size: 15px; font-weight: bold; letter-spacing: 2px; color: var(--brass-hi); }
#stage-sub { font-size: 11px; color: var(--cream-dim); letter-spacing: 1px; }

#top-buttons { display: flex; gap: 8px; pointer-events: auto; }

/* ================= BUTTONS ================= */

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 9px;
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  color: var(--cream);
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.08s, background 0.12s, box-shadow 0.12s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.icon-btn:hover { background: rgba(217,164,65,0.22); transform: translateY(-1px); box-shadow: 0 4px 10px rgba(0,0,0,0.5); }
.icon-btn:active { transform: translateY(1px) scale(0.96); }
.icon-btn.off { color: #5a5470; text-decoration: line-through; }

.big-btn {
  display: block;
  width: 240px;
  padding: 12px 18px;
  margin: 8px 0;
  font-family: inherit;
  font-size: 17px; font-weight: bold;
  letter-spacing: 2px;
  color: var(--cream);
  background: linear-gradient(to bottom, #2e2a48, #221f38);
  border: 2px solid var(--panel-edge);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.12s, border-color 0.12s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.08);
}
.big-btn:hover { transform: translateY(-2px); border-color: var(--brass); box-shadow: 0 8px 18px rgba(0,0,0,0.55), 0 0 14px rgba(217,164,65,0.25); }
.big-btn:active { transform: translateY(1px) scale(0.98); }
.big-btn.primary {
  background: linear-gradient(to bottom, var(--brass-hi), var(--brass) 45%, var(--brass-dk));
  color: #241a06;
  border-color: var(--brass-hi);
  text-shadow: 0 1px 0 rgba(255,255,255,0.35);
}
.big-btn.primary:hover { box-shadow: 0 8px 20px rgba(0,0,0,0.55), 0 0 22px rgba(217,164,65,0.5); }

.small-btn {
  margin-top: 18px;
  padding: 6px 14px;
  font-family: inherit; font-size: 12px; letter-spacing: 1px;
  color: var(--cream-dim);
  background: transparent;
  border: 1px solid rgba(184,173,151,0.35);
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.small-btn:hover { color: var(--red); border-color: var(--red); }

/* ================= BOTTOM HUD ================= */

#hud-bottom {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: 128px;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  z-index: 10;
  pointer-events: none;
  background: linear-gradient(to top, rgba(13, 12, 22, 0.92), rgba(13, 12, 22, 0.0));
}

#winding-wrap {
  width: 150px;
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex; flex-direction: column; gap: 5px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.4);
}
#winding-icon {
  width: 30px; height: 30px; margin: 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #241a06 0 26%, transparent 27%),
    conic-gradient(var(--brass-hi) 0 12%, var(--brass) 12% 25%, var(--brass-hi) 25% 37%, var(--brass) 37% 50%, var(--brass-hi) 50% 62%, var(--brass) 62% 75%, var(--brass-hi) 75% 87%, var(--brass) 87% 100%);
  -webkit-mask: radial-gradient(circle, transparent 0 22%, #000 23% 44%, transparent 45% 48%, #000 49% 100%);
  mask: radial-gradient(circle, transparent 0 22%, #000 23% 44%, transparent 45% 48%, #000 49% 100%);
  animation: spin-slow 9s linear infinite;
}
@keyframes spin-slow { to { transform: rotate(360deg); } }
#winding-bar {
  height: 12px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(217,164,65,0.35);
  border-radius: 6px;
  overflow: hidden;
}
#winding-fill {
  height: 100%; width: 0%;
  background: linear-gradient(to bottom, var(--brass-hi), var(--brass) 60%, var(--brass-dk));
  transition: width 0.12s linear;
}
#winding-text {
  text-align: center;
  font-size: 12px; font-weight: bold; letter-spacing: 1px;
  color: var(--brass-hi);
  text-shadow: 0 1px 2px #000;
}

#cards {
  flex: 1;
  display: flex; justify-content: center; gap: 8px;
  pointer-events: auto;
}

.card {
  position: relative;
  width: 92px;
  height: 104px;
  border-radius: 12px;
  border: 2px solid var(--panel-edge);
  background: linear-gradient(to bottom, #2b2745, #1e1b33);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.08s, border-color 0.12s, box-shadow 0.12s;
  box-shadow: 0 3px 8px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.07);
  font-family: inherit;
  color: var(--cream);
}
.card:hover { transform: translateY(-3px); border-color: var(--brass); box-shadow: 0 7px 14px rgba(0,0,0,0.55), 0 0 12px rgba(217,164,65,0.3); }
.card:active { transform: translateY(0) scale(0.97); }
.card .card-icon { display: block; margin: 0 auto; }
.card .card-name {
  position: absolute; bottom: 16px; left: 0; right: 0;
  font-size: 10px; font-weight: bold; letter-spacing: 0.5px;
  text-align: center;
  text-shadow: 0 1px 2px #000;
}
.card .card-cost {
  position: absolute; top: 5px; left: 6px;
  font-size: 12px; font-weight: bold;
  color: var(--brass-hi);
  text-shadow: 0 1px 2px #000;
  display: flex; align-items: center; gap: 3px;
}
.card .card-cost::before {
  content: "";
  width: 9px; height: 9px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--brass-hi), var(--brass) 65%, var(--brass-dk));
}
.card .card-key {
  position: absolute; top: 4px; right: 5px;
  width: 17px; height: 17px;
  border-radius: 5px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(217,164,65,0.5);
  font-size: 10px; font-weight: bold;
  display: flex; align-items: center; justify-content: center;
  color: var(--brass-hi);
}
.card .cd-overlay {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 0%;
  background: rgba(10, 9, 18, 0.78);
  pointer-events: none;
  transition: height 0.08s linear;
}
.card .cd-text {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  font-size: 20px; font-weight: bold;
  color: #fff; text-shadow: 0 2px 4px #000;
  pointer-events: none;
}
.card.cooling .cd-text { display: flex; }
.card.broke { filter: saturate(0.35) brightness(0.7); }
.card.broke .card-cost { color: var(--red); }
.card.flash-deny { animation: deny 0.25s; }
@keyframes deny {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.card.flash-ok { animation: cardok 0.18s; }
@keyframes cardok { 50% { transform: scale(1.06); border-color: var(--brass-hi); } }

/* special ability */
#special-wrap {
  width: 110px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  pointer-events: auto;
}
#btn-special {
  position: relative;
  width: 74px; height: 74px;
  border-radius: 50%;
  border: 3px solid var(--panel-edge);
  background: radial-gradient(circle at 50% 40%, #2b2745, #171527);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.08s, border-color 0.12s, box-shadow 0.12s;
  box-shadow: 0 3px 10px rgba(0,0,0,0.5);
}
#btn-special:hover { transform: scale(1.04); }
#btn-special:active { transform: scale(0.96); }
#special-fill {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 0%;
  background: linear-gradient(to top, rgba(79,179,169,0.85), rgba(79,179,169,0.25));
  transition: height 0.15s linear;
}
#special-icon {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
#special-key {
  position: absolute; bottom: 2px; right: 6px;
  font-size: 11px; font-weight: bold;
  color: var(--cream); text-shadow: 0 1px 2px #000;
}
#btn-special.ready {
  border-color: var(--teal);
  animation: special-ready 1.1s infinite;
}
@keyframes special-ready {
  0%, 100% { box-shadow: 0 0 8px rgba(79,179,169,0.5); }
  50% { box-shadow: 0 0 22px rgba(79,179,169,0.95); }
}
#special-label { font-size: 11px; letter-spacing: 1px; color: var(--teal); font-weight: bold; }

/* ================= OVERLAYS ================= */

.overlay {
  position: absolute; inset: 0;
  z-index: 20;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: rgba(10, 9, 18, 0.62);
  backdrop-filter: blur(3px);
  animation: fade-in 0.25s ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.panel {
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  border-radius: 16px;
  padding: 24px 30px;
  width: 560px;
  max-width: 92%;
  max-height: 88%;
  overflow-y: auto;
  box-shadow: 0 18px 50px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.06);
  animation: panel-pop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes panel-pop { from { transform: scale(0.92) translateY(14px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }
.panel.wide { width: 760px; }
.panel.narrow { width: 400px; text-align: center; }
.panel h2 {
  font-size: 26px; letter-spacing: 3px;
  color: var(--brass-hi);
  margin-bottom: 14px;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
}
.panel-footer { margin-top: 16px; display: flex; justify-content: center; }

/* title */
#title-logo { text-align: center; margin-bottom: 10px; position: relative; }
#title-logo h1 {
  font-size: 74px;
  letter-spacing: 10px;
  font-weight: 900;
  background: linear-gradient(to bottom, #fff3cf 10%, var(--brass-hi) 35%, var(--brass) 60%, var(--brass-dk) 95%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 0 rgba(0,0,0,0.55)) drop-shadow(0 10px 24px rgba(217,164,65,0.35));
}
#title-logo .amp { font-size: 54px; }
#logo-sub {
  margin-top: 2px;
  font-size: 17px; letter-spacing: 12px;
  color: var(--teal);
  text-shadow: 0 2px 8px rgba(0,0,0,0.8);
}
.logo-gear {
  position: absolute; top: -18px; left: 50%; margin-left: -130px;
  width: 46px; height: 46px;
  border-radius: 50%;
  background: conic-gradient(var(--brass-hi) 0 12%, var(--brass) 12% 25%, var(--brass-hi) 25% 37%, var(--brass) 37% 50%, var(--brass-hi) 50% 62%, var(--brass) 62% 75%, var(--brass-hi) 75% 87%, var(--brass) 87% 100%);
  -webkit-mask: radial-gradient(circle, transparent 0 26%, #000 27% 46%, transparent 47% 50%, #000 51% 100%);
  mask: radial-gradient(circle, transparent 0 26%, #000 27% 46%, transparent 47% 50%, #000 51% 100%);
  animation: spin-slow 7s linear infinite;
  opacity: 0.9;
}
#title-story {
  text-align: center;
  max-width: 520px;
  font-size: 14px; line-height: 1.55;
  color: var(--cream-dim);
  margin-bottom: 22px;
  text-shadow: 0 1px 3px #000;
}
#title-buttons { display: flex; flex-direction: column; align-items: center; }
#title-audio { display: flex; gap: 10px; margin-top: 10px; }

/* howto */
.howto-grid { display: flex; gap: 24px; }
.howto-col { flex: 1; }
.howto-col h3 {
  font-size: 14px; letter-spacing: 2px;
  color: var(--teal);
  margin: 10px 0 6px;
}
.howto-col h3:first-child { margin-top: 0; }
.howto-col ul { list-style: none; }
.howto-col li {
  font-size: 12.5px; line-height: 1.5;
  color: var(--cream-dim);
  padding-left: 14px; position: relative;
  margin-bottom: 5px;
}
.howto-col li::before {
  content: "⚙";
  position: absolute; left: 0;
  color: var(--brass);
  font-size: 10px;
}
.howto-col li b { color: var(--cream); }
#howto-units li { display: flex; align-items: center; gap: 8px; }
#howto-units li::before { content: none; }
#howto-units .hu-icon { flex: 0 0 auto; }
#howto-units .hu-name { color: var(--brass-hi); font-weight: bold; }
#howto-units .hu-role { color: var(--teal); font-size: 11px; }

/* stage select */
#stage-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 6px 0 4px;
}
.stage-card {
  position: relative;
  border: 2px solid var(--panel-edge);
  border-radius: 14px;
  background: linear-gradient(135deg, #2b2745, #1c1930);
  padding: 16px 18px;
  cursor: pointer;
  font-family: inherit;
  color: var(--cream);
  text-align: left;
  transition: transform 0.1s, border-color 0.12s, box-shadow 0.12s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  overflow: hidden;
}
.stage-card:hover:not(.locked) { transform: translateY(-3px); border-color: var(--brass); box-shadow: 0 8px 20px rgba(0,0,0,0.55), 0 0 16px rgba(217,164,65,0.25); }
.stage-card .sc-num { font-size: 11px; letter-spacing: 2px; color: var(--teal); }
.stage-card .sc-name { font-size: 19px; font-weight: bold; margin: 2px 0 4px; }
.stage-card .sc-desc { font-size: 12px; color: var(--cream-dim); line-height: 1.4; }
.stage-card .sc-pips { margin-top: 8px; font-size: 12px; letter-spacing: 3px; color: var(--brass); }
.stage-card .sc-pips .off { color: #453f5e; }
.stage-card .sc-status {
  position: absolute; top: 10px; right: 12px;
  font-size: 11px; font-weight: bold; letter-spacing: 1px;
  padding: 3px 9px; border-radius: 8px;
}
.stage-card .sc-status.cleared { background: rgba(124,179,66,0.2); color: #b6e08a; border: 1px solid rgba(124,179,66,0.5); }
.stage-card .sc-status.boss { background: rgba(224,85,69,0.18); color: #f0907f; border: 1px solid rgba(224,85,69,0.5); }
.stage-card.locked { filter: grayscale(0.8) brightness(0.6); cursor: not-allowed; }
.stage-card.locked .sc-status { background: rgba(0,0,0,0.4); color: #8a8299; border: 1px solid #453f5e; }

/* pause */
#pause-buttons { display: flex; flex-direction: column; align-items: center; }
#pause-audio { display: flex; gap: 10px; margin-top: 12px; }

/* upgrade */
#upgrade-cards { display: flex; gap: 14px; justify-content: center; }
.upg-card {
  width: 200px;
  border: 2px solid var(--panel-edge);
  border-radius: 14px;
  background: linear-gradient(160deg, #2b2745, #1c1930);
  padding: 16px 14px;
  cursor: pointer;
  font-family: inherit; color: var(--cream);
  text-align: center;
  transition: transform 0.1s, border-color 0.12s, box-shadow 0.12s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.upg-card:hover { transform: translateY(-4px) scale(1.02); border-color: var(--brass-hi); box-shadow: 0 10px 24px rgba(0,0,0,0.6), 0 0 18px rgba(217,164,65,0.35); }
.upg-card:active { transform: scale(0.98); }
.upg-card .upg-icon { width: 56px; height: 56px; margin: 0 auto 10px; display: block; }
.upg-card .upg-name { font-size: 15px; font-weight: bold; color: var(--brass-hi); letter-spacing: 1px; margin-bottom: 6px; }
.upg-card .upg-desc { font-size: 12px; color: var(--cream-dim); line-height: 1.45; }

/* result */
#result-title { font-size: 40px; letter-spacing: 6px; }
#result-title.win {
  background: linear-gradient(to bottom, #fff3cf, var(--brass) 70%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: win-glow 1.2s infinite;
}
@keyframes win-glow { 50% { filter: drop-shadow(0 0 14px rgba(217,164,65,0.8)); } }
#result-title.lose { color: var(--red); text-shadow: 0 0 18px rgba(224,85,69,0.6); }
#result-sub { color: var(--cream-dim); font-size: 14px; margin: 8px 0 14px; line-height: 1.5; }
#result-stats {
  display: flex; justify-content: center; gap: 18px;
  margin-bottom: 14px;
}
.stat {
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(217,164,65,0.3);
  border-radius: 10px;
  padding: 8px 14px;
  min-width: 92px;
}
.stat .stat-v { font-size: 20px; font-weight: bold; color: var(--brass-hi); }
.stat .stat-l { font-size: 10px; letter-spacing: 1px; color: var(--cream-dim); margin-top: 2px; }
#result-buttons { display: flex; flex-direction: column; align-items: center; }

/* hint bubble */
#hint-bubble {
  position: absolute;
  top: 78px; left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  background: var(--panel);
  border: 2px solid var(--teal);
  border-radius: 12px;
  padding: 10px 16px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5), 0 0 16px rgba(79,179,169,0.25);
  animation: hint-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 560px;
}
@keyframes hint-in { from { transform: translate(-50%, -16px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
#hint-text { font-size: 13.5px; line-height: 1.45; color: var(--cream); }
#hint-text b { color: var(--teal); }
#hint-next {
  font-family: inherit;
  font-size: 12px; font-weight: bold; letter-spacing: 1px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--teal);
  background: rgba(79,179,169,0.15);
  color: var(--teal);
  cursor: pointer;
  transition: background 0.12s;
}
#hint-next:hover { background: rgba(79,179,169,0.35); }

/* scrollbars */
.panel::-webkit-scrollbar { width: 8px; }
.panel::-webkit-scrollbar-track { background: rgba(0,0,0,0.3); border-radius: 4px; }
.panel::-webkit-scrollbar-thumb { background: var(--brass-dk); border-radius: 4px; }
