/* EagliumX Launcher */
:root {
  --bg: #0b0d0c;
  --surface: #121614;
  --surface-2: #181d1a;
  --surface-3: #1f2521;
  --line: #262d29;
  --line-2: #323a35;
  --text: #e9ece9;
  --muted: #8d978f;
  --faint: #5b645d;
  --accent: #f3b33d;
  --accent-2: #ffc95e;
  --accent-ink: #1a1203;
  --accent-soft: rgba(243, 179, 61, .12);
  --danger: #ef5a4f;
  --ok: #6fcf7f;
  --r: 14px;
  --r-sm: 10px;
  --display: 'Cabinet Grotesk', 'General Sans', system-ui, sans-serif;
  --body: 'General Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --ease: cubic-bezier(.2, .8, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 400 15px/1.5 var(--body); -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-user-select: none; user-select: none; }
[hidden] { display: none !important; }
code, kbd { font-family: var(--mono); font-size: .88em; background: var(--surface-3); border: 1px solid var(--line); border-radius: 5px; padding: .05em .35em; }
svg { flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------- shell ---------------- */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
body.playing .shell { display: none; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px;
  padding: calc(12px + var(--sat)) calc(20px + var(--sar)) 12px calc(20px + var(--sal));
  background: rgba(11, 13, 12, .86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand-mark { width: 30px; height: 30px; }
.brand-name { font: 800 21px/1 var(--display); letter-spacing: -.01em; }
.brand-sub { font: 500 12px/1 var(--body); color: var(--muted); border: 1px solid var(--line-2); padding: 4px 7px; border-radius: 999px; letter-spacing: .02em; }
.tabs { display: flex; gap: 4px; margin-left: auto; background: var(--surface); border: 1px solid var(--line); padding: 4px; border-radius: 12px; }
.tabs button { border: 0; background: none; padding: 7px 14px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.tabs button.on { background: var(--surface-3); color: var(--text); }
.tabs button:hover { color: var(--text); }

main { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: 28px calc(20px + var(--sar)) 40px calc(20px + var(--sal)); }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
h1 { font: 800 clamp(30px, 6vw, 40px)/1.05 var(--display); letter-spacing: -.02em; margin: 0; }
h2 { font: 700 20px/1.2 var(--display); margin: 0; }
h3 { font: 600 12px/1 var(--body); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.sub { color: var(--muted); margin: 6px 0 0; }
.head-acts { display: flex; gap: 8px; }
.lede { color: var(--muted); margin: -8px 0 18px; }

.bottom-nav { display: none; }

@media (max-width: 720px) {
  .tabs { display: none; }
  .brand-sub { display: none; }
  main { padding-top: 20px; padding-bottom: calc(96px + var(--sab)); }
  .bottom-nav {
    display: flex; position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
    padding: 6px calc(8px + var(--sar)) calc(6px + var(--sab)) calc(8px + var(--sal));
    background: rgba(13, 16, 14, .94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
  }
  .bottom-nav button {
    flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 7px 0 5px; color: var(--faint); font-size: 11.5px; font-weight: 500; border-radius: 10px;
  }
  .bottom-nav svg { width: 24px; height: 24px; }
  .bottom-nav button.on { color: var(--accent); }
  .view-head .head-acts .btn span { display: none; }
  .view-head .head-acts .btn { padding: 0; width: 44px; justify-content: center; }
}

/* ---------------- buttons & inputs ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface-2); color: var(--text);
  font-weight: 500; white-space: nowrap; transition: background .15s, border-color .15s, transform .1s;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { background: transparent; border-color: rgba(239, 90, 79, .4); color: #ff8a80; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.sm svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-row { display: flex; gap: 8px; margin: 14px 0; }
.btn-row.wrap { flex-wrap: wrap; }
.btn-row.center { justify-content: center; }
.btn-row > .btn { flex: 1 1 auto; }
.icon-btn { width: 44px; height: 44px; display: inline-grid; place-items: center; border: 1px solid transparent; background: none; border-radius: 12px; color: var(--muted); }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.link-btn { background: none; border: 0; color: var(--muted); padding: 8px 0; text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 4px; }
.link-btn:hover { color: var(--text); }
.input { width: 100%; min-height: 42px; padding: 0 12px; background: var(--bg); border: 1px solid var(--line-2); border-radius: 10px; color: var(--text); font-size: 16px; }
select.input { padding-right: 32px; appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238d978f' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; }
.input:focus { border-color: var(--accent); outline: none; }
.field { display: block; }
.field > span { display: block; color: var(--muted); font-size: 14px; margin-bottom: 6px; }

/* ---------------- library ---------------- */
.empty { display: grid; gap: 18px; }
.drop {
  text-align: center; padding: 36px 20px 30px; border-radius: 20px;
  background: radial-gradient(120% 90% at 50% 0%, rgba(243, 179, 61, .09), transparent 60%), var(--surface);
  border: 1px solid var(--line);
}
.drop-art { color: var(--line-2); width: 120px; margin: 0 auto 18px; }
.drop h2 { font-size: clamp(21px, 4.6vw, 26px); }
.drop p { color: var(--muted); max-width: 460px; margin: 10px auto 18px; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; counter-reset: s; }
.steps li { counter-increment: s; padding: 16px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.steps li::before { content: counter(s); display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); font: 700 13px/1 var(--display); margin-bottom: 10px; }
.steps b { display: block; font-weight: 600; margin-bottom: 4px; }
.steps span { color: var(--muted); font-size: 14px; }
@media (max-width: 720px) { .steps { grid-template-columns: 1fr; } }

.games { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.game { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); transition: border-color .15s; }
.game:hover { border-color: var(--line-2); }
.game-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; border: 0; background: none; text-align: left; padding: 0; }
.game-cover {
  width: 60px; height: 60px; flex: none; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(160deg, #2b3a2b, #19241a); border: 1px solid rgba(255, 255, 255, .06);
  font: 800 15px/1 var(--display); color: #cfe7c4; letter-spacing: -.01em; position: relative; overflow: hidden;
}
.game-cover::after { content: ''; position: absolute; inset: auto 0 0 0; height: 30%; background: linear-gradient(0deg, rgba(0, 0, 0, .25), transparent); }
.game-cover span { position: relative; z-index: 1; }
.fam-x18w { background: linear-gradient(160deg, #3e3317, #241d0d); color: #ffd98a; }
.fam-x112, .fam-x112w { background: linear-gradient(160deg, #1f3140, #121d26); color: #b9dcf5; }
.fam-e152 { background: linear-gradient(160deg, #3a2a24, #221713); color: #f0c5b3; }
.fam-b13 { background: linear-gradient(160deg, #2d2d33, #18181d); color: #d6d6e4; }
.fam-x121, .fam-e262 { background: linear-gradient(160deg, #2c2240, #191326); color: #d8c7ff; }
.fam-other { background: linear-gradient(160deg, #2a2f2c, #171a18); color: #c4ccc6; }
.game-info { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.game-name { font: 700 17px/1.2 var(--display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-meta { display: flex; gap: 5px; flex-wrap: wrap; }
.game-sub { color: var(--faint); font-size: 13px; }
.tag { font: 500 11.5px/1 var(--body); padding: 4px 7px; border-radius: 6px; background: var(--surface-3); color: var(--muted); border: 1px solid var(--line); }
.tag-w { color: var(--accent); border-color: rgba(243, 179, 61, .3); background: var(--accent-soft); }
.tag-a { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.game-acts { display: flex; align-items: center; gap: 2px; }
.play-btn svg { width: 16px; height: 16px; }
@media (max-width: 520px) {
  .game-cover { width: 52px; height: 52px; font-size: 13px; }
  .play-btn { width: 48px; padding: 0; }
  .play-btn span { display: none; }
  .game-name { font-size: 16px; }
}
.lib-more { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 18px; font-size: 14px; }

/* ---------------- layouts ---------------- */
.layouts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 12px; }
.layout { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); padding: 10px; display: grid; grid-template-columns: 1fr auto; gap: 10px 8px; }
.layout-prev { grid-column: 1 / -1; }
.layout-prev svg { display: block; width: 100%; height: auto; }
.mp-bg { fill: #1b2a1d; }
.mp-c { fill: rgba(255, 255, 255, .1); stroke: rgba(255, 255, 255, .45); stroke-width: .8; }
.mp-a { stroke: var(--accent); }
.layout-info { min-width: 0; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; padding-left: 4px; }
.layout-info strong { font: 700 16px/1.2 var(--display); }
.layout-info small { color: var(--faint); font-size: 13px; }
.layout-acts { display: flex; align-items: center; gap: 2px; }
.howto { margin-top: 26px; padding: 18px 18px 6px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.howto dl { display: grid; grid-template-columns: 110px 1fr; gap: 10px 14px; margin: 14px 0; }
.howto dt { font-weight: 600; }
.howto dd { margin: 0; color: var(--muted); }

/* ---------------- settings groups ---------------- */
.group { margin: 0 0 18px; padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.group h3 { margin-bottom: 8px; }
.group.compact { padding: 4px 14px; }
.group-note { color: var(--muted); font-size: 14px; margin: 8px 0 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-l { min-width: 0; flex: 1 1 auto; }
.row-l span { display: block; }
.row-l small { display: block; color: var(--faint); font-size: 13px; line-height: 1.35; margin-top: 2px; }
.row-r { flex: 0 1 auto; display: flex; justify-content: flex-end; }
.row-r .input { min-width: 190px; }
@media (max-width: 520px) {
  .row { flex-wrap: wrap; }
  .row-r { flex: 1 1 100%; justify-content: stretch; }
  .row-r > * { flex: 1; }
  .row-r .input { min-width: 0; }
  .row:has(.switch) { flex-wrap: nowrap; }
  .row:has(.switch) .row-r { flex: 0 0 auto; }
}
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; min-height: 34px; padding: 0 12px; border-radius: 7px; color: var(--muted); font-size: 14px; font-weight: 500; flex: 1; white-space: nowrap; }
.seg button.on { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.switch { position: relative; width: 48px; height: 28px; flex: none; display: inline-block; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--surface-3); border: 1px solid var(--line-2); transition: background .15s; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: transform .2s var(--ease), background .15s; }
.switch input:checked + i { background: var(--accent); border-color: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); background: var(--accent-ink); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.range { display: flex; align-items: center; gap: 10px; min-width: 210px; }
.range input { flex: 1; }
.range output { min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
input[type=range] { -webkit-appearance: none; appearance: none; height: 28px; background: transparent; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--line-2); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--line-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); }

.caps { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin-top: 8px; }
.caps > div { padding: 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.caps > div > span:first-child { font-weight: 500; }
.caps small { color: var(--faint); font-size: 13px; }
.cap { font: 600 12px/1 var(--body); align-self: flex-start; padding: 4px 8px; border-radius: 6px; }
.cap.ok { color: var(--ok); background: rgba(111, 207, 127, .1); }
.cap.no { color: #ff8a80; background: rgba(239, 90, 79, .1); }
.vt { display: grid; gap: 0; margin-top: 6px; }
.vt-row { display: grid; grid-template-columns: 230px 1fr; gap: 6px 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.vt-row:last-child { border-bottom: 0; }
.vt-name { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.vt-d span { display: block; }
.vt-d small { display: block; color: var(--faint); font-size: 13px; margin-top: 2px; }
.lvl { font: 600 11px/1 var(--body); padding: 4px 7px; border-radius: 6px; letter-spacing: .02em; }
.lvl-best { color: var(--accent-ink); background: var(--accent); }
.lvl-good { color: var(--ok); background: rgba(111, 207, 127, .1); }
.lvl-ok { color: var(--muted); background: var(--surface-3); }
@media (max-width: 620px) { .vt-row { grid-template-columns: 1fr; } }
.danger-zone { border-color: rgba(239, 90, 79, .22); }
.foot { color: var(--faint); font-size: 13px; text-align: center; max-width: 560px; margin: 26px auto 0; }

/* ---------------- sheets ---------------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: flex-end; justify-content: center; }
.sheet-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); opacity: 0; transition: opacity .2s; }
.sheet {
  position: relative; width: 100%; max-width: 560px; max-height: min(88dvh, 860px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line-2); border-bottom: 0; border-radius: 22px 22px 0 0;
  transform: translateY(100%); transition: transform .26s var(--ease); box-shadow: 0 -20px 60px rgba(0, 0, 0, .45);
  padding-bottom: var(--sab);
}
.sheet-wrap.open .sheet-scrim { opacity: 1; }
.sheet-wrap.open .sheet { transform: none; }
.sheet-grip { width: 38px; height: 4px; border-radius: 4px; background: var(--line-2); margin: 8px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px 8px 20px; flex: none; }
.sheet-head h2 { font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { overflow-y: auto; padding: 4px 20px 20px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet-body .group { background: var(--surface-2); }
.sheet-text { color: var(--muted); margin: 4px 0 16px; }
.sheet-text b { color: var(--text); font-weight: 600; }
.sheet-text.muted { font-size: 12px; opacity: .8; }
.crash-log { max-height: 30vh; overflow: auto; font: 11px/1.4 ui-monospace, monospace; background: rgba(0,0,0,.35); padding: 8px; border-radius: 8px; white-space: pre-wrap; word-break: break-word; }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.sheet-actions .btn { flex: 1; }
.sheet-wrap.small .sheet { max-width: 440px; }
@media (min-width: 721px) {
  .sheet-wrap { align-items: center; padding: 24px; }
  .sheet { border-radius: 20px; border-bottom: 1px solid var(--line-2); transform: translateY(16px) scale(.98); opacity: 0; transition: transform .22s var(--ease), opacity .18s; }
  .sheet-wrap.open .sheet { opacity: 1; }
  .sheet-grip { display: none; }
  .sheet-head { padding-top: 14px; }
}
.bar { height: 6px; border-radius: 6px; background: var(--surface-3); overflow: hidden; position: relative; }
.bar i { position: absolute; inset: 0 auto 0 0; width: 30%; background: var(--accent); border-radius: 6px; animation: indet 1.2s ease-in-out infinite; }
.bar.det i { animation: none; transition: width .2s; }
@keyframes indet { 0% { left: -30%; } 100% { left: 100%; } }
.list-acts { display: flex; flex-direction: column; margin: 0 -8px; }
.list-acts button { text-align: left; background: none; border: 0; padding: 14px 8px; border-radius: 10px; font-weight: 500; }
.list-acts button:hover { background: var(--surface-3); }
.list-acts .danger { color: #ff8a80; }
.game-head { display: flex; align-items: center; gap: 14px; }
.game-head strong { display: block; font: 700 19px/1.2 var(--display); }
.game-head small { color: var(--faint); font-size: 13px; }

/* in-game menu (landscape-friendly) */
.sheet-wrap.menu .sheet { max-width: 620px; }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-bottom: 14px; }
.tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 84px; padding: 10px; border-radius: 14px; border: 1px solid var(--line-2); background: var(--surface-2); font-weight: 500; font-size: 14px; }
.tile svg { width: 24px; height: 24px; }
.tile:first-child { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
@media (orientation: landscape) and (max-height: 520px) {
  .sheet-wrap { align-items: stretch; justify-content: flex-end; padding: 0; }
  .sheet { max-height: 100dvh; height: 100dvh; max-width: 420px !important; border-radius: 20px 0 0 20px; border: 1px solid var(--line-2); border-right: 0; transform: translateX(100%); opacity: 1; padding-bottom: 0; padding-right: var(--sar); }
  .sheet-wrap.open .sheet { transform: none; }
  .sheet-grip { display: none; }
  .sheet-wrap.small .sheet { height: auto; max-height: 100dvh; align-self: center; border-radius: 20px 0 0 20px; }
  .menu-grid { grid-template-columns: repeat(2, 1fr); }
  .tile { min-height: 64px; flex-direction: row; }
}

/* ---------------- toast & drop veil ---------------- */
.toast {
  position: fixed; z-index: 2000; left: 50%; bottom: calc(24px + var(--sab)); transform: translate(-50%, 20px);
  max-width: min(92vw, 520px); padding: 12px 16px; border-radius: 12px; background: #20271f; color: var(--text);
  border: 1px solid var(--line-2); box-shadow: 0 10px 30px rgba(0, 0, 0, .4); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .25s var(--ease); font-size: 14px; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #2d1614; border-color: rgba(239, 90, 79, .45); }
@media (max-width: 720px) { body:not(.playing) .toast { bottom: calc(88px + var(--sab)); } }
.drop-veil { position: fixed; inset: 0; z-index: 900; display: grid; place-items: center; background: rgba(11, 13, 12, .82); opacity: 0; pointer-events: none; transition: opacity .15s; }
.drop-veil.show { opacity: 1; }
.drop-veil > div { padding: 40px 56px; border: 2px dashed var(--accent); border-radius: 22px; text-align: center; display: flex; flex-direction: column; gap: 6px; }
.drop-veil strong { font: 800 26px/1 var(--display); }
.drop-veil span { color: var(--muted); }

/* ---------------- play stage ---------------- */
.play { position: fixed; inset: 0; z-index: 100; background: #000; overflow: hidden; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#game-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: #000; }
.play-ctl { position: absolute; inset: 0; pointer-events: none; }
.play-ctl > * { pointer-events: auto; }
.play:not(.touch) .play-ctl { display: none; }
.play-veil { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: var(--bg); transition: opacity .35s; text-align: center; padding: 20px; }
.play-veil.gone { opacity: 0; pointer-events: none; }
.play-veil strong { font: 800 22px/1.1 var(--display); }
.play-veil span { color: var(--muted); font-size: 14px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; margin-bottom: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.play-fab { position: absolute; z-index: 6; top: calc(8px + var(--sat)); right: calc(8px + var(--sar)); width: 36px; height: 36px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .2); background: rgba(12, 14, 13, .5); color: #fff; display: grid; place-items: center; opacity: .45; transition: opacity .15s; }
.play-fab:hover { opacity: 1; }
.play-fab svg { width: 18px; height: 18px; }

.kbd { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; font-size: 16px; pointer-events: none; display: none; caret-color: transparent; }
.kbd-bar { position: absolute; z-index: 8; left: 50%; top: calc(8px + var(--sat)); transform: translateX(-50%); display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: rgba(12, 14, 13, .82); border: 1px solid rgba(255, 255, 255, .16); }
.kbd-bar button { min-width: 44px; height: 38px; padding: 0 10px; border-radius: 8px; border: 0; background: rgba(255, 255, 255, .08); color: #fff; font: 500 14px/1 var(--body); }
.kbd-bar button.primary { background: var(--accent); color: var(--accent-ink); }

.rotate { position: absolute; inset: 0; z-index: 7; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; background: rgba(11, 13, 12, .96); padding: 24px; }
.rotate svg { width: 64px; height: 64px; color: var(--accent); margin-bottom: 6px; animation: tilt 2.4s var(--ease) infinite; }
.rotate-acts { display: flex; gap: 8px; }
.rotate strong { font: 800 22px/1.15 var(--display); }
.rotate span { color: var(--muted); margin-bottom: 8px; }
@keyframes tilt { 0%, 25% { transform: rotate(0); } 55%, 85% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
@media (orientation: portrait) and (max-width: 820px) {
  .play.touch:not(.portrait-ok) .rotate, .editor:not(.portrait-ok) .rotate { display: flex; }
}

/* mock scene for the standalone editor */
.mock { position: absolute; inset: 0; }
.mock-sky { position: absolute; inset: 0 0 42% 0; background: linear-gradient(#7fb0ff, #b9d6ff); }
.mock-ground { position: absolute; inset: 58% 0 0 0; background:
  linear-gradient(#5d9a3c 0 14%, #7a5534 14%), #7a5534; }
.mock-ground::before { content: ''; position: absolute; inset: 0; background-image: linear-gradient(90deg, rgba(0,0,0,.12) 1px, transparent 1px), linear-gradient(rgba(0,0,0,.12) 1px, transparent 1px); background-size: 48px 48px; }
.mock-cross { position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; transform: translate(-50%, -50%); }
.mock-cross::before, .mock-cross::after { content: ''; position: absolute; background: rgba(255, 255, 255, .85); }
.mock-cross::before { left: 8px; top: 0; width: 2px; height: 18px; }
.mock-cross::after { top: 8px; left: 0; height: 2px; width: 18px; }
.mock-hotbar { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); display: flex; background: rgba(0, 0, 0, .45); border: 2px solid rgba(0, 0, 0, .6); }
.mock-hotbar i { width: min(9vmin, 44px); height: min(9vmin, 44px); border: 2px solid rgba(160, 160, 160, .5); }
.mock-hotbar i.on { border-color: #fff; }

/* =====================================================================
 *                         TOUCH CONTROLS OVERLAY
 * ===================================================================== */
.ctl-layer { position: absolute; inset: 0; z-index: 3; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.ctl-area {
  position: absolute;
  top: var(--sat); bottom: var(--sab); left: var(--sal); right: var(--sar);
}
.ctl-grid { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .2s;
  background-image: linear-gradient(90deg, rgba(255,255,255,.07) 1px, transparent 1px), linear-gradient(rgba(255,255,255,.07) 1px, transparent 1px);
  background-size: 2.5% 2.5%; background-position: var(--sal) var(--sat); }
.ctl-grid.show { opacity: 1; }
.ctl-layer.editing { background: rgba(0, 0, 0, .28); }

.ctl { position: absolute; transition: opacity .15s; }
.ctl.hidden { opacity: 0 !important; pointer-events: none; visibility: hidden; }

.ctl-btn .btn-face {
  position: absolute; inset: 0; border-radius: 28%; display: grid; place-items: center;
  background: rgba(12, 14, 13, .42); border: 1.5px solid rgba(255, 255, 255, .28); color: rgba(255, 255, 255, .92);
  transition: transform .06s, background .08s, border-color .08s;
}
.ctl-btn svg { width: 46%; height: 46%; }
.btn-label { font: 600 var(--fs, 14px)/1 var(--mono); letter-spacing: -.02em; }
.ctl-btn.active .btn-face { background: rgba(243, 179, 61, .78); border-color: var(--accent); color: var(--accent-ink); transform: scale(.94); }
.ctl-btn.on .btn-face { background: rgba(243, 179, 61, .32); border-color: var(--accent); color: #fff; }
.ctl-btn.on .btn-face::after { content: ''; position: absolute; top: 12%; right: 12%; width: 13%; height: 13%; border-radius: 50%; background: var(--accent); }
.ctl-btn.is-menu .btn-face { border-radius: 30%; background: rgba(12, 14, 13, .35); }
.ctl-btn.is-menu svg { width: 52%; height: 52%; }

.ctl-joy .joy-zone { position: absolute; inset: 0; border-radius: 50%; }
.play:not(.editor) .ctl-joy.floating .joy-zone { inset: -28%; border-radius: 30%; }
.ctl-joy .joy-base, .ctl-joy .joy-knob { will-change: transform; }
.ctl-joy.active .joy-knob { transition: none; }
.ctl-joy .joy-base { position: absolute; left: 19%; top: 19%; width: 62%; height: 62%; border-radius: 50%; transition: transform .12s var(--ease); }
.ctl-joy.active .joy-base { transition: none; }
.ctl-joy .joy-ring { position: absolute; inset: 0; border-radius: 50%; background: rgba(12, 14, 13, .34); border: 1.5px solid rgba(255, 255, 255, .26); }
.ctl-joy .joy-knob { position: absolute; left: 28%; top: 28%; width: 44%; height: 44%; border-radius: 50%; background: rgba(255, 255, 255, .5); border: 1.5px solid rgba(255, 255, 255, .7); box-shadow: 0 2px 10px rgba(0, 0, 0, .3); transition: transform .12s var(--ease); }
.ctl-joy.active .joy-knob { transition: none; background: rgba(255, 255, 255, .7); }
.ctl-joy.sprint .joy-ring { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(243, 179, 61, .3); }
.ctl-joy.sprint .joy-knob { background: var(--accent); border-color: var(--accent-2); }

.ctl-dpad .dp { position: absolute; width: 33.4%; height: 33.4%; display: grid; place-items: center; background: rgba(12, 14, 13, .42); border: 1.5px solid rgba(255, 255, 255, .28); color: rgba(255, 255, 255, .85); }
.ctl-dpad .dp svg { width: 55%; height: 55%; }
.ctl-dpad .dp-u { left: 33.3%; top: 0; border-radius: 22% 22% 0 0; border-bottom: 0; }
.ctl-dpad .dp-d { left: 33.3%; bottom: 0; border-radius: 0 0 22% 22%; border-top: 0; }
.ctl-dpad .dp-d svg { transform: rotate(180deg); }
.ctl-dpad .dp-l { left: 0; top: 33.3%; border-radius: 22% 0 0 22%; border-right: 0; }
.ctl-dpad .dp-l svg { transform: rotate(-90deg); }
.ctl-dpad .dp-r { right: 0; top: 33.3%; border-radius: 0 22% 22% 0; border-left: 0; }
.ctl-dpad .dp-r svg { transform: rotate(90deg); }
.ctl-dpad .dp-c { position: absolute; left: 33.3%; top: 33.3%; width: 33.4%; height: 33.4%; background: rgba(12, 14, 13, .42); }
.ctl-dpad.u .dp-u, .ctl-dpad.d .dp-d, .ctl-dpad.l .dp-l, .ctl-dpad.r .dp-r { background: rgba(243, 179, 61, .78); color: var(--accent-ink); }

.ctl-hotbar { display: flex; }
.ctl-hotbar .hb-slot { flex: 1; height: 100%; border-radius: 2px; transition: background .1s; }
.ctl-hotbar .hb-slot.active { background: rgba(255, 255, 255, .28); }
.editing .ctl-hotbar, .ctl-layer[data-ctx] .ctl-hotbar.sel { background: rgba(255, 255, 255, .06); outline: 1.5px dashed rgba(255, 255, 255, .45); }
.editing .ctl-hotbar .hb-slot + .hb-slot { border-left: 1px dashed rgba(255, 255, 255, .25); }

.touch-ring { position: absolute; z-index: 4; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; pointer-events: none; border: 2px solid rgba(255, 255, 255, .8); animation: ring .4s ease-out forwards; }
.touch-ring.hold { border-color: var(--accent); }
@keyframes ring { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.3); opacity: 0; } }

/* ---------------- editor ---------------- */
.editing .ctl { cursor: grab; }
.editing .ctl::after { content: ''; position: absolute; inset: -4px; border-radius: 30%; border: 1.5px dashed transparent; pointer-events: none; }
.editing .ctl-joy::after, .editing .ctl-dpad::after { border-radius: 50%; }
.editing .ctl.sel::after { border-color: var(--accent); }
.editing .ctl.sel { z-index: 2; }
.ed-handle { position: absolute; z-index: 3; width: 34px; height: 34px; margin: -8px 0 0 -8px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: 0 3px 12px rgba(0, 0, 0, .4); cursor: nwse-resize; touch-action: none; }
.ed-handle svg { width: 18px; height: 18px; }

.ed-toolbar {
  position: absolute; z-index: 6; left: 50%; top: calc(8px + var(--sat)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; padding: 5px; border-radius: 14px;
  background: rgba(14, 17, 15, .94); border: 1px solid var(--line-2); box-shadow: 0 8px 28px rgba(0, 0, 0, .45);
  font-family: var(--body); max-width: calc(100% - 16px - var(--sal) - var(--sar));
}
.ed-btn { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px; border-radius: 10px; border: 0; background: none; color: var(--text); font: 500 14px/1 var(--body); white-space: nowrap; }
.ed-btn svg { width: 18px; height: 18px; }
.ed-btn:hover { background: var(--surface-3); }
.ed-btn.on { color: var(--accent); }
.ed-btn.ghost { color: var(--muted); }
.ed-btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.ed-sep { width: 1px; height: 22px; background: var(--line-2); margin: 0 4px; }
@media (max-width: 560px), (max-height: 440px) { .ed-btn:not(.primary):not(.ghost) span { display: none; } .ed-btn { padding: 0 10px; } }

.ed-toolbar.at-mid { top: 50%; transform: translate(-50%, -50%); }
.ed-toolbar.at-bot { top: auto; bottom: calc(8px + var(--sab)); }
.ed-move { color: var(--muted); padding: 0 8px !important; }
.ed-hint.fade { opacity: 0; transition: opacity .6s; }
.ed-hint.below-mid { top: calc(50% + 34px); }
.ed-hint { position: absolute; z-index: 5; left: 50%; top: calc(62px + var(--sat)); transform: translateX(-50%); padding: 8px 14px; border-radius: 10px; background: rgba(14, 17, 15, .8); color: var(--muted); font: 400 13px/1.35 var(--body); text-align: center; max-width: min(90%, 440px); pointer-events: none; }

.ed-panel {
  position: absolute; z-index: 7; top: calc(60px + var(--sat)); right: calc(8px + var(--sar)); bottom: calc(8px + var(--sab));
  width: min(300px, 46vw); overflow-y: auto; padding: 12px 14px 14px; border-radius: 16px;
  background: rgba(14, 17, 15, .96); border: 1px solid var(--line-2); box-shadow: 0 10px 34px rgba(0, 0, 0, .5);
  font: 400 14px/1.4 var(--body); color: var(--text); display: none; overscroll-behavior: contain; touch-action: pan-y;
}
.ed-panel.open { display: block; }
.ed-panel.left { right: auto; left: calc(8px + var(--sal)); }
.ed-panel-head, .ed-sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.ed-panel-head strong, .ed-sheet-head strong { font: 700 17px/1.2 var(--display); }
.icon-x { width: 34px; height: 34px; border: 0; background: none; border-radius: 9px; color: var(--muted); display: grid; place-items: center; margin-right: -6px; }
.icon-x:hover { background: var(--surface-3); color: var(--text); }
.icon-x svg { width: 18px; height: 18px; }
.f-row { display: grid; grid-template-columns: 62px 1fr 42px; align-items: center; gap: 8px; padding: 6px 0; }
.f-row > span { color: var(--muted); }
.f-row output { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.f-col { display: flex; flex-direction: column; gap: 6px; padding: 7px 0; }
.f-col > span { color: var(--muted); }
.f-col em { font-style: normal; color: var(--faint); }
.f-col select, .f-col input[type=text] { width: 100%; height: 38px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--bg); color: var(--text); font-size: 15px; }
.f-col .seg { display: flex; }
.f-col .seg button { padding: 0 6px; font-size: 13px; }
.f-check { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; color: var(--text); }
.f-check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 1px 0 0; flex: none; }
.ed-actions { display: flex; gap: 8px; margin-top: 10px; }
.btn-sm { flex: 1; height: 38px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface-2); color: var(--text); font: 500 14px/1 var(--body); }
.btn-sm.danger { color: #ff8a80; border-color: rgba(239, 90, 79, .4); background: transparent; }
.muted { color: var(--muted); }

.ed-sheet {
  position: absolute; z-index: 8; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px - var(--sat) - var(--sab)); overflow-y: auto;
  padding: 14px 16px 16px; border-radius: 18px; background: rgba(14, 17, 15, .98); border: 1px solid var(--line-2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6); font: 400 14px/1.4 var(--body); color: var(--text); overscroll-behavior: contain; touch-action: pan-y;
}
.ed-sheet.small { width: min(380px, calc(100% - 24px)); }
.pal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.pal-item { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font: 500 12.5px/1.2 var(--body); text-align: center; }
.pal-item svg { width: 24px; height: 24px; }
.pal-item:hover { border-color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
