:root {
  --bg: #1e1f22;          /* app shell background (near-black, gaming-client style) */
  --bg-soft: #2b2d31;
  --card: #2b2d31;
  --card-2: #313338;
  --card-3: #383a40;
  --text: #f2f3f5;
  --muted: #96989d;
  --border: #1a1b1e;
  --border-soft: #3f4147;
  --accent: #1d6fd6;      /* speakmx blue, now the primary highlight on dark UI */
  --accent-2: #5bb7ff;    /* bright blue for secondary highlights / hover */
  --navy: #0e3255;
  --gold: #f2b705;        /* speakmx gold accent */
  --teal: #23a6a8;
  --coral: #ef5a54;
  --good: #23a55a;
  --bad: #ef5a54;
  --warn: #f0b132;
  --radius: 10px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

#app { min-height: 100%; display: flex; flex-direction: column; }

.screen { display: none; flex: 1; flex-direction: column; padding: 18px; max-width: 900px; margin: 0 auto; width: 100%; }
.screen.active { display: flex; animation: fadeIn .35s ease; }

#screen-home.screen.active { max-width: none; padding: 0; display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none; } }

/* ---------- HUB SHELL: left icon rail (server-list style) + main content ---------- */
.hub-shell { display: flex; min-height: 100%; }

.hub-rail {
  width: 72px; flex-shrink: 0; background: var(--bg); border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 14px 0;
}
.rail-sep { width: 32px; height: 2px; background: var(--border-soft); border-radius: 1px; margin: 2px 0; }
.rail-spacer { flex: 1; }
.rail-icon {
  width: 48px; height: 48px; border-radius: 50%; background: var(--card-2); border: none; cursor: pointer;
  display: grid; place-items: center; transition: border-radius .15s ease, background-color .15s ease;
  position: relative;
}
.rail-icon-inner { font-size: 1.35rem; filter: grayscale(1); opacity: .75; transition: filter .15s, opacity .15s; }
.rail-icon:hover { border-radius: 16px; background: var(--accent); }
.rail-icon:hover .rail-icon-inner { filter: none; opacity: 1; }
.rail-icon.active { border-radius: 16px; background: var(--accent); }
.rail-icon.active .rail-icon-inner { filter: none; opacity: 1; }
.rail-icon.active::before {
  content: ""; position: absolute; left: -14px; top: 50%; transform: translateY(-50%);
  width: 5px; height: 22px; border-radius: 3px; background: var(--text);
}
.rail-icon.rail-danger:hover { background: var(--bad); }

.hub-main { flex: 1; min-width: 0; padding: 18px 22px 90px; max-width: 1100px; }

/* fixed bottom user panel (Discord-style persistent account bar) */
.user-panel {
  position: fixed; left: 0; right: 0; bottom: 0; height: 56px; z-index: 20;
  background: var(--card-2); border-top: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: 10px; padding: 0 18px;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--navy); display: grid; place-items: center;
  font-size: 1.1rem; border: 2px solid var(--good);
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-weight: 700; font-size: .85rem; }
.user-status { font-size: .72rem; color: var(--muted); }
.user-badge {
  margin-left: auto; font-size: .68rem; font-weight: 700; color: var(--muted);
  background: var(--card-3); border: 1px solid var(--border-soft); padding: 3px 8px; border-radius: 4px;
}

/* ---------- HUB HEADER / STATS ---------- */
.hub-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.hub-title { display: flex; align-items: center; gap: 12px; }
.logo-badge {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent);
  color: #fff; font-weight: 800; letter-spacing: 1px; border-bottom: 3px solid var(--gold);
}
.hub-title h1 { margin: 0; font-size: 1.25rem; color: var(--text); font-weight: 800; }
.hub-title .sub { margin: 2px 0 0; color: var(--muted); font-size: .82rem; }

.hub-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat {
  display: flex; align-items: center; gap: 6px; background: var(--card-2);
  padding: 7px 11px; border-radius: 6px; font-weight: 700; font-size: .85rem;
  border: 1px solid var(--border-soft); color: var(--text);
}
.stat-icon { font-size: .95rem; }

.xp-bar-wrap { margin: 16px 0 6px; display: flex; align-items: center; gap: 10px; }
.xp-bar { flex: 1; height: 8px; border-radius: 5px; background: var(--card-2); overflow: hidden; border: 1px solid var(--border-soft); }
.xp-fill { height: 100%; width: 0%; background: var(--accent); transition: width .6s ease; }
.xp-label { font-size: .72rem; color: var(--muted); white-space: nowrap; }

.game-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px; margin-top: 18px;
}

.game-card {
  position: relative; border-radius: var(--radius); padding: 14px 14px 14px 16px; cursor: pointer;
  background: var(--card-2);
  border: 1px solid var(--border-soft); border-left: 3px solid var(--cat-color, var(--accent));
  transition: background-color .12s ease, transform .12s ease;
  overflow: hidden; text-align: left;
}
.game-card:hover { background: var(--card-3); transform: translateX(2px); }
.game-card:active { transform: translateX(2px) scale(.99); }
.game-card .icon {
  width: 40px; height: 40px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border-soft);
  display: grid; place-items: center; font-size: 1.3rem; margin-bottom: 10px;
}
.game-card h3 { margin: 0 0 4px; font-size: .98rem; color: var(--text); }
.game-card p { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.35; }
.game-card .best {
  margin-top: 10px; font-size: .72rem; color: var(--cat-color, var(--accent-2)); font-weight: 700;
}
.game-card .tag {
  position: absolute; top: 12px; right: 12px; font-size: .6rem; padding: 3px 7px;
  border-radius: 4px; background: var(--cat-color, var(--accent)); color: #0b0c0d;
  text-transform: uppercase; letter-spacing: .5px; font-weight: 800;
}

.hub-footer { margin-top: auto; display: flex; justify-content: space-between; align-items: center; padding-top: 22px; color: var(--muted); font-size: .78rem; }

.ghost-btn, .btn, .primary-btn {
  border-radius: 6px; border: 1px solid var(--border-soft); background: var(--card-2); color: var(--text);
  padding: 9px 16px; font-size: .85rem; cursor: pointer; font-weight: 700;
}
.ghost-btn:hover, .btn:hover { border-color: var(--accent); color: var(--accent-2); }
.primary-btn { background: var(--accent); border: 1px solid var(--accent); color: white; }
.primary-btn:hover { background: #1861bd; }
.primary-btn:active { transform: translateY(1px); }
.primary-btn:disabled, .btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- GAME SCREEN ---------- */
.game-header { display: flex; align-items: center; gap: 12px; }
.game-header h2 { flex: 1; margin: 0; font-size: 1.05rem; color: var(--text); }
.icon-btn {
  background: var(--card-2); border: 1px solid var(--border-soft); color: var(--text); width: 38px; height: 38px;
  border-radius: 8px; font-size: 1.1rem; cursor: pointer;
}
.chip { background: var(--card-2); border: 1px solid var(--border-soft); padding: 6px 12px; border-radius: 6px; font-weight: 700; font-size: .82rem; }
.game-header-stats { display: flex; gap: 8px; }

.game-root { flex: 1; margin-top: 14px; display: flex; flex-direction: column; gap: 12px; position: relative; }

/* generic building blocks reused across games */
.panel { background: var(--card-2); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 16px; }
.center-box { display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; gap:12px; flex:1; }
.instructions { color: var(--muted); font-size: .88rem; line-height: 1.5; }

.tile {
  padding: 10px 14px; border-radius: 8px; background: var(--card-3); border: 1px solid var(--border-soft);
  cursor: grab; user-select: none; font-weight: 700; transition: transform .12s; color: var(--text);
}
.tile:active { cursor: grabbing; transform: translateY(1px); }
.tile.dragging { opacity: .4; }
.tile.correct { background: rgba(35,165,90,.18); border-color: var(--good); }
.tile.wrong { background: rgba(239,90,84,.18); border-color: var(--bad); animation: shake .3s; }

@keyframes shake { 0%,100%{transform:translateX(0);} 25%{transform:translateX(-6px);} 75%{transform:translateX(6px);} }
@keyframes pop { 0%{ transform: scale(.85); opacity:0;} 100%{ transform: scale(1); opacity:1;} }
.pop-in { animation: pop .25s ease; }

.pill-row { display: flex; flex-wrap: wrap; gap: 8px; }
.dropzone {
  min-height: 52px; border: 2px dashed var(--border-soft); border-radius: 10px; padding: 8px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  background: var(--bg-soft);
}
.dropzone.over { border-color: var(--accent-2); background: rgba(91,183,255,.1); }

.feedback-banner {
  position: absolute; left: 50%; top: 8px; transform: translateX(-50%); padding: 8px 18px; border-radius: 8px;
  font-weight: 800; opacity: 0; pointer-events: none; transition: all .25s; box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
.feedback-banner.show { opacity: 1; top: -2px; }
.feedback-banner.good { background: var(--good); color: #ffffff; }
.feedback-banner.bad { background: var(--bad); color: #ffffff; }

.timer-bar { height: 8px; border-radius: 6px; background: var(--card-3); overflow: hidden; border: 1px solid var(--border-soft); }
.timer-fill { height: 100%; background: var(--good); width: 100%; transform-origin: left; transition: background-color .2s; }
.timer-fill.warn { background: var(--warn); }
.timer-fill.danger { background: var(--bad); }

.result-card { text-align: center; display:flex; flex-direction:column; gap:10px; align-items:center; }
.result-card .big-score { font-size: 2.4rem; font-weight: 900; color: var(--accent-2); }
.result-row { display: flex; gap: 10px; }

.toast {
  position: fixed; bottom: 74px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--card-3); border: 1px solid var(--accent); padding: 10px 18px; border-radius: 8px;
  color: #fff; font-weight: 700; opacity: 0; pointer-events: none; transition: all .3s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* canvas games */
canvas.game-canvas { width: 100%; background: var(--bg-soft); border-radius: var(--radius); border: 1px solid var(--border-soft); touch-action: none; display: block; }

/* WebGL canvas wrapper + floating HTML labels projected from 3D world space */
.canvas-wrap { position: relative; }
.canvas-wrap canvas.game-canvas { display: block; }
.webgl-label {
  position: absolute; font-weight: 800; font-size: .82rem; pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,.6); z-index: 3;
}

/* small rotating 3D scenario banners (replace the old flat CSS scene-banner look) */
.scene-webgl { position: relative; height: 96px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border-soft); }
.scene-webgl canvas { width: 100%; height: 100%; display: block; }

/* word rain specific */
.wr-input-row { display: flex; gap: 8px; }
.wr-input-row input { flex: 1; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border-soft); background: var(--card-2); color: var(--text); font-size: 1rem; }

/* option buttons grid */
.opt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap: 10px; }
.opt-btn {
  padding: 14px 10px; border-radius: 8px; background: var(--card-3); border: 1px solid var(--border-soft); color: var(--text);
  font-weight: 700; cursor: pointer; font-size: .95rem;
}
.opt-btn:hover { border-color: var(--accent-2); }
.opt-btn:active { transform: translateY(1px); }
.opt-btn.correct { background: rgba(35,165,90,.22); border-color: var(--good); }
.opt-btn.wrong { background: rgba(239,90,84,.22); border-color: var(--bad); }

/* story branch */
.story-text { font-size: 1.05rem; line-height: 1.6; }
.story-choice { display:block; width:100%; text-align:left; margin-top:8px; }

/* idiom charades */
.idiom-scene { font-size: 3.4rem; text-align: center; padding: 20px; }

/* escape room */
.room-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.lock-row { display:flex; gap:8px; align-items:center; flex-wrap: wrap; }

/* spelling duel */
.vs-row { display:flex; justify-content:space-between; align-items:center; gap: 10px; }
.vs-side { flex:1; background: var(--card-3); border: 1px solid var(--border-soft); border-radius: 10px; padding: 12px; text-align:center; }
.vs-bar { height: 10px; background: var(--card); border-radius: 6px; overflow: hidden; margin-top:6px; border:1px solid var(--border-soft);}
.vs-fill { height:100%; background: var(--accent-2); width:0%; transition: width .3s; }
.vs-fill.ai { background: var(--coral); }

/* ---------- scenario banners: flat, illustrated mini-scenes for each game (no gradients) ---------- */
.scene-banner {
  position: relative; height: 84px; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
}
.scene-banner .scene-icon { font-size: 2.3rem; position: relative; z-index: 2; filter: drop-shadow(0 2px 0 rgba(0,0,0,.15)); }
.scene-dot { position: absolute; border-radius: 50%; z-index: 1; }
.scene-bar { position: absolute; z-index: 1; }

.scene-detective { background: #16233a; }
.scene-detective .scene-dot:nth-child(1) { width: 10px; height: 10px; background: var(--coral); top: 14px; left: 22px; }
.scene-detective .scene-dot:nth-child(2) { width: 10px; height: 10px; background: var(--gold); top: 20px; right: 34px; }
.scene-detective .scene-dot:nth-child(3) { width: 8px; height: 8px; background: var(--accent-2); bottom: 16px; left: 46px; }
.scene-detective .scene-bar { width: 60px; height: 2px; background: rgba(255,255,255,.25); top: 40px; left: 20px; transform: rotate(8deg); }
.scene-detective .scene-bar.b2 { width: 44px; top: 50px; right: 30px; left: auto; transform: rotate(-12deg); }

.scene-story { background: #f6ead2; border-color: #e3d3ab; }
.scene-story::after {
  content: ""; position: absolute; top: 0; right: 20px; width: 22px; height: 44px; background: var(--coral);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%);
}
.scene-story .scene-dot { width: 5px; height: 5px; background: #c9a969; bottom: 10px; }
.scene-story .scene-dot:nth-child(1) { left: 16px; }
.scene-story .scene-dot:nth-child(2) { left: 30px; }
.scene-story .scene-dot:nth-child(3) { left: 44px; }

.scene-vault { background: #2b3648; }
.scene-vault::before {
  content: ""; position: absolute; width: 52px; height: 52px; border-radius: 50%; border: 6px solid var(--gold);
  top: 50%; left: 50%; margin: -26px 0 0 -26px;
}
.scene-vault::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--accent-2);
  top: 50%; left: 50%; margin: -8px 0 0 -8px;
}
.scene-vault .scene-dot { width: 6px; height: 6px; background: var(--muted); }
.scene-vault .scene-dot:nth-child(1) { top: 10px; left: 10px; }
.scene-vault .scene-dot:nth-child(2) { top: 10px; right: 10px; }
.scene-vault .scene-dot:nth-child(3) { bottom: 10px; left: 10px; }

.scene-stage { background: #3a1620; }
.scene-stage::before, .scene-stage::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 26%; background: #591f2e;
}
.scene-stage::before { left: 0; clip-path: polygon(0 0, 100% 0, 70% 100%, 0 100%); }
.scene-stage::after { right: 0; clip-path: polygon(0 0, 100% 0, 100% 100%, 30% 100%); }

.scene-portal { background: #101b2e; }
.scene-portal::before {
  content: ""; position: absolute; width: 58px; height: 58px; border-radius: 50%; border: 4px solid var(--accent-2);
  top: 50%; left: 50%; margin: -29px 0 0 -29px;
}
.scene-portal::after {
  content: ""; position: absolute; width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--gold);
  top: 50%; left: 50%; margin: -17px 0 0 -17px;
}

.scene-arena { background: var(--accent); }
.scene-arena::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 50%; background: var(--coral); }
.scene-arena .scene-icon { z-index: 3; }

.scene-web { background: #101b2e; }
.scene-web .scene-dot { width: 6px; height: 6px; background: var(--accent-2); }
.scene-web .scene-dot:nth-child(1) { top: 14px; left: 30px; }
.scene-web .scene-dot:nth-child(2) { top: 20px; right: 26px; }
.scene-web .scene-dot:nth-child(3) { bottom: 14px; left: 50%; }
.scene-web .scene-bar { width: 40px; height: 1px; background: rgba(255,255,255,.3); top: 22px; left: 34px; transform: rotate(20deg); }
.scene-web .scene-bar.b2 { width: 36px; top: 26px; right: 32px; left: auto; transform: rotate(-24deg); }

.scene-workshop { background: var(--card-2); }
.scene-workshop .scene-dot { width: 22px; height: 14px; border-radius: 3px; background: var(--gold); }
.scene-workshop .scene-dot:nth-child(1) { bottom: 12px; left: 20%; background: var(--accent-2); }
.scene-workshop .scene-dot:nth-child(2) { bottom: 12px; left: 45%; background: var(--coral); }
.scene-workshop .scene-dot:nth-child(3) { bottom: 12px; left: 70%; background: var(--good); }

/* ---------- virtual joystick + action buttons (gamepad / touch controller) ---------- */
.vpad { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 6px; }
.vjoy {
  width: 108px; height: 108px; border-radius: 50%; background: var(--card-2); border: 2px solid var(--border-soft);
  position: relative; touch-action: none; flex-shrink: 0;
}
.vjoy-knob {
  width: 46px; height: 46px; border-radius: 50%; background: var(--accent-2); position: absolute;
  top: 50%; left: 50%; margin: -23px 0 0 -23px; box-shadow: 0 4px 10px rgba(16,35,60,.25); transition: transform .05s linear;
}
.vbtn-col { display: flex; gap: 10px; }
.vbtn {
  width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--border-soft); background: var(--card);
  font-size: 1.3rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  cursor: pointer; touch-action: none; color: var(--text);
}
.vbtn span { font-size: .55rem; font-weight: 700; color: var(--muted); }
.vbtn-action { background: var(--accent-2); color: #fff; border-color: var(--accent-2); }
.vbtn-action span { color: rgba(255,255,255,.85); }
.vbtn:active, .vjoy:active { filter: brightness(0.95); }
.controller-hint { text-align: center; color: var(--muted); font-size: .78rem; margin: 4px 0 0; }

@media (max-width: 480px) {
  .hub-title h1 { font-size: 1.15rem; }
  :root { font-size: 15px; }
}

