/* ------------------------------ Fonts ------------------------------ */
@font-face { font-family: 'Cinzel'; src: url('../assets/fonts/Cinzel.ttf') format('truetype'); font-weight: 400 900; font-display: swap; }
@font-face { font-family: 'Orbitron'; src: url('../assets/fonts/Orbitron.ttf') format('truetype'); font-weight: 400 900; font-display: swap; }
@font-face { font-family: 'Zen Old Mincho'; src: url('../assets/fonts/ZenOldMincho.ttf') format('truetype'); font-weight: 400 900; font-display: swap; }
@font-face { font-family: 'Cormorant Garamond'; src: url('../assets/fonts/CormorantGaramond.ttf') format('truetype'); font-weight: 300 700; font-display: swap; }
@font-face { font-family: 'Josefin Sans'; src: url('../assets/fonts/JosefinSans.ttf') format('truetype'); font-weight: 100 700; font-display: swap; }
@font-face { font-family: 'Lilita One'; src: url('../assets/fonts/LilitaOne-Regular.ttf') format('truetype'); font-weight: 400 900; font-display: swap; }
@font-face { font-family: 'Antonio'; src: url('../assets/fonts/Antonio.ttf') format('truetype'); font-weight: 100 700; font-display: swap; }
@font-face { font-family: 'Fredoka'; src: url('../assets/fonts/Fredoka.ttf') format('truetype'); font-weight: 300 700; font-display: swap; }

/* ------------------------------ Theme tokens ------------------------------ */
:root {
  --bg: #0d0806;
  --panel: rgba(24, 14, 10, 0.62);
  --panel-solid: #1c110c;
  --border: rgba(233, 196, 106, 0.28);
  --text: #f6ecd6;
  --muted: #c2ab84;
  --accent: #e9c46a;
  --accent-2: #b02a3a;
  --glow: rgba(233, 196, 106, 0.35);
  --radius: 10px;
  --font-ui: 'Cinzel', serif;
  --tool-fs: 9.5px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font-ui); -webkit-font-smoothing: antialiased; transition: background-color 0.4s; }
button, input, select { font-family: inherit; color: inherit; }
.hidden { display: none !important; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 90; transition: opacity 0.28s ease; }
#fade.on { opacity: 1; }

/* ------------------------------ Panels / buttons ------------------------------ */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.btn {
  appearance: none; cursor: pointer; border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0.02));
  color: var(--text); padding: 10px 18px; border-radius: var(--radius);
  font-size: 14px; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 600;
  display: inline-flex; align-items: center; gap: 10px; transition: transform 0.12s, box-shadow 0.2s, background 0.2s, border-color 0.2s;
}
.btn svg { width: 18px; height: 18px; fill: currentColor; }
.btn:hover { transform: translateY(-1px); border-color: var(--accent); box-shadow: 0 0 22px var(--glow); }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn.primary { background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 65%, #000)); color: #140c06; border-color: transparent; box-shadow: 0 6px 24px var(--glow); }
.btn.big { padding: 15px 28px; font-size: 16px; }
.btn.active { border-color: var(--accent); box-shadow: 0 0 20px var(--glow); }
.btn em { font-style: normal; font-size: 11px; opacity: 0.8; padding: 2px 8px; border-radius: 99px; background: rgba(0,0,0,0.3); }
.btn em:empty { display: none; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; padding: 6px 2px; }
.link:hover { color: var(--accent); }

.icon-btn {
  appearance: none; width: 42px; height: 42px; border-radius: var(--radius); cursor: pointer;
  display: grid; place-items: center; border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.05); transition: background 0.15s, border-color 0.15s, box-shadow 0.2s, transform 0.1s;
}
.icon-btn svg { width: 22px; height: 22px; fill: var(--text); opacity: 0.9; }
.icon-btn:hover { background: rgba(255,255,255,0.12); border-color: var(--border); box-shadow: 0 0 16px var(--glow); }
.icon-btn:active { transform: scale(0.93); }
.icon-btn.active { border-color: var(--accent); box-shadow: 0 0 18px var(--glow); }
.icon-btn.active svg { fill: var(--accent); }
.icon-btn.close { font-size: 26px; line-height: 1; color: var(--text); }

/* ------------------------------ Loader ------------------------------ */
#loader { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; background: radial-gradient(circle at 50% 40%, #1a1008, #050302 70%); transition: opacity 0.6s; }
#loader.done { opacity: 0; pointer-events: none; }
.loader-inner { text-align: center; width: min(78vw, 360px); }
.loader-suit { font-size: 54px; color: var(--accent); text-shadow: 0 0 30px var(--glow); animation: pulse 1.6s ease-in-out infinite; }
.loader-title { font-size: 24px; letter-spacing: 0.18em; text-transform: uppercase; margin: 6px 0 22px; }
.loader-bar { height: 3px; background: rgba(255,255,255,0.12); border-radius: 3px; overflow: hidden; }
.loader-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #fff); box-shadow: 0 0 12px var(--accent); transition: width 0.25s; }
.loader-text { margin-top: 14px; font-size: 12px; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase; }
@keyframes pulse { 50% { transform: scale(1.12); opacity: 0.8; } }

/* ------------------------------ Title screen ------------------------------ */
#title-screen { position: fixed; inset: 0; z-index: 40; overflow: hidden; transition: opacity 0.5s ease, transform 0.5s ease; }
#title-screen.leaving { opacity: 0; transform: scale(1.04); pointer-events: none; }
.hero-layer { position: fixed; inset: 0; background: #000; }
.hero-layer img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.9s ease; animation: kenburns 28s ease-in-out infinite alternate; }
.hero-layer img.show { opacity: 1; }
@keyframes kenburns { from { transform: scale(1.04) translate(0, 0); } to { transform: scale(1.14) translate(-1.5%, -1%); } }
.hero-shade { position: fixed; inset: 0; background: linear-gradient(90deg, rgba(0,0,0,0.82) 0%, rgba(0,0,0,0.55) 38%, rgba(0,0,0,0.05) 75%), linear-gradient(0deg, rgba(0,0,0,0.65), transparent 40%); }
.title-content { position: relative; height: 100%; padding: clamp(14px, 4.5vh, 60px) clamp(22px, 6vw, 90px); display: flex; flex-direction: column; justify-content: center; gap: clamp(8px, 1.5vh, 18px); max-width: 1100px; overflow: hidden; }
.eyebrow { margin: 0; font-size: 13px; letter-spacing: 0.4em; text-transform: uppercase; color: var(--accent); }
.title-logo { margin: 0; font-size: clamp(32px, min(11vw, 18vh), 132px); line-height: 0.92; font-weight: 800; letter-spacing: 0.04em; text-shadow: 0 6px 40px rgba(0,0,0,0.6), 0 0 40px var(--glow); }
.title-logo span { color: var(--accent); }
.title-tagline { margin: 0 0 6px; font-size: clamp(13px, min(2vw, 2.4vh), 20px); color: var(--muted); max-width: 34em; line-height: 1.5; }
.title-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.deal-pick { display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: rgba(0,0,0,0.35); font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.deal-pick input { width: 96px; background: transparent; border: 0; outline: 0; font-size: 16px; color: var(--text); text-align: right; }
.deal-pick .btn { padding: 8px 14px; }
.title-themes { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 6px; }
#btn-title-themes { background: var(--panel-solid); color: var(--text); border-color: var(--accent); text-shadow: none; }
.theme-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; padding: 4px 0; width: min(100%, 470px); }
.theme-card { position: relative; min-width: 0; min-height: 68px; width: 100%; aspect-ratio: 16/10; border-radius: calc(var(--radius) + 2px); overflow: hidden; border: 2px solid transparent; cursor: pointer; padding: 0; background: #000; transition: transform 0.2s, border-color 0.2s, box-shadow 0.3s; }
.theme-card img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.5s; }
.theme-card span { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px 6px; font-size: 10px; line-height: 1.15; letter-spacing: 0.08em; text-transform: uppercase; text-align: left; background: linear-gradient(0deg, rgba(0,0,0,0.85), transparent); color: #fff; font-family: inherit; }
.theme-card:hover { transform: translateY(-3px); }
.theme-card:hover img { transform: scale(1.08); }
.theme-card.selected { border-color: var(--accent); box-shadow: 0 0 28px var(--glow); }
.theme-card.theme-random { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 6px; background: var(--panel-solid); border: 2px dashed var(--border); color: var(--accent); }
.theme-random svg { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.theme-card.theme-random span { position: static; padding: 0; background: none; color: var(--text); text-align: center; }
.theme-card.theme-random:hover { border-color: var(--accent); }
.theme-card.theme-random:disabled { cursor: wait; opacity: 0.65; }
.title-foot { display: flex; flex-wrap: wrap; gap: 22px; align-items: center; margin-top: 8px; }
.hint { font-size: 12px; color: var(--muted); letter-spacing: 0.06em; opacity: 0.8; }

/* ------------------------------ HUD ------------------------------ */
/* One row at every desktop width: brand and the Deal chip drop out first, then the tools
   shrink, and only below ~720px do labels become visually hidden (still read by screen readers). */
#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; flex-wrap: nowrap;
  gap: clamp(6px, 1vw, 14px); padding: calc(8px + var(--safe-top)) clamp(8px, 1.2vw, 16px) 12px; pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,0.72), transparent);
}
#hud > * { pointer-events: auto; }
.hud-left, .hud-center, .hud-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hud-left { flex: 0 0 auto; }
.hud-center { flex: 0 1 auto; justify-content: center; }
.hud-right { flex: 0 0 auto; }
.brand { display: flex; flex-direction: column; line-height: 1.1; margin-left: 4px; }
.brand-name { font-size: 17px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; }
.brand-theme { font-size: 9px; letter-spacing: 0.24em; text-transform: uppercase; color: var(--accent); }
.chip { display: flex; flex-direction: column; align-items: center; min-width: 58px; padding: 4px 11px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border); backdrop-filter: blur(12px); }
.chip label { font-size: 9px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }
.chip span, .chip input { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.25; }
.chip input { width: 74px; background: transparent; border: 0; outline: 0; text-align: center; padding: 0; color: var(--text); }
.chip input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.chip input::-webkit-inner-spin-button { display: none; }
.chip.progress { flex-direction: row; gap: 7px; min-width: 0; padding: 3px 11px 3px 8px; }
.chip.progress svg { width: 28px; height: 28px; transform: rotate(-90deg); }
.chip.progress circle { fill: none; stroke-width: 3.4; }
.ring-bg { stroke: rgba(255,255,255,0.14); }
.ring { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 94.25; stroke-dashoffset: 94.25; transition: stroke-dashoffset 0.5s ease; filter: drop-shadow(0 0 4px var(--accent)); }

.controls { padding: 3px; gap: 2px; border-radius: calc(var(--radius) + 4px); background: var(--panel); border: 1px solid var(--border); backdrop-filter: blur(12px); }
.sep { width: 1px; height: 30px; background: var(--border); margin: 0 3px; flex: none; }

/* Icon-over-label tool buttons. */
.tool {
  appearance: none; cursor: pointer; flex: none; min-width: 54px; height: 48px; padding: 0 7px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: var(--radius); border: 1px solid transparent; background: rgba(255,255,255,0.05);
  color: var(--text); font-family: var(--font-ui); transition: background 0.15s, border-color 0.15s, box-shadow 0.2s, transform 0.1s;
}
.tool svg { width: 20px; height: 20px; fill: currentColor; opacity: 0.92; }
.tool span { font-size: var(--tool-fs, 9.5px); letter-spacing: 0.07em; text-transform: uppercase; font-weight: 600; line-height: 1; white-space: nowrap; }
.tool:hover { background: rgba(255,255,255,0.13); border-color: var(--border); box-shadow: 0 0 16px var(--glow); }
.tool:active { transform: scale(0.94); }
.tool.active { border-color: var(--accent); box-shadow: 0 0 18px var(--glow); color: var(--accent); }
.hud-left .tool { background: var(--panel); border-color: var(--border); }

/* Keyboard focus is always visible. */
.tool:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, .theme-card:focus-visible, .theme-big:focus-visible, .link:focus-visible,
.row input:focus-visible, .row select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#status-bar { position: fixed; left: 50%; bottom: calc(16px + var(--safe-bottom)); transform: translateX(-50%); z-index: 20; display: flex; align-items: center; gap: 12px; max-width: 92vw; pointer-events: none; }
.status { padding: 9px 20px; border-radius: 99px; font-size: 13px; letter-spacing: 0.05em; background: var(--panel); border: 1px solid var(--border); backdrop-filter: blur(14px); color: var(--text); transition: color 0.2s, border-color 0.2s; text-align: center; }
.status.ok { border-color: #57d39a; color: #9bf0c6; }
.status.bad { border-color: #ff6b6b; color: #ffb0b0; }
.status.warn { border-color: var(--accent); color: var(--accent); }
.badge { display: none; align-items: center; gap: 8px; padding: 7px 14px; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; border-radius: 99px; background: var(--panel); border: 1px solid var(--border); color: var(--accent); }
.badge.active { display: inline-flex; }
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------ Toasts ------------------------------ */
#toasts { position: fixed; top: calc(76px + var(--safe-top)); right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 12px; padding: 12px 18px 12px 14px; border-radius: calc(var(--radius) + 2px); background: var(--panel-solid); border: 1px solid var(--accent); box-shadow: 0 10px 40px rgba(0,0,0,0.5), 0 0 28px var(--glow); animation: toast-in 0.45s cubic-bezier(.2,1.2,.3,1) both; }
.toast.out { animation: toast-out 0.35s ease both; }
.toast .t-ico { width: 38px; height: 38px; display: grid; place-items: center; font-size: 20px; border-radius: 50%; background: radial-gradient(circle, var(--accent), color-mix(in srgb, var(--accent) 50%, #000)); color: #140c06; }
.toast b { display: block; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.toast small { font-size: 12px; color: var(--muted); }
@keyframes toast-in { from { transform: translateX(120%); opacity: 0; } }
@keyframes toast-out { to { transform: translateX(120%); opacity: 0; } }

/* ------------------------------ Win overlay ------------------------------ */
#win-overlay { position: fixed; inset: 0; z-index: 50; display: none; place-items: center; background: radial-gradient(circle at 50% 50%, rgba(0,0,0,0.0), rgba(0,0,0,0.55)); pointer-events: none; }
#win-overlay.show { display: grid; }
#win-overlay.show .win-card { animation: win-in 0.8s cubic-bezier(.2,1.1,.3,1) both; pointer-events: auto; }
.win-card { padding: 34px 44px 30px; text-align: center; min-width: min(88vw, 440px); }
.win-crest { font-size: 46px; color: var(--accent); text-shadow: 0 0 30px var(--glow); }
.win-card h2 { margin: 4px 0 4px; font-size: 42px; letter-spacing: 0.22em; text-transform: uppercase; text-shadow: 0 0 30px var(--glow); }
.win-card p { margin: 0 0 22px; color: var(--muted); }
.win-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.win-stats div { padding: 12px 6px; border-radius: var(--radius); background: rgba(0,0,0,0.28); border: 1px solid var(--border); }
.win-stats label { display: block; font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--muted); }
.win-stats b { display: block; font-size: 28px; font-variant-numeric: tabular-nums; }
.win-stats em { display: block; font-style: normal; font-size: 11px; color: var(--accent); min-height: 14px; }
.win-actions { display: flex; gap: 12px; justify-content: center; }
@keyframes win-in { from { transform: translateY(40px) scale(0.9); opacity: 0; } }

/* ------------------------------ Modals ------------------------------ */
.modal { position: fixed; inset: 0; z-index: 70; display: none; place-items: center; background: rgba(0,0,0,0.55); backdrop-filter: blur(4px); padding: 16px; }
.modal.show { display: grid; animation: fade-in 0.2s both; }
@keyframes fade-in { from { opacity: 0; } }
.modal-card { width: min(94vw, 460px); max-height: 88vh; display: flex; flex-direction: column; background: var(--panel-solid); animation: win-in 0.4s cubic-bezier(.2,1.1,.3,1) both; }
.modal-card.wide { width: min(94vw, 860px); }
.modal-card > header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 6px; }
.modal-card h3 { margin: 0; font-size: 20px; letter-spacing: 0.18em; text-transform: uppercase; }
.modal-body { padding: 4px 22px 22px; overflow: auto; }
.modal-body h4 { margin: 20px 0 8px; font-size: 11px; letter-spacing: 0.26em; text-transform: uppercase; color: var(--accent); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 9px 0; font-size: 14px; letter-spacing: 0.04em; }
.row input[type=range] { flex: 0 0 55%; accent-color: var(--accent); }
.row select { flex: 0 0 55%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: rgba(0,0,0,0.35); }
.row.check { display: grid; grid-template-columns: 22px 1fr; column-gap: 12px; align-items: start; }
.row.check input { margin-top: 3px; accent-color: var(--accent); width: 18px; height: 18px; }
.row.check small { grid-column: 2; color: var(--muted); font-size: 12px; letter-spacing: 0; }
.note { font-size: 12px; color: var(--muted); margin: 2px 0 0; }

.theme-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; padding-top: 10px; }
.theme-big { position: relative; min-width: 0; border-radius: calc(var(--radius) + 4px); overflow: hidden; cursor: pointer; border: 2px solid transparent; padding: 0; background: #000; text-align: left; transition: transform 0.2s, box-shadow 0.3s, border-color 0.2s; }
.theme-big img { width: 100%; aspect-ratio: 16/11; object-fit: cover; display: block; }
.theme-big .meta { position: absolute; inset: auto 0 0 0; padding: 28px 10px 8px; background: linear-gradient(0deg, rgba(0,0,0,0.92), transparent); }
.theme-big b { display: block; font-size: 12px; line-height: 1.25; letter-spacing: 0.08em; text-transform: uppercase; color: #fff; }
.theme-big small { display: block; margin-top: 3px; font-size: 10px; line-height: 1.3; color: #d4d4d4; letter-spacing: 0.02em; }
.theme-big:hover { transform: translateY(-4px); }
.theme-big.selected { border-color: var(--accent); box-shadow: 0 0 30px var(--glow); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-grid div { padding: 12px 8px; text-align: center; border-radius: var(--radius); background: rgba(0,0,0,0.25); border: 1px solid var(--border); }
.stat-grid label { display: block; font-size: 9px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }
.stat-grid b { font-size: 22px; font-variant-numeric: tabular-nums; }
.ach-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.ach { display: flex; gap: 10px; padding: 10px; border-radius: var(--radius); border: 1px solid var(--border); background: rgba(0,0,0,0.2); opacity: 0.45; }
.ach.got { opacity: 1; border-color: var(--accent); }
.ach .t-ico { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,0.08); }
.ach.got .t-ico { background: var(--accent); color: #140c06; }
.ach b { display: block; font-size: 12px; letter-spacing: 0.08em; }
.ach small { font-size: 11px; color: var(--muted); }

/* ------------------------------ Theme flavour ------------------------------ */
body[data-theme='cyber'] { --tool-fs: 8px; }
body[data-theme='aero'] { --tool-fs: 10px; }
body[data-theme='roman'] .title-logo { background: linear-gradient(180deg, #fff6d8, #e9c46a 55%, #a8812e); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none; filter: drop-shadow(0 4px 24px rgba(0,0,0,0.6)); }
body[data-theme='roman'] .title-logo span { background: linear-gradient(180deg, #fff6d8, #e9c46a 55%, #a8812e); -webkit-background-clip: text; background-clip: text; color: transparent; }
body[data-theme='roman'] .panel { box-shadow: 0 18px 60px rgba(0,0,0,0.5), inset 0 0 0 1px rgba(233,196,106,0.12), inset 0 1px 0 rgba(255,236,190,0.15); }

body[data-theme='cyber'] .tool, body[data-theme='cyber'] .btn, body[data-theme='cyber'] .chip, body[data-theme='cyber'] .panel, body[data-theme='cyber'] .status { clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px); }
body[data-theme='cyber'] .btn { text-shadow: 0 0 8px var(--glow); }
body[data-theme='cyber'] .btn.primary { background: linear-gradient(90deg, var(--accent), #ff2fa8); color: #05060d; text-shadow: none; }
body[data-theme='cyber'] .title-logo { text-shadow: 3px 0 #ff2fa8, -3px 0 #35f3ff, 0 0 40px var(--glow); letter-spacing: 0.1em; font-weight: 900; }
body[data-theme='cyber'] .title-logo span { color: var(--text); }
body[data-theme='cyber'] #hud::after { content: ''; position: absolute; left: 0; right: 0; bottom: 6px; height: 1px; background: linear-gradient(90deg, transparent, var(--accent), transparent); opacity: 0.5; }
body[data-theme='cyber']::after { content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 95; background: repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 3px); mix-blend-mode: overlay; }

body[data-theme='cyber'] .win-card h2 { letter-spacing: 0.1em; font-size: 36px; }
body[data-theme='aero'] { --panel-tint: rgba(255,255,255,0.28); }
body[data-theme='aero'] .panel, body[data-theme='aero'] .chip, body[data-theme='aero'] .controls, body[data-theme='aero'] .status { background: linear-gradient(180deg, rgba(255,255,255,0.42), rgba(255,255,255,0.12)); box-shadow: 0 10px 34px rgba(0,60,100,0.35), inset 0 1px 0 rgba(255,255,255,0.8), inset 0 -10px 20px rgba(120,220,255,0.15); }
body[data-theme='aero'] .modal-card { background: linear-gradient(180deg, #2a95c6, #0d5a82); }
body[data-theme='aero'] .btn { border-radius: 99px; background: linear-gradient(180deg, rgba(255,255,255,0.65), rgba(255,255,255,0.18) 50%, rgba(255,255,255,0.1) 52%, rgba(255,255,255,0.3)); color: #08425f; text-shadow: 0 1px 0 rgba(255,255,255,0.7); box-shadow: 0 3px 10px rgba(0,60,100,0.35), inset 0 1px 1px #fff; }
body[data-theme='aero'] .btn.primary { background: linear-gradient(180deg, #9bffd2, #2fd6a4 50%, #14c08c 52%, #6dffd0); color: #05402f; }
body[data-theme='aero'] .btn svg { fill: currentColor; }
body[data-theme='aero'] .tool { border-radius: 14px; background: linear-gradient(180deg, rgba(255,255,255,0.5), rgba(255,255,255,0.12)); border-color: rgba(255,255,255,0.55); color: #08425f; text-shadow: 0 1px 0 rgba(255,255,255,0.6); }
body[data-theme='aero'] .tool.active { color: #05402f; }
body[data-theme='aero'] .icon-btn { border-radius: 50%; background: linear-gradient(180deg, rgba(255,255,255,0.5), rgba(255,255,255,0.1)); border-color: rgba(255,255,255,0.6); }
body[data-theme='aero'] .icon-btn svg { fill: #08425f; }
body[data-theme='aero'] .title-logo { letter-spacing: 0; text-shadow: 0 4px 0 rgba(0,70,110,0.45), 0 0 40px rgba(124,242,255,0.8); }
body[data-theme='aero'] .hero-shade { background: linear-gradient(90deg, rgba(0,40,70,0.7) 0%, rgba(0,60,100,0.3) 45%, transparent 80%), linear-gradient(0deg, rgba(0,40,70,0.5), transparent 40%); }
body[data-theme='aero'] .chip span, body[data-theme='aero'] .chip input, body[data-theme='aero'] .brand-name { color: #fff; text-shadow: 0 1px 3px rgba(0,60,100,0.6); }


/* ---- Zen Garden: restrained, vermilion seal accents ---- */
body[data-theme='zen'] { --tool-fs: 9.5px; }
body[data-theme='zen'] .title-logo { letter-spacing: 0.06em; font-weight: 700; }
body[data-theme='zen'] .title-logo span { color: var(--accent); }
body[data-theme='zen'] .btn.primary { background: linear-gradient(180deg, #ef6a52, #b93523); color: #fff6ea; }
body[data-theme='zen'] .eyebrow::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 12px; background: var(--accent); transform: rotate(45deg); }
body[data-theme='zen'] .panel { box-shadow: 0 18px 60px rgba(0,0,0,0.5), inset 0 0 0 1px rgba(244,226,196,0.1); }

/* ---- Enchanted Forest: soft glow, rounded leaves ---- */
body[data-theme='forest'] { --tool-fs: 10.5px; }
body[data-theme='forest'] .btn, body[data-theme='forest'] .tool, body[data-theme='forest'] .chip { font-weight: 700; }
body[data-theme='forest'] .title-logo { font-style: italic; font-weight: 700; letter-spacing: 0.02em; text-shadow: 0 4px 28px rgba(0,0,0,0.6), 0 0 44px rgba(155,227,154,0.55); }
body[data-theme='forest'] .title-logo span { color: var(--accent); }
body[data-theme='forest'] .btn.primary { background: linear-gradient(135deg, #b8f5b2, #6fcf86 60%, #f2c14e); color: #0a1f12; }
body[data-theme='forest'] .panel, body[data-theme='forest'] .chip, body[data-theme='forest'] .controls { box-shadow: 0 14px 44px rgba(0,0,0,0.5), 0 0 26px rgba(155,227,154,0.12), inset 0 1px 0 rgba(255,255,255,0.1); }
body[data-theme='forest'] .tool span, body[data-theme='forest'] .chip label { letter-spacing: 0.1em; }

/* ---- Art Deco: chamfered corners, gold keylines ---- */
body[data-theme='deco'] { --tool-fs: 8.5px; }
body[data-theme='deco'] .tool, body[data-theme='deco'] .btn, body[data-theme='deco'] .chip, body[data-theme='deco'] .panel, body[data-theme='deco'] .status, body[data-theme='deco'] .controls { clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 8px, 100% calc(100% - 8px), calc(100% - 8px) 100%, 8px 100%, 0 calc(100% - 8px), 0 8px); }
body[data-theme='deco'] .btn { letter-spacing: 0.2em; font-weight: 600; box-shadow: inset 0 0 0 3px rgba(0,0,0,0.4), inset 0 0 0 4px var(--border); }
body[data-theme='deco'] .btn.primary { background: linear-gradient(180deg, #f3dc9b, #b8943f); color: #17120a; box-shadow: inset 0 0 0 3px rgba(0,0,0,0.25), inset 0 0 0 4px rgba(255,255,255,0.35); }
body[data-theme='deco'] .title-logo { letter-spacing: 0.16em; font-weight: 600; background: linear-gradient(180deg, #fff4cf, #e6c77a 55%, #9c7a2e); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none; filter: drop-shadow(0 4px 24px rgba(0,0,0,0.6)); }
body[data-theme='deco'] .title-logo span { background: inherit; -webkit-background-clip: text; background-clip: text; color: transparent; }
body[data-theme='deco'] .eyebrow { letter-spacing: 0.5em; }
body[data-theme='deco'] .win-card h2, body[data-theme='deco'] .modal-card h3 { letter-spacing: 0.3em; }

/* ---- Día de Muertos: papel-picado dashes, marigold gradients ---- */
body[data-theme='muertos'] { --tool-fs: 10px; }
body[data-theme='muertos'] .title-logo { letter-spacing: 0.02em; background: linear-gradient(180deg, #ffe08a, #ffb627 50%, #ff7a1a); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 4px 0 rgba(230,57,127,0.7)) drop-shadow(0 8px 28px rgba(0,0,0,0.6)); text-shadow: none; }
body[data-theme='muertos'] .title-logo span { background: inherit; -webkit-background-clip: text; background-clip: text; color: transparent; }
body[data-theme='muertos'] .btn.primary { background: linear-gradient(135deg, #ffd35a, #ff9a1f 55%, #e6397f); color: #2a0f2e; }
body[data-theme='muertos'] .panel { outline: 2px dashed rgba(255,182,39,0.35); outline-offset: -9px; }
body[data-theme='muertos'] .chip, body[data-theme='muertos'] .controls { border-style: dashed; }
body[data-theme='muertos'] .win-card h2, body[data-theme='muertos'] .modal-card h3 { letter-spacing: 0.1em; }

/* ---- Deep Space Station: LCARS-flavoured pills and elbows ---- */
body[data-theme='space'] { --tool-fs: 11px; }
body[data-theme='space'] .btn, body[data-theme='space'] .chip { border-radius: 24px 6px 24px 6px; }
body[data-theme='space'] .tool { border-radius: 16px 5px 16px 5px; background: rgba(255,153,102,0.14); border-color: rgba(255,153,102,0.35); }
body[data-theme='space'] .tool:nth-child(3n+2) { background: rgba(204,153,204,0.16); border-color: rgba(204,153,204,0.38); }
body[data-theme='space'] .tool:nth-child(3n) { background: rgba(122,162,255,0.16); border-color: rgba(122,162,255,0.4); }
body[data-theme='space'] .controls { border-radius: 30px 8px 30px 8px; }
body[data-theme='space'] .btn.primary { background: linear-gradient(90deg, #ffb48a, #ff9966 50%, #cc99cc); color: #0a0f26; }
body[data-theme='space'] .title-logo { letter-spacing: 0.12em; text-transform: uppercase; font-weight: 700; }
body[data-theme='space'] .title-logo span { color: var(--accent); }
body[data-theme='space'] .eyebrow { letter-spacing: 0.45em; }
body[data-theme='space'] .win-card h2, body[data-theme='space'] .modal-card h3 { letter-spacing: 0.2em; }

/* ---- Azulejo: cobalt ink, ivory glaze and painted tile keylines ---- */
body[data-theme='azulejo'] { --tool-fs: 9px; }
body[data-theme='azulejo'] .title-logo { color: #17375d; text-shadow: 0 2px 0 #fffdf5; letter-spacing: 0.05em; }
body[data-theme='azulejo'] .title-logo span { color: #245b9e; }
body[data-theme='azulejo'] .hero-shade { background: linear-gradient(90deg, rgba(250,248,241,0.94), rgba(250,248,241,0.7) 38%, rgba(250,248,241,0.02) 75%); }
body[data-theme='azulejo'] .panel { box-shadow: 0 12px 38px rgba(23,55,93,0.2), inset 0 0 0 3px #faf8f1, inset 0 0 0 4px rgba(36,91,158,0.3); }
body[data-theme='azulejo'] .btn.primary { background: linear-gradient(180deg, #356aaa, #1b4781); color: #fffdf5; }
body[data-theme='azulejo'] .eyebrow::before { content: '❖'; margin-right: 12px; color: var(--accent); }
body[data-theme='azulejo'] .theme-card, body[data-theme='azulejo'] .theme-big { background: #faf8f1; }

/* ---- Jet Set: boarding-pass keylines, cream panels and tomato red ---- */
body[data-theme='jetset'] { --tool-fs: 9px; }
body[data-theme='jetset'] .title-logo { font-weight: 700; letter-spacing: -0.04em; color: #203b43; text-shadow: 0 2px 0 #faf2e1; }
body[data-theme='jetset'] .title-logo span { color: #b9362c; }
body[data-theme='jetset'] .hero-shade { background: linear-gradient(90deg, rgba(250,242,225,0.94), rgba(250,242,225,0.7) 38%, rgba(250,242,225,0.02) 75%); }
body[data-theme='jetset'] .panel { box-shadow: 0 12px 38px rgba(32,59,67,0.2), inset 0 3px 0 #b9362c; }
body[data-theme='jetset'] .btn.primary { background: linear-gradient(180deg, #ce493c, #a12b23); color: #fff9ed; }
body[data-theme='jetset'] .btn, body[data-theme='jetset'] .tool { font-weight: 700; }
body[data-theme='jetset'] .chip-deal { border-left: 3px solid #b9362c; }
body[data-theme='jetset'] .eyebrow { letter-spacing: 0.3em; font-weight: 700; }
body[data-theme='jetset'] .theme-card, body[data-theme='jetset'] .theme-big { background: #faf2e1; }

/* Light themes need opaque controls and darker feedback text. */
body:is([data-theme='azulejo'], [data-theme='jetset']) #hud { background: linear-gradient(180deg, rgba(250,248,241,0.96), rgba(250,248,241,0.6) 65%, transparent); }
body:is([data-theme='azulejo'], [data-theme='jetset']) .tool,
body:is([data-theme='azulejo'], [data-theme='jetset']) .icon-btn { background: var(--panel); border-color: var(--border); }
body:is([data-theme='azulejo'], [data-theme='jetset']) .status.ok { color: #206044; border-color: #398262; }
body:is([data-theme='azulejo'], [data-theme='jetset']) .status.bad { color: #a1232b; border-color: #b9362c; }
body:is([data-theme='azulejo'], [data-theme='jetset']) .row select,
body:is([data-theme='azulejo'], [data-theme='jetset']) .win-stats div,
body:is([data-theme='azulejo'], [data-theme='jetset']) .deal-pick { background: var(--panel); }
body:is([data-theme='azulejo'], [data-theme='jetset']) .deal-pick input::placeholder { color: var(--muted); opacity: 1; }
body:is([data-theme='azulejo'], [data-theme='jetset']) .theme-card span { background: var(--panel); color: var(--text); }
body:is([data-theme='azulejo'], [data-theme='jetset']) .ach.got .t-ico { color: #fffdf5; }
body:is([data-theme='azulejo'], [data-theme='jetset']) #loader { background: radial-gradient(circle at 50% 40%, #faf8f1, #c2d2e0 80%); }

/* ---- Riverboat Royale: engraved brass and oxblood velvet ---- */
body[data-theme='riverboat'] { --tool-fs: 10.5px; }
body[data-theme='riverboat'] .title-logo { font-weight: 700; letter-spacing: 0.03em; text-shadow: 0 4px 20px #100c08; }
body[data-theme='riverboat'] .title-logo span { color: var(--accent); }
body[data-theme='riverboat'] .btn, body[data-theme='riverboat'] .tool, body[data-theme='riverboat'] .chip { font-weight: 700; }
body[data-theme='riverboat'] .btn.primary { background: linear-gradient(180deg, #ebcf90, #ba8d43); color: #24150d; }
body[data-theme='riverboat'] .panel { box-shadow: 0 16px 48px rgba(0,0,0,0.5), inset 0 0 0 3px #20140d, inset 0 0 0 4px rgba(201,166,92,0.28); }
body[data-theme='riverboat'] .controls { background: linear-gradient(180deg, rgba(65,29,22,0.94), rgba(32,20,13,0.94)); }
body[data-theme='riverboat'] .eyebrow::before { content: '♠'; margin-right: 12px; color: var(--accent); }
body[data-theme='riverboat'] .modal-card h3 { letter-spacing: 0.12em; }

/* ---- Coastal Carvings: cedar relief, painted red borders and sea-green ink ---- */
body[data-theme='carvings'] { --tool-fs: 9px; }
body[data-theme='carvings'] .title-logo { font-weight: 700; letter-spacing: 0.035em; text-shadow: 0 4px 22px #100e0b; }
body[data-theme='carvings'] .title-logo span { color: #83b6b0; }
body[data-theme='carvings'] .btn.primary { background: linear-gradient(180deg, #c8583c, #963326); color: #fff0d9; }
body[data-theme='carvings'] .panel { border-top: 3px solid #ae3e2d; box-shadow: 0 14px 42px rgba(0,0,0,0.5), inset 0 0 0 3px #1f1711, inset 0 0 0 4px rgba(131,182,176,0.25); }
body[data-theme='carvings'] .controls { border-bottom: 3px solid #ae3e2d; }
body[data-theme='carvings'] .eyebrow { letter-spacing: 0.3em; }

/* ---- Varsity Club: cream stitching, athletic lettering and navy wool ---- */
body[data-theme='varsity'] { --tool-fs: 11px; }
body[data-theme='varsity'] .title-logo { text-transform: uppercase; font-weight: 700; letter-spacing: 0.025em; text-shadow: 3px 3px 0 #762932, 0 8px 30px rgba(0,0,0,0.65); }
body[data-theme='varsity'] .title-logo span { color: #edc56e; }
body[data-theme='varsity'] .btn { font-weight: 700; letter-spacing: 0.12em; }
body[data-theme='varsity'] .btn.primary { background: linear-gradient(180deg, #f4d58f, #d5a94e); color: #0f1b30; }
body[data-theme='varsity'] .panel { outline: 1px dashed rgba(255,244,218,0.5); outline-offset: -7px; }
body[data-theme='varsity'] .controls, body[data-theme='varsity'] .chip { border-style: dashed; }
body[data-theme='varsity'] .win-card h2 { color: #edc56e; text-shadow: 2px 2px 0 #762932; }
body[data-theme='varsity'] .eyebrow::before { content: '★'; margin-right: 10px; }

/* ---- Driftwood Bay: faded paint, rope keylines and soft seafoam ---- */
body[data-theme='driftwood'] { --tool-fs: 10.5px; }
body[data-theme='driftwood'] .title-logo { font-weight: 700; letter-spacing: 0.02em; text-shadow: 0 4px 24px rgba(12,30,40,0.8); }
body[data-theme='driftwood'] .title-logo span { color: #b0cfc5; }
body[data-theme='driftwood'] .btn, body[data-theme='driftwood'] .tool, body[data-theme='driftwood'] .chip { font-weight: 700; }
body[data-theme='driftwood'] .btn.primary { background: linear-gradient(180deg, #c5ded1, #8db7ac); color: #172a33; }
body[data-theme='driftwood'] .panel { box-shadow: 0 12px 38px rgba(12,30,40,0.45), inset 0 0 0 3px #172a33, inset 0 0 0 4px rgba(176,207,197,0.3); }
body[data-theme='driftwood'] .controls { border-bottom: 2px solid #d1c5a8; }
body[data-theme='driftwood'] .eyebrow { letter-spacing: 0.26em; }

/* ------------------------------ Responsive ------------------------------ */
@media (max-width: 1280px) { .brand-name, .brand-theme { display: none; } .brand { display: none; } }
@media (max-width: 960px) {
  .chip-deal { display: none; }
  .tool { min-width: 48px; height: 46px; padding: 0 5px; }
  .tool span { font-size: calc(var(--tool-fs, 9.5px) - 1px); letter-spacing: 0.04em; }
  .chip { min-width: 52px; padding: 3px 9px; }
}
@media (max-width: 800px) {
  .tool { min-width: 42px; height: 44px; padding: 0 3px; }
  .tool svg { width: 18px; height: 18px; }
  .chip span, .chip input { font-size: 15px; }
  .sep { display: none; }
}
/* Narrow screens: icons only (labels stay in the accessibility tree), still a single row where possible. */
@media (max-width: 700px) {
  .tool { min-width: 36px; width: 36px; height: 36px; padding: 0; }
  .tool span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .tool svg { width: 20px; height: 20px; }
  .chip { min-width: 44px; padding: 2px 7px; }
  .chip label { font-size: 8px; letter-spacing: 0.12em; }
  .chip.progress svg { display: none; }
}
@media (max-width: 560px) {
  #hud { flex-wrap: wrap; row-gap: 6px; }
  .hud-center { order: 3; width: 100%; }
  .hud-right { margin-left: auto; }
  .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .hint { display: none; }
  #toasts { top: auto; bottom: calc(70px + var(--safe-bottom)); right: 10px; }
}

/* Short viewports: shrink the hero and keep the featured themes compact. */
@media (max-height: 640px) {
  .title-logo { font-size: clamp(26px, min(9vw, 14vh), 96px); }
  .eyebrow { font-size: 11px; letter-spacing: 0.3em; }
  .title-tagline { font-size: clamp(12px, min(1.8vw, 2vh), 16px); margin-bottom: 0; }
  .title-actions { gap: 8px; }
  .btn.big { padding: 9px 14px; font-size: 13px; gap: 8px; }
  .deal-pick input { width: 64px; }
  .hint { display: none; }
  .title-themes { gap: 8px; }
  #btn-title-themes { padding: 8px 12px; font-size: 12px; }
}

/* Very short viewports: drop the decorative tagline and tighten everything so the
   theme selector and actions stay visible without scrolling. */
@media (max-height: 420px) {
  .title-content { padding: clamp(8px, 3vh, 18px) clamp(14px, 4.5vw, 60px); gap: clamp(4px, 1.2vh, 10px); }
  .title-logo { font-size: clamp(18px, min(8vw, 10vh), 52px); }
  .title-tagline { display: none; }
  .title-actions { gap: 6px; }
  .btn.big { padding: 6px 12px; font-size: 12px; gap: 6px; }
  .btn.big svg { width: 14px; height: 14px; }
  .deal-pick { padding: 2px 4px 2px 8px; font-size: 10px; gap: 5px; }
  .deal-pick input { width: 52px; font-size: 12px; }
  .theme-row { max-width: 398px; }
  .title-foot { margin-top: 0; }
}

/* Tiny windows: smallest step so even a ~320px-tall viewport fits. */
@media (max-height: 360px) {
  .title-content { gap: clamp(3px, 1vh, 8px); }
  .eyebrow { font-size: 10px; }
  .title-actions { gap: 5px; }
  .btn.big { padding: 5px 10px; font-size: 11px; }
  .deal-pick input { width: 46px; }
  .theme-row { max-width: 366px; padding-bottom: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .hero-layer img { animation: none; }
  .loader-suit { animation: none; }
}
