:root {
  --bg: #090714;
  --panel: rgba(24, 18, 54, 0.86);
  --panel-2: rgba(18, 12, 47, 0.9);
  --line: rgba(255,255,255,0.12);
  --text: #f7f3ff;
  --muted: #b9add5;
  --gold: #ffd76a;
  --violet: #8c6cff;
  --violet-2: #5f46d9;
  --green: #63e6be;
  --danger: #ff6b81;
  --shadow: 0 20px 70px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(circle at top, #20164a 0%, #0b0718 45%, #05040b 100%); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { overflow-x: hidden; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px clamp(14px, 3vw, 34px); background: rgba(8, 6, 20, 0.78); border-bottom: 1px solid var(--line); backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; color: #241244; font-weight: 900; background: linear-gradient(135deg, #ffe28a, #f7b84b); box-shadow: 0 0 24px rgba(255,215,106,0.34); }
.brand h1 { font-size: clamp(16px, 2.4vw, 22px); line-height: 1.05; margin: 0; letter-spacing: 0.01em; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 7px; background: rgba(255,255,255,0.055); padding: 5px; border: 1px solid var(--line); border-radius: 14px; }
.tab-btn { border: 0; border-radius: 10px; background: transparent; color: var(--muted); padding: 9px 16px; cursor: pointer; font-weight: 750; }
.tab-btn.active { color: white; background: linear-gradient(135deg, var(--violet), var(--violet-2)); box-shadow: 0 8px 24px rgba(109,80,255,.26); }

main { flex: 1; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.game-layout { width: min(1500px, 100%); margin: 0 auto; padding: clamp(12px, 2vw, 24px); display: grid; grid-template-columns: minmax(220px, 290px) minmax(0, 1fr) minmax(210px, 270px); gap: clamp(12px, 1.7vw, 22px); align-items: start; }
.side-panel { background: linear-gradient(180deg, rgba(32,24,68,.86), rgba(17,12,39,.88)); border: 1px solid var(--line); border-radius: 22px; padding: 18px; box-shadow: var(--shadow); position: sticky; top: 88px; }
.side-panel h2 { margin: 0 0 15px; font-size: 18px; }
.character-grid { display: grid; gap: 10px; }
.character-card { width: 100%; border: 1px solid var(--line); background: rgba(255,255,255,.045); color: white; display: grid; grid-template-columns: 46px 1fr; grid-template-rows: auto auto; column-gap: 11px; text-align: left; padding: 11px; border-radius: 16px; cursor: pointer; transition: .18s ease; }
.character-card:hover { transform: translateY(-2px); background: rgba(255,255,255,.075); }
.character-card.selected { border-color: rgba(255,215,106,.75); box-shadow: inset 0 0 0 1px rgba(255,215,106,.18), 0 10px 30px rgba(255,198,84,.08); }
.avatar { grid-row: 1 / 3; width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-weight: 900; color: #151020; }
.avatar-harry { background: linear-gradient(135deg, #d9c8ff, #7f6ee7); }
.avatar-ron { background: linear-gradient(135deg, #ffd0a8, #e87635); }
.avatar-hermione { background: linear-gradient(135deg, #ffeaa0, #bf8a37); }
.char-name { font-weight: 800; }
.char-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.control-help { margin: 16px 0; border-top: 1px solid var(--line); padding-top: 14px; }
.control-help h3 { margin: 0 0 9px; font-size: 13px; color: var(--gold); }
.control-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; font-size: 11px; border-bottom: 1px dashed rgba(255,255,255,.08); }
.control-row span { color: var(--muted); }
.control-row b { text-align: right; }
.primary-btn, .secondary-btn { width: 100%; border: 0; border-radius: 14px; padding: 12px 14px; cursor: pointer; font-weight: 850; }
.primary-btn { color: #1e1238; background: linear-gradient(135deg, #ffe786, #f4b93e); box-shadow: 0 12px 30px rgba(250,193,69,.2); }
.secondary-btn { margin-top: 8px; color: white; background: rgba(255,255,255,.08); border: 1px solid var(--line); }
.hidden { display: none !important; }

.game-stage-wrap { min-width: 0; }
.hud { display: grid; grid-template-columns: repeat(3, minmax(80px, 1fr)) auto auto; gap: 8px; margin-bottom: 10px; }
.hud-pill { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 7px; padding: 9px 12px; border-radius: 14px; border: 1px solid var(--line); background: rgba(19,14,42,.86); }
.hud-pill span { font-size: 11px; color: var(--muted); }
.hud-pill strong { font-size: 16px; }
.hud-icon { width: 42px; height: 42px; border-radius: 14px; border: 1px solid var(--line); background: rgba(19,14,42,.86); color: white; cursor: pointer; font-weight: 900; }
.canvas-frame { position: relative; width: 100%; aspect-ratio: 3 / 5; max-height: calc(100vh - 165px); min-height: 520px; overflow: hidden; border: 1px solid rgba(255,255,255,.14); border-radius: 24px; box-shadow: 0 24px 80px rgba(0,0,0,.42), 0 0 0 1px rgba(117,94,255,.08) inset; background: #0c0a1a; touch-action: none; }
#gameCanvas { width: 100%; height: 100%; display: block; }
.game-overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; background: linear-gradient(180deg, rgba(6,4,15,.18), rgba(6,4,15,.72)); z-index: 5; }
.overlay-card { width: min(430px, 92%); text-align: center; padding: clamp(22px, 4vw, 34px); border-radius: 24px; background: rgba(13,9,32,.86); border: 1px solid rgba(255,255,255,.16); backdrop-filter: blur(15px); box-shadow: var(--shadow); }
.overlay-card h2 { margin: 10px 0 10px; font-size: clamp(25px, 5vw, 42px); line-height: 1; }
.overlay-card p { color: var(--muted); line-height: 1.55; font-size: 14px; }
.overlay-card .primary-btn { margin-top: 10px; }
.magic-badge { width: 58px; height: 58px; border-radius: 18px; margin: 0 auto; display: grid; place-items: center; font-size: 26px; background: linear-gradient(135deg, #6045d9, #a477ff); box-shadow: 0 0 32px rgba(148,105,255,.35); }
.small-note { font-size: 11px !important; margin-bottom: 0; }
.eyebrow { font-size: 11px; letter-spacing: .18em; color: var(--gold); font-weight: 900; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0 10px; }
.result-grid div { padding: 12px 8px; background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 14px; }
.result-grid span { display: block; color: var(--muted); font-size: 10px; }
.result-grid strong { display: block; margin-top: 5px; font-size: 20px; }
.compact-card { width: min(330px, 90%); }

.mobile-controls { display: none; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.mobile-controls button { height: 52px; border: 1px solid var(--line); border-radius: 16px; color: white; background: rgba(30,23,65,.9); font-size: 20px; font-weight: 900; }

.mission-card { display: grid; grid-template-columns: 38px 1fr; gap: 10px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.mission-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: rgba(255,255,255,.07); color: var(--gold); }
.mission-card b { font-size: 13px; }
.mission-card p { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.status-card { margin-top: 16px; padding: 14px; border-radius: 16px; background: linear-gradient(135deg, rgba(109,80,255,.19), rgba(255,215,106,.08)); border: 1px solid rgba(255,255,255,.12); }
.status-card span, .status-card small { display: block; color: var(--muted); font-size: 10px; }
.status-card strong { display: block; margin: 4px 0 8px; font-size: 22px; color: var(--gold); }

.maker-panel { min-height: calc(100vh - 140px); padding: 40px 18px; }
.maker-card { width: min(820px, 100%); margin: 0 auto; text-align: center; background: linear-gradient(180deg, rgba(33,24,74,.9), rgba(15,10,35,.92)); border: 1px solid var(--line); border-radius: 28px; padding: clamp(28px, 5vw, 58px); box-shadow: var(--shadow); }
.maker-emblem { width: 78px; height: 78px; margin: 0 auto 18px; border-radius: 24px; display: grid; place-items: center; font-size: 34px; color: #241244; background: linear-gradient(135deg, #ffe589, #f2b53d); box-shadow: 0 0 50px rgba(255,211,96,.25); }
.maker-card h2 { margin: 9px 0 10px; font-size: clamp(32px, 6vw, 56px); }
.maker-intro { width: min(650px, 100%); margin: 0 auto 25px; color: var(--muted); line-height: 1.7; }
.maker-details { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 22px; }
.maker-details div { padding: 18px; border-radius: 18px; background: rgba(255,255,255,.045); border: 1px solid var(--line); }
.maker-details span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.maker-details strong, .maker-details a { color: white; font-size: 13px; text-decoration: none; word-break: break-word; }
.fan-note { margin-top: 28px; color: #8e83aa; font-size: 11px; line-height: 1.55; }

footer { display: flex; justify-content: space-between; gap: 12px; padding: 16px clamp(14px,3vw,34px); border-top: 1px solid var(--line); color: #897fa1; font-size: 11px; }

@media (max-width: 1100px) {
  .game-layout { grid-template-columns: 220px minmax(0, 1fr); }
  .info-panel { display: none; }
}

@media (max-width: 780px) {
  .topbar { padding: 10px 12px; }
  .brand p { display: none; }
  .brand-mark { width: 36px; height: 36px; border-radius: 12px; }
  .tab-btn { padding: 8px 12px; }
  .game-layout { display: block; padding: 10px; }
  .setup-panel { position: static; margin-bottom: 10px; padding: 12px; }
  .setup-panel h2, .control-help { display: none; }
  .character-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .character-card { display: flex; align-items: center; justify-content: center; flex-direction: column; text-align: center; padding: 8px 4px; gap: 5px; min-height: 92px; }
  .avatar { width: 38px; height: 38px; border-radius: 12px; }
  .char-sub { display: none; }
  .char-name { font-size: 11px; }
  #startBtn { display: none; }
  #installBtn { margin-top: 8px; }
  .hud { grid-template-columns: repeat(3, 1fr) auto auto; gap: 5px; }
  .hud-pill { padding: 7px 8px; display: block; text-align: center; }
  .hud-pill span { display: block; font-size: 9px; }
  .hud-pill strong { font-size: 14px; }
  .hud-icon { width: 38px; height: 38px; border-radius: 12px; }
  .canvas-frame { min-height: 0; max-height: none; border-radius: 20px; }
  .mobile-controls { display: grid; }
  .maker-details { grid-template-columns: 1fr; }
  footer { flex-direction: column; text-align: center; }
}

@media (max-width: 430px) {
  .brand h1 { font-size: 14px; }
  .brand-mark { width: 32px; height: 32px; }
  .tabs { padding: 3px; }
  .tab-btn { padding: 7px 9px; font-size: 12px; }
  .setup-panel { border-radius: 18px; }
  .canvas-frame { border-radius: 18px; }
  .overlay-card { padding: 22px 16px; }
  .overlay-card h2 { font-size: 30px; }
}

@media (display-mode: standalone) {
  .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
}


.share-btn { color: var(--gold); }
.toast { position: fixed; top: 82px; left: 50%; transform: translateX(-50%); z-index: 100; padding: 10px 16px; border-radius: 999px; background: rgba(15,10,35,.94); color: white; border: 1px solid rgba(255,255,255,.16); box-shadow: 0 14px 45px rgba(0,0,0,.35); font-size: 12px; font-weight: 800; backdrop-filter: blur(12px); }
@media (max-width: 430px) { .toast { top: 68px; max-width: calc(100vw - 24px); white-space: nowrap; } }
