/* Lumina Vale -- app styles. Colours follow the desktop game's UI theme. */
:root {
  --bg: #12131c;
  --panel: #1f2232;
  --panel2: #2c3044;
  --line: #3a3f5a;
  --gold: #f5d246;
  --gold2: #ffb43c;
  --text: #ebecf5;
  --muted: #9a9eb8;
  --red: #ff5a6e;
  --green: #5be08a;
  --blue: #5ab0ff;
  --pink: #ff8fd1;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  font-size: 16px;
}
html.car { font-size: 21px; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ------------------------------------------------------------- screens */
#ui {
  position: fixed; inset: 0; overflow-y: auto; overflow-x: hidden;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(90, 176, 255, 0.18), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(255, 143, 209, 0.14), transparent 60%),
    linear-gradient(180deg, #171a28, #10111a);
}
#ui.over-game { background: rgba(10, 11, 18, 0.72); backdrop-filter: blur(3px); }
.screen { max-width: 1100px; margin: 0 auto; animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.topnav { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topnav .spacer { flex: 1; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.logo img { height: 44px; width: auto; filter: drop-shadow(0 3px 8px rgba(0,0,0,.4)); }
.logo b { font-size: 1.35rem; letter-spacing: .02em; }

.hero { display: grid; gap: 8px; margin: 6px 0 22px; }
.hero h1 { margin: 0; font-size: clamp(1.7rem, 4.5vw, 2.8rem); line-height: 1.1; }
.hero p { margin: 0; color: var(--muted); font-size: 1.05rem; max-width: 640px; }
.hero .accent { background: linear-gradient(90deg, var(--gold), var(--pink)); -webkit-background-clip: text; background-clip: text; color: transparent; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tile {
  position: relative; display: flex; flex-direction: column; gap: 6px; text-align: left;
  min-height: 132px; padding: 18px; border-radius: var(--radius); border: 1px solid var(--line);
  background: linear-gradient(160deg, var(--panel2), var(--panel)); cursor: pointer; color: var(--text);
  box-shadow: var(--shadow); transition: transform .12s ease, border-color .12s ease;
}
.tile:hover, .tile:focus-visible { transform: translateY(-2px); border-color: var(--gold); outline: none; }
.tile .icon { font-size: 2rem; line-height: 1; }
.tile b { font-size: 1.15rem; }
.tile span { color: var(--muted); font-size: .95rem; }
.tile.big { grid-column: span 2; min-height: 160px; background: linear-gradient(135deg, #3b2b6e, #1f2a55 55%, #213a5b); }
.tile.big b { font-size: 1.45rem; }
@media (max-width: 560px) { .tile.big { grid-column: span 1; } }

.section-title { display: flex; align-items: center; gap: 10px; margin: 28px 0 12px; }
.section-title h2 { margin: 0; font-size: 1.25rem; }
.section-title .spacer { flex: 1; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.card {
  border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line);
  background: var(--panel); box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.card .thumb { height: 112px; background-size: cover; background-position: center; position: relative; }
.card .thumb .badge { position: absolute; top: 8px; right: 8px; }
.card .body { padding: 12px 14px 14px; display: grid; gap: 8px; }
.card .body b { font-size: 1.05rem; }
.card .meta { color: var(--muted); font-size: .88rem; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-size: .78rem;
  font-weight: 700; background: rgba(0,0,0,.55); color: #fff; }
.badge.live { background: var(--green); color: #0b2516; }
.badge.gold { background: var(--gold); color: #2a2205; }

/* -------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font-weight: 650; cursor: pointer; text-decoration: none;
  transition: background .12s, transform .08s, border-color .12s; user-select: none; white-space: nowrap;
}
.btn:hover { border-color: #5a6080; }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, var(--gold), var(--gold2)); color: #251c03; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: #4a1f2a; border-color: #7a2d40; color: #ffd6dd; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn.big { min-height: 56px; padding: 0 26px; font-size: 1.1rem; border-radius: 14px; }
.btn.icon { width: 44px; padding: 0; font-size: 1.2rem; }
.btn:disabled { opacity: .45; cursor: default; }
html.car .btn { min-height: 60px; }
html.car .btn.icon { width: 60px; }

/* --------------------------------------------------------------- forms */
.field { display: grid; gap: 6px; }
.field label { font-size: .9rem; color: var(--muted); font-weight: 600; }
.input, select.input {
  width: 100%; min-height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: #151724; color: var(--text); outline: none;
}
.input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(245, 210, 70, .2); }
.form { display: grid; gap: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.error-text { color: var(--red); font-weight: 600; min-height: 1.2em; }
.seg { display: inline-flex; background: #151724; border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 650; color: var(--muted); }
.seg button.on { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--gold); }
.range { width: 100%; accent-color: var(--gold); }

/* ---------------------------------------------------------- avatar chip */
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 99px;
  background: var(--panel2); border: 1px solid var(--line); cursor: pointer; font-weight: 650; }
.chip img, .avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: contain; object-position: center top;
  background: radial-gradient(circle at 50% 35%, #46507a, #23263a); }
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.char-pick { display: grid; justify-items: center; gap: 6px; padding: 10px; border-radius: 14px; background: var(--panel2);
  border: 2px solid transparent; cursor: pointer; }
.char-pick img { width: 72px; height: 88px; object-fit: contain; }
.char-pick span { font-size: .85rem; font-weight: 650; text-align: center; }
.char-pick.on { border-color: var(--gold); background: #383c56; }

/* --------------------------------------------------------------- modal */
#modals .modal-back {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(6, 7, 12, 0.65); backdrop-filter: blur(4px); animation: fade .15s;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(560px, 100%); max-height: calc(100% - 20px); overflow-y: auto; border-radius: 20px; padding: 22px;
  background: linear-gradient(180deg, #262a3d, #1d2030); border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: rise .18s ease-out;
}
.modal.wide { width: min(820px, 100%); }
.modal h2 { margin: 0 0 6px; font-size: 1.35rem; }
.modal .lead { margin: 0 0 16px; color: var(--muted); }
.modal .close { float: right; }

/* -------------------------------------------------------------- toasts */
#toasts { position: fixed; top: calc(70px + var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 60;
  display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { padding: 10px 18px; border-radius: 99px; background: rgba(20, 22, 36, .92); border: 1px solid var(--line);
  font-weight: 650; box-shadow: var(--shadow); animation: rise .2s, fade .4s 2.4s reverse forwards; }

/* ============================================================== in-game */
#play { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#play > * { pointer-events: auto; }
#hud { position: absolute; top: calc(10px + var(--safe-top)); left: calc(12px + var(--safe-left)); display: grid; gap: 6px; pointer-events: none; }
.hud-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px;
  background: rgba(14, 15, 25, .66); font-weight: 750; font-size: .95rem; text-shadow: 0 1px 2px #000; }
.hearts { letter-spacing: 1px; color: #ff4d67; }
.hearts .empty { color: rgba(255,255,255,.25); }
.ping { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--green); }
.ping.mid { background: var(--gold); } .ping.bad { background: var(--red); }

#topbar { position: absolute; top: calc(10px + var(--safe-top)); right: calc(12px + var(--safe-right)); display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; max-width: 70vw; }
.hbtn { min-width: 44px; height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,.12);
  background: rgba(14, 15, 25, .7); color: #fff; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.hbtn:hover { border-color: var(--gold); }
.hbtn.on { background: var(--gold); color: #2a2205; }
.hbtn .lbl { font-size: .9rem; }
@media (max-width: 700px) { .hbtn .lbl { display: none; } }
html.car .hbtn { height: 60px; min-width: 60px; font-size: 1.1rem; }

/* chat */
#chat { position: absolute; left: calc(12px + var(--safe-left)); bottom: calc(12px + var(--safe-bottom)); width: min(380px, 70vw);
  display: grid; gap: 6px; pointer-events: none; }
#chat .log { display: grid; gap: 4px; max-height: 32vh; overflow: hidden; align-content: end; }
#chat .msg { padding: 5px 10px; border-radius: 10px; background: rgba(14, 15, 25, .62); font-size: .92rem; width: fit-content;
  max-width: 100%; overflow-wrap: anywhere; transition: opacity .6s; text-shadow: 0 1px 2px #000; }
#chat .msg.old { opacity: 0; }
#chat.open .msg.old { opacity: 1; }
#chat .msg b { margin-right: 6px; }
#chat .msg.sys { color: var(--muted); font-style: italic; }
#chat .bar { display: flex; gap: 6px; pointer-events: auto; }
#chat .compose { display: grid; gap: 6px; pointer-events: auto; background: rgba(14, 15, 25, .88); padding: 8px; border-radius: 14px; border: 1px solid var(--line); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button { border: 1px solid var(--line); background: var(--panel2); border-radius: 99px; padding: 6px 10px; cursor: pointer; font-weight: 600; font-size: .88rem; }
.quick button.emo { font-size: 1.15rem; padding: 4px 9px; }
body.touch-on #chat { bottom: calc(150px + var(--safe-bottom)); }

/* status */
#status { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(8, 9, 15, .55); }
#status .box { padding: 20px 26px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); text-align: center; display: grid; gap: 10px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--gold); margin: 0 auto; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* players panel / overlays inside the game */
.panel { position: absolute; top: calc(64px + var(--safe-top)); right: calc(12px + var(--safe-right)); width: min(320px, 92vw);
  max-height: 70vh; overflow: auto; border-radius: 16px; background: rgba(22, 24, 38, .95); border: 1px solid var(--line);
  padding: 12px; box-shadow: var(--shadow); }
.plist { display: grid; gap: 6px; }
.plist .p { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 10px; background: rgba(255,255,255,.04); }
.plist .p .dot { width: 10px; height: 10px; border-radius: 50%; }
.plist .p .n { flex: 1; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .p .s { color: var(--muted); font-size: .85rem; }

/* build bar */
#buildbar { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px calc(10px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(10px + var(--safe-left));
  background: linear-gradient(0deg, rgba(10, 11, 18, .95), rgba(10, 11, 18, .82)); border-top: 1px solid var(--line); display: grid; gap: 8px; }
.bb-tools, .bb-libs, .bb-items { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; padding-bottom: 2px; }
.bb-tool { min-width: 46px; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-size: 1.3rem; cursor: pointer; }
.bb-tool.on { border-color: var(--gold); background: #4a4220; }
.bb-lib { flex: none; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-weight: 650; color: var(--muted); }
.bb-lib.on { color: #2a2205; background: var(--gold); border-color: var(--gold); }
.bb-item { flex: none; width: 54px; height: 54px; padding: 4px; border-radius: 12px; border: 2px solid transparent; background: #151724; cursor: pointer; font-size: 1.5rem; }
.bb-item img { width: 100%; height: 100%; object-fit: contain; image-rendering: auto; }
.bb-item.on { border-color: var(--gold); background: #2e2a18; }
.bb-hint { color: var(--muted); padding: 6px 4px; }
body.building #chat { bottom: calc(150px + var(--safe-bottom)); }
html.car .bb-item { width: 70px; height: 70px; }

/* end-of-level / game-over cards */
.overlay-card { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(8, 9, 15, .6); padding: 16px; }
.overlay-card .box { width: min(460px, 100%); text-align: center; padding: 26px; border-radius: 22px; background: linear-gradient(180deg, #2a2f48, #1d2030);
  border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(0,0,0,.5); display: grid; gap: 14px; animation: pop .3s cubic-bezier(.2, 1.4, .5, 1); }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }
.overlay-card h2 { margin: 0; font-size: 2rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div { background: rgba(255,255,255,.05); border-radius: 12px; padding: 10px 6px; }
.stats b { display: block; font-size: 1.4rem; }
.stats span { color: var(--muted); font-size: .8rem; }

/* level list */
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }

/* leaderboard */
table.board { width: 100%; border-collapse: collapse; }
table.board td, table.board th { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.board th { color: var(--muted); font-size: .85rem; }

/* controller test */
.padtest { display: grid; gap: 10px; }
.padtest .btns { display: flex; flex-wrap: wrap; gap: 6px; }
.padtest .b { min-width: 40px; padding: 6px 8px; border-radius: 8px; background: var(--panel2); text-align: center; font-weight: 700; font-size: .85rem; }
.padtest .b.on { background: var(--gold); color: #2a2205; }
.padtest .axes { font-family: ui-monospace, Consolas, monospace; color: var(--muted); }

/* rotate hint for portrait phones while playing */
#rotate { display: none; }
@media (orientation: portrait) and (max-width: 600px) {
  body.playing #rotate { display: grid; position: fixed; z-index: 4; left: 50%; bottom: calc(160px + var(--safe-bottom)); transform: translateX(-50%);
    padding: 8px 14px; border-radius: 99px; background: rgba(14,15,25,.8); font-weight: 650; font-size: .9rem; pointer-events: none; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ================================================================ party */
#party.party-side { position: absolute; top: calc(64px + var(--safe-top)); right: calc(12px + var(--safe-right)); width: min(380px, 94vw);
  max-height: calc(100% - 140px); overflow: auto; }
#party.party-side.mini .party-card > :not(:first-child) { display: none; }
#party.party-center { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(8, 9, 15, .45); }
#party.party-corner { position: absolute; top: calc(10px + var(--safe-top)); left: 50%; transform: translateX(-50%); }
#party.passthrough { pointer-events: none; background: transparent; }
.party-card { display: grid; gap: 12px; padding: 18px; border-radius: 20px; background: linear-gradient(180deg, rgba(42, 47, 72, .97), rgba(29, 32, 48, .97));
  border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(0, 0, 0, .45); }
.party-card h2 { margin: 0; }
.party-card .quick button { opacity: .55; }
.party-card .quick button.on { opacity: 1; border-color: var(--gold); background: #3d3a22; }
.party-card .quick button:disabled { cursor: default; }
.party-card.intro { width: min(520px, 100%); text-align: center; animation: pop .35s cubic-bezier(.2, 1.4, .5, 1); }
.party-card.intro p { font-size: 1.1rem; margin: 0; }
.big-icon { font-size: 4.5rem; line-height: 1; filter: drop-shadow(0 6px 14px rgba(0,0,0,.4)); }
.count { display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--gold); color: #2a2205; font-size: 1.5rem; }
.countdown { font-size: clamp(5rem, 22vw, 12rem); font-weight: 900; color: var(--gold); text-shadow: 0 8px 0 rgba(0,0,0,.35), 0 0 40px rgba(245,210,70,.5);
  animation: pop .5s cubic-bezier(.2, 1.4, .5, 1) infinite; }
.party-card.results { width: min(560px, 100%); }
.res-list { display: grid; gap: 6px; }
.res { display: grid; grid-template-columns: 40px 1fr auto auto; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 12px; background: rgba(255,255,255,.05); }
.res.me { background: rgba(245, 210, 70, .16); box-shadow: inset 0 0 0 1px var(--gold); }
.res .place { font-size: 1.4rem; text-align: center; }
.res .n { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res .s { color: var(--muted); }
.res .gain { color: var(--green); font-weight: 800; }
.board-track { position: relative; height: 92px; border-radius: 14px; background: linear-gradient(180deg, #2f6b3a, #23502c); overflow: hidden;
  display: flex; align-items: flex-end; gap: 3px; padding: 6px; }
.board-track .space { flex: 1; height: 14px; border-radius: 4px; background: #5ab0ff; box-shadow: 0 2px 0 rgba(0,0,0,.3); }
.board-track .space:nth-child(3n) { background: #ff5a6e; }
.board-track .space.star { background: var(--gold); }
.board-track .token { position: absolute; width: 34px; height: 42px; object-fit: contain; transition: left 1.2s cubic-bezier(.3, 1.3, .5, 1);
  filter: drop-shadow(0 3px 3px rgba(0,0,0,.5)); }
.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: end; gap: 8px; }
.pod { display: grid; justify-items: center; gap: 4px; padding: 10px 6px; border-radius: 12px 12px 4px 4px; background: rgba(255,255,255,.06); }
.pod img { width: 56px; height: 68px; object-fit: contain; }
.pod.first { min-height: 170px; background: linear-gradient(180deg, rgba(245,210,70,.35), rgba(245,210,70,.08)); }
.pod.second { min-height: 140px; } .pod.third { min-height: 120px; }
.pod b { overflow: hidden; text-overflow: ellipsis; max-width: 100%; white-space: nowrap; }
.pod span { color: var(--muted); font-size: .85rem; }

img.coin { width: 1.15em; height: 1.15em; vertical-align: -0.2em; margin-right: 2px; }
#party.pad-on .party-card { box-shadow: 0 0 0 3px var(--gold), 0 20px 60px rgba(0, 0, 0, .45); }

/* in-game layers stack above the touch controls (widgets.css: --lv-z-touch 40);
   #chat itself is pointer-events:none, so only its button bar takes taps */
#hud, #topbar, #chat, #party, #buildbar { z-index: 50; }
#status { z-index: 60; }

/* level-complete / game-over cards sit above the touch joystick zone (z 40) */
.overlay-card { z-index: 55; }
