:root {
  --ink: #1a1f2c;
  --paper: #f5ecd9;
  --gold: #e8a23a;
  --teal: #1f5f6a;
  --shadow: rgba(0,0,0,0.45);
  --panel: rgba(15, 22, 30, 0.85);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: #0b1014; overflow: hidden; font-family: ui-rounded, "Hiragino Maru Gothic ProN", "Comic Sans MS", system-ui, sans-serif; color: var(--paper); -webkit-font-smoothing: antialiased; }

#game { display: block; width: 100vw; height: 100vh; image-rendering: -webkit-optimize-contrast; cursor: default; }

/* ---------- Loader ---------- */
#loader { position: fixed; inset: 0; background: radial-gradient(ellipse at center, #14202a 0%, #06090c 100%); z-index: 100; display: grid; place-items: center; transition: opacity .8s ease; }
#loader.gone { opacity: 0; pointer-events: none; }
.loader-inner { text-align: center; }
.loader-title { font-size: 64px; letter-spacing: 12px; color: var(--paper); text-shadow: 0 0 30px rgba(232,162,58,0.4); }
.loader-sub { font-size: 14px; letter-spacing: 4px; color: var(--gold); margin-top: 6px; opacity: .8; }
.loader-bar { width: 280px; height: 6px; background: rgba(255,255,255,0.08); border-radius: 6px; overflow: hidden; margin: 28px auto 12px; }
#loader-fill { width: 0%; height: 100%; background: linear-gradient(90deg, var(--gold), #ffd071); transition: width .25s ease; }
.loader-status { font-size: 12px; opacity: .6; letter-spacing: 2px; }

/* ---------- Mobile ---------- */
#mobile-fallback { position: fixed; inset: 0; background: #0e1620; z-index: 200; display: grid; place-items: center; padding: 24px; text-align: center; }
.mf-inner h1 { color: var(--gold); }
.mf-inner p { max-width: 360px; opacity: .8; }
.btn-primary { display: inline-block; margin-top: 18px; padding: 14px 22px; background: var(--gold); color: #1a1206; text-decoration: none; border-radius: 10px; font-weight: 700; }

/* ---------- HUD ---------- */
.hud-top-right { position: fixed; top: 16px; right: 16px; display: flex; gap: 8px; z-index: 20; }
.hud-btn { background: var(--panel); color: var(--paper); border: 1px solid rgba(232,162,58,0.3); padding: 9px 14px; border-radius: 999px; font: inherit; font-size: 13px; cursor: pointer; backdrop-filter: blur(6px); text-decoration: none; transition: transform .12s ease, background .2s; }
.hud-btn:hover { background: rgba(232,162,58,0.2); transform: translateY(-1px); }

.hud-top-left { position: fixed; top: 16px; left: 16px; background: var(--panel); padding: 10px 14px; border-radius: 12px; backdrop-filter: blur(6px); border-left: 3px solid var(--gold); z-index: 20; max-width: 260px; }
.hud-top-left strong { display: block; font-size: 16px; color: var(--gold); }
.hud-top-left span { display: block; font-size: 11px; opacity: .7; letter-spacing: 1px; margin-top: 2px; }
.hud-top-left em { display: block; font-size: 11px; opacity: .55; margin-top: 8px; font-style: normal; }

.hud-bottom-left { position: fixed; bottom: 16px; left: 16px; background: var(--panel); padding: 12px 16px; border-radius: 12px; backdrop-filter: blur(6px); z-index: 20; min-width: 220px; }
.quest-title { font-size: 11px; letter-spacing: 3px; opacity: .6; margin-bottom: 8px; }
#quest-list { list-style: none; padding: 0; margin: 0; font-size: 13px; }
#quest-list li { padding: 3px 0; opacity: .7; transition: opacity .3s, color .3s; }
#quest-list li.done { opacity: 1; color: var(--gold); text-decoration: line-through; text-decoration-color: rgba(232,162,58,0.5); }
#quest-list li::before { content: "□  "; opacity: .5; }
#quest-list li.done::before { content: "■  "; }

/* ---------- Prompt ---------- */
#prompt { position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%); background: var(--panel); padding: 12px 22px; border-radius: 999px; font-size: 14px; z-index: 25; backdrop-filter: blur(6px); border: 1px solid rgba(232,162,58,0.4); animation: bob 1.4s ease-in-out infinite; }
.kbd { display: inline-block; background: var(--gold); color: #1a1206; padding: 2px 8px; border-radius: 4px; font-weight: 700; margin-right: 4px; box-shadow: 0 2px 0 rgba(0,0,0,0.4); }
@keyframes bob { 0%,100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-3px); } }

/* ---------- Pokemon transition ---------- */
#transition { position: fixed; inset: 0; z-index: 60; background: white; pointer-events: none; clip-path: circle(0% at 50% 50%); }
#transition.in { animation: irisIn .55s ease forwards; }
#transition.out { animation: irisOut .55s ease forwards; }
@keyframes irisIn { from { clip-path: circle(0% at 50% 50%); } to { clip-path: circle(150% at 50% 50%); } }
@keyframes irisOut { from { clip-path: circle(150% at 50% 50%); } to { clip-path: circle(0% at 50% 50%); } }

/* ---------- Encounter / content overlay ---------- */
#encounter { position: fixed; inset: 0; background: rgba(8, 12, 18, 0.85); backdrop-filter: blur(10px); z-index: 70; display: grid; place-items: center; padding: 24px; }
#encounter[hidden] { display: none; }
.enc-frame { width: min(820px, 100%); background: var(--paper); color: var(--ink); border-radius: 16px; padding: 0; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,0.6); border: 4px solid var(--ink); position: relative; animation: pop .35s cubic-bezier(.2,.9,.3,1.4); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.enc-close { position: absolute; top: 10px; right: 12px; width: 38px; height: 38px; background: var(--gold); color: var(--ink); border: 2px solid var(--ink); border-radius: 50%; font-size: 22px; font-weight: 700; cursor: pointer; line-height: 1; display: grid; place-items: center; z-index: 5; box-shadow: 0 4px 0 rgba(0,0,0,0.3); }
.enc-close:hover { transform: translateY(-1px); box-shadow: 0 5px 0 rgba(0,0,0,0.4); }
.enc-banner { background: var(--ink); color: var(--gold); padding: 14px 22px; font-size: 14px; letter-spacing: 4px; text-transform: uppercase; }
.enc-body { padding: 28px 32px 36px; }
.enc-body h2 { margin: 0 0 6px; font-size: 28px; color: var(--teal); }
.enc-body .role { font-size: 12px; letter-spacing: 3px; text-transform: uppercase; color: #8a6a2a; margin-bottom: 18px; }
.enc-body p { line-height: 1.6; font-size: 15px; }
.enc-body .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-top: 18px; }
.enc-body .tile { background: rgba(31,95,106,0.08); border: 1px solid rgba(31,95,106,0.2); padding: 14px; border-radius: 10px; text-align: center; font-size: 13px; }
.enc-body .quote { border-left: 4px solid var(--gold); padding: 10px 16px; margin: 16px 0; font-style: italic; background: rgba(232,162,58,0.08); }
.enc-body .quote cite { display: block; margin-top: 8px; font-size: 12px; font-style: normal; opacity: .7; }
.enc-body a { color: var(--teal); }

/* ---------- Toast ---------- */
#toast { position: fixed; top: 80px; left: 50%; transform: translateX(-50%); background: var(--gold); color: #1a1206; padding: 14px 22px; border-radius: 10px; font-weight: 700; z-index: 80; box-shadow: 0 10px 30px rgba(0,0,0,0.4); animation: toastIn .4s ease, toastOut .4s ease 2.6s forwards; }
@keyframes toastIn { from { transform: translateX(-50%) translateY(-20px); opacity: 0; } to { transform: translateX(-50%) translateY(0); opacity: 1; } }
@keyframes toastOut { to { transform: translateX(-50%) translateY(-20px); opacity: 0; } }

@media (max-width: 768px) {
  body:not(.force-desktop) #game,
  body:not(.force-desktop) .hud-top-left,
  body:not(.force-desktop) .hud-bottom-left,
  body:not(.force-desktop) .hud-top-right { display: none; }
}
