:root {
  color-scheme: dark;
  --ink: #f7f3ff;
  --muted: #aaa8c3;
  --panel: rgba(12, 14, 34, .82);
  --panel-solid: #11142d;
  --line: rgba(255, 255, 255, .11);
  --violet: #a974ff;
  --cyan: #59ddff;
  --gold: #ffd77a;
  --good: #72efc5;
  --danger: #ff6b84;
  --nav-height: 76px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #070918; }
body { color: var(--ink); font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif; }
[hidden] { display: none !important; }
button { color: inherit; font: inherit; }
button, img { user-select: none; -webkit-user-drag: none; }
.app { position: relative; width: 100%; height: 100svh; min-height: 540px; overflow: hidden; background: radial-gradient(circle at 50% 0, #27205d 0, #0b0d22 45%, #070918 100%); }
.glass { background: linear-gradient(145deg, rgba(24, 27, 59, .88), rgba(8, 10, 26, .78)); border: 1px solid var(--line); box-shadow: 0 12px 34px rgba(0, 0, 0, .28), inset 0 1px rgba(255,255,255,.08); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.eyebrow { color: #c7b1ff; font-size: 10px; font-weight: 900; letter-spacing: .16em; text-transform: uppercase; }

.ambient { position: absolute; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.particle { position: absolute; width: 3px; height: 3px; border-radius: 50%; background: var(--cyan); opacity: 0; box-shadow: 0 0 12px 3px rgba(89,221,255,.55); animation: drift var(--duration) linear var(--delay) infinite; }
@keyframes drift { 0% { opacity: 0; transform: translate3d(0, 25px, 0) scale(.4); } 20% { opacity: .75; } 100% { opacity: 0; transform: translate3d(var(--travel), -65vh, 0) scale(1.3); } }

.hud { position: absolute; z-index: 50; top: calc(var(--safe-top) + 10px); left: 10px; right: 10px; height: 58px; display: flex; align-items: center; gap: 9px; padding: 8px 9px; border-radius: 18px; }
.brand-mark { flex: 0 0 40px; height: 40px; display: grid; place-items: center; border-radius: 13px; color: #fff; font-size: 21px; background: radial-gradient(circle at 30% 25%, #e2c5ff, #8a51e8 48%, #312369); box-shadow: 0 0 20px rgba(169,116,255,.42); }
.player-block { display: flex; min-width: 0; flex: 1; flex-direction: column; gap: 2px; }
.player-block strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.hud-resource { display: flex; align-items: center; gap: 3px; padding: 6px 7px; border-radius: 11px; background: rgba(255,255,255,.06); font-size: 12px; }
.icon-button { width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%; background: rgba(255,255,255,.06); font-size: 20px; cursor: pointer; }
.icon-button.is-spinning { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main, .view { position: absolute; inset: 0; }
.view { display: none; }
.view.active { display: block; animation: reveal .26s ease-out both; }
@keyframes reveal { from { opacity: 0; transform: scale(.985); } }
.map-viewport { position: absolute; inset: 0 0 calc(var(--nav-height) + var(--safe-bottom)); overflow: hidden; touch-action: none; cursor: grab; }
.map-viewport.dragging { cursor: grabbing; }
.map-stage { position: absolute; width: 1200px; height: 800px; transform-origin: 0 0; background: #151736 url("/web/assets/etheria_world_map.webp") center/cover no-repeat; will-change: transform; }
.map-vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, transparent 50%, rgba(4,5,15,.25) 75%, rgba(4,5,15,.76) 100%); }
.map-markers { position: absolute; inset: 0; }
.map-marker { position: absolute; width: 52px; height: 52px; margin: -26px; padding: 0; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.35); border-radius: 18px; background: linear-gradient(145deg, rgba(33,37,79,.94), rgba(11,13,35,.92)); box-shadow: 0 8px 20px rgba(0,0,0,.45), inset 0 1px rgba(255,255,255,.22); transform: translateZ(0); cursor: pointer; animation: markerFloat 3.6s ease-in-out infinite; }
.map-marker::after { content: ""; position: absolute; inset: -7px; border: 1px solid rgba(124,220,255,.25); border-radius: 23px; }
.map-marker .marker-emoji { font-size: 24px; filter: drop-shadow(0 3px 4px rgba(0,0,0,.5)); }
.map-marker .marker-label { position: absolute; top: 58px; left: 50%; min-width: max-content; max-width: 150px; padding: 5px 8px; border: 1px solid rgba(255,255,255,.13); border-radius: 9px; background: rgba(7,9,24,.86); box-shadow: 0 5px 12px rgba(0,0,0,.32); transform: translateX(-50%); font-size: 11px; font-weight: 850; text-align: center; text-shadow: 0 1px 2px #000; }
.map-marker.current { background: linear-gradient(145deg, #8254dc, #372269); border-color: #e6d5ff; box-shadow: 0 0 0 5px rgba(169,116,255,.2), 0 0 28px rgba(169,116,255,.75); }
.map-marker.current::after { border-color: rgba(217,191,255,.9); animation: pulse 1.8s ease-out infinite; }
.map-marker.event-active { background: linear-gradient(145deg, #ab355c, #46152f); box-shadow: 0 0 28px rgba(255,72,126,.55); }
.map-marker.sky { animation-duration: 4.4s; }
.map-marker.locked { filter: grayscale(.65); opacity: .62; }
.map-marker.locked .marker-emoji::after { content: "🔒"; }
@keyframes markerFloat { 50% { transform: translateY(-7px); } }
@keyframes pulse { 0% { transform: scale(.75); opacity: 1; } 100% { transform: scale(1.45); opacity: 0; } }
.map-title { position: absolute; z-index: 5; left: 12px; top: calc(var(--safe-top) + 80px); display: flex; flex-direction: column; gap: 2px; padding: 10px 13px; border-radius: 15px; pointer-events: none; }
.map-title strong { font-family: Georgia, serif; font-size: 19px; }
.map-title small { max-width: 210px; overflow: hidden; color: #d7d3e8; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.map-tools { position: absolute; z-index: 5; top: calc(var(--safe-top) + 80px); right: 12px; display: flex; padding: 3px; border-radius: 14px; }
.map-tools button { width: 34px; height: 34px; padding: 0; border: 0; border-radius: 10px; background: transparent; font-size: 18px; cursor: pointer; }
.map-tools button:active { background: rgba(255,255,255,.1); }

.panel-view { padding: calc(var(--safe-top) + 80px) 0 calc(var(--nav-height) + var(--safe-bottom)); background: radial-gradient(circle at 80% -5%, rgba(127,76,219,.3), transparent 40%), #090b1d; }
.panel-scroll { height: 100%; padding: 10px 14px 30px; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
.section-heading { margin: 2px 2px 20px; }
.section-heading h1 { margin: 3px 0 5px; font-family: Georgia, serif; font-size: 29px; }
.section-heading p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.feature-card { position: relative; height: 255px; overflow: hidden; border: 1px solid var(--line); border-radius: 25px; box-shadow: 0 18px 40px rgba(0,0,0,.3); }
.feature-card img { width: 100%; height: 100%; object-fit: cover; }
.feature-shade { position: absolute; inset: 0; background: linear-gradient(0deg, rgba(5,7,21,.96) 0, rgba(5,7,21,.15) 72%); }
.feature-copy { position: absolute; left: 18px; right: 18px; bottom: 17px; }
.feature-copy h2 { margin: 4px 0 4px; font-family: Georgia, serif; font-size: 25px; }
.feature-copy p { display: -webkit-box; margin: 0; overflow: hidden; color: #d6d3e3; font-size: 12px; line-height: 1.35; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.primary-action { width: 100%; min-height: 60px; margin: 12px 0; padding: 10px 18px; display: flex; align-items: center; justify-content: center; gap: 12px; border: 1px solid rgba(223,201,255,.42); border-radius: 18px; background: linear-gradient(135deg, #8c55df, #5639b9); box-shadow: 0 12px 28px rgba(92,54,191,.38), inset 0 1px rgba(255,255,255,.28); font-weight: 800; cursor: pointer; }
.primary-action > span:first-child { font-size: 25px; }
.primary-action > span:last-child { display: flex; flex-direction: column; align-items: flex-start; }
.primary-action small { color: #e3d9f7; font-size: 10px; font-weight: 600; }
.primary-action:disabled { opacity: .5; filter: grayscale(.5); }
.primary-action.compact { min-height: 48px; margin: 15px 0 0; }
.section-label { margin: 22px 2px 9px; color: #aaa5c0; font-size: 10px; font-weight: 900; letter-spacing: .13em; }
.mini-team { display: flex; gap: 9px; }
.mini-creature { min-width: 0; flex: 1; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.055); }
.mini-creature img { width: 100%; height: 76px; object-fit: cover; }
.mini-creature div { padding: 7px; }
.mini-creature strong { display: block; overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.mini-creature small { color: var(--muted); font-size: 9px; }

.creature-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.creature-card { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 20px; background: #151832; box-shadow: 0 10px 24px rgba(0,0,0,.22); cursor: pointer; }
.creature-card img { width: 100%; aspect-ratio: 1.16; object-fit: cover; }
.creature-card .slot { position: absolute; top: 8px; left: 8px; padding: 4px 7px; border-radius: 9px; background: rgba(9,10,27,.82); font-size: 9px; font-weight: 900; }
.creature-card.active-card { border-color: rgba(186,139,255,.72); box-shadow: 0 0 22px rgba(157,92,255,.28); }
.creature-copy { padding: 9px 10px 11px; }
.creature-copy strong { display: block; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.creature-copy small { color: var(--muted); font-size: 10px; }
.micro-hp { height: 4px; margin-top: 7px; overflow: hidden; border-radius: 4px; background: rgba(255,255,255,.1); }
.micro-hp span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #48d8b1, #75f3c6); }

.quest-list { display: flex; flex-direction: column; gap: 12px; }
.quest-card { position: relative; overflow: hidden; padding: 18px; border: 1px solid var(--line); border-radius: 21px; background: linear-gradient(145deg, rgba(31,34,72,.94), rgba(15,17,40,.94)); }
.quest-card.world { background: linear-gradient(145deg, rgba(72,29,73,.96), rgba(21,18,49,.95)); }
.quest-card::before { content: ""; position: absolute; width: 140px; height: 140px; top: -80px; right: -35px; border-radius: 50%; background: var(--glow, rgba(125,87,226,.32)); filter: blur(20px); }
.quest-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.quest-top span:last-child { font-size: 12px; font-weight: 800; }
.quest-card h2 { position: relative; margin: 8px 0 5px; font-family: Georgia, serif; font-size: 20px; }
.quest-card p { position: relative; margin: 0 0 14px; color: #c3bfd2; font-size: 12px; }
.progress-track { height: 8px; overflow: hidden; border-radius: 8px; background: rgba(255,255,255,.09); }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--violet), var(--cyan)); box-shadow: 0 0 13px rgba(89,221,255,.45); transition: width .6s ease; }
.claim-button { width: 100%; margin-top: 13px; padding: 11px; border: 1px solid rgba(255,255,255,.14); border-radius: 13px; background: rgba(255,255,255,.08); font-weight: 800; }

.profile-hero { position: relative; min-height: 180px; padding: 30px 20px 20px; overflow: hidden; border-radius: 25px; text-align: center; }
.profile-rune { width: 70px; height: 70px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: 24px; background: radial-gradient(circle at 35% 25%, #dfc5ff, #7648ca 52%, #2b1e66); box-shadow: 0 0 34px rgba(161,98,255,.5); font-size: 32px; }
.profile-hero h1 { margin: 5px 0; font-family: Georgia, serif; font-size: 27px; }
.profile-hero p { margin: 0; color: var(--muted); font-size: 12px; }
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.stat-card, .info-card { padding: 15px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,255,255,.05); }
.stat-card span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; }
.stat-card strong { font-size: 18px; }
.info-card { margin-top: 12px; color: #d9d5e7; font-size: 12px; line-height: 1.6; }
.info-card strong { color: #fff; }
.version-line { padding: 24px; color: #65627d; font-size: 10px; font-weight: 800; letter-spacing: .12em; text-align: center; }

.bottom-nav { position: absolute; z-index: 60; left: 8px; right: 8px; bottom: calc(var(--safe-bottom) + 7px); height: 68px; padding: 5px 3px; display: flex; border-radius: 22px; }
.nav-item { flex: 1; min-width: 0; padding: 5px 2px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 3px; border: 0; border-radius: 16px; background: transparent; color: #8f8ca8; cursor: pointer; }
.nav-item span { font-size: 20px; filter: grayscale(.8); transition: transform .2s ease, filter .2s ease; }
.nav-item small { font-size: 9px; font-weight: 760; }
.nav-item.active { color: #fff; background: linear-gradient(145deg, rgba(150,91,236,.3), rgba(75,56,160,.24)); }
.nav-item.active span { filter: none; transform: translateY(-2px) scale(1.1); }

.sheet-backdrop { position: absolute; z-index: 70; inset: 0; background: rgba(3,4,13,.62); opacity: 0; transition: opacity .25s; }
.sheet-backdrop.visible { opacity: 1; }
.bottom-sheet { position: absolute; z-index: 80; left: 8px; right: 8px; bottom: calc(var(--safe-bottom) + 7px); max-height: min(76vh, 630px); overflow: hidden; border: 1px solid var(--line); border-radius: 28px; background: #11142d; box-shadow: 0 -25px 70px rgba(0,0,0,.58); transform: translateY(calc(100% + 20px)); transition: transform .32s cubic-bezier(.2,.85,.25,1); }
.bottom-sheet.open { transform: translateY(0); }
.sheet-handle { position: absolute; z-index: 3; top: 7px; left: 50%; width: 42px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.48); transform: translateX(-50%); }
.sheet-picture { position: relative; height: 210px; }
.sheet-picture img { width: 100%; height: 100%; object-fit: cover; }
.sheet-picture-shade { position: absolute; inset: 0; background: linear-gradient(0deg, #11142d, transparent 70%); }
.sheet-close { position: absolute; top: 15px; right: 15px; width: 36px; height: 36px; padding: 0; border: 1px solid rgba(255,255,255,.2); border-radius: 50%; background: rgba(7,9,22,.68); font-size: 24px; }
.sheet-body { max-height: calc(76vh - 200px); padding: 0 19px 20px; overflow-y: auto; }
.sheet-body h2 { margin: 5px 0; font-family: Georgia, serif; font-size: 26px; }
.sheet-body p { color: #c0bdce; font-size: 13px; line-height: 1.45; }
.sheet-subtitle { margin: 0 0 8px !important; color: var(--gold) !important; font-weight: 800; }

.battle-overlay { position: absolute; z-index: 100; inset: 0; display: none; overflow: hidden; background: radial-gradient(circle at 50% 40%, #302769 0, #10152f 46%, #070918 100%); }
.battle-overlay.active { display: block; animation: battleIn .4s ease-out both; }
@keyframes battleIn { from { opacity: 0; transform: scale(1.08); } }
.battle-sky { position: absolute; inset: 0; opacity: .25; background: url("/web/assets/etheria_world_map.webp") center/cover; filter: blur(7px) saturate(1.3); transform: scale(1.08); }
.battle-sky::after { content: ""; position: absolute; inset: 0; background: linear-gradient(rgba(8,10,27,.35), rgba(8,10,27,.95)); }
.battle-header { position: absolute; z-index: 2; top: calc(var(--safe-top) + 18px); left: 18px; right: 18px; display: flex; justify-content: space-between; }
.battle-header strong { font-size: 12px; }
.fighter { position: absolute; z-index: 2; left: 15px; right: 15px; display: flex; align-items: center; gap: 12px; }
.fighter.enemy { top: calc(var(--safe-top) + 55px); justify-content: flex-end; }
.fighter.ally { top: 47%; }
.fighter img { width: min(42vw, 190px); aspect-ratio: 1; object-fit: cover; border: 2px solid rgba(255,255,255,.2); border-radius: 50%; box-shadow: 0 0 35px rgba(115,83,215,.4); }
.fighter.enemy img { order: 2; }
.fighter-info { width: min(47vw, 210px); }
.fighter.enemy .fighter-info { text-align: right; }
.fighter-info > span { color: #beb9d1; font-size: 10px; }
.fighter-info h2 { margin: 3px 0 7px; font-family: Georgia, serif; font-size: 19px; }
.hp-track { height: 7px; overflow: hidden; border-radius: 7px; background: rgba(255,255,255,.13); }
.hp-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #43cfa9, #8bf0c5); transition: width .45s ease; }
.fighter-info small { color: #c2bfd0; font-size: 9px; }
.battle-flare { position: absolute; z-index: 3; top: 41%; left: 50%; color: #fff; font-size: 28px; filter: drop-shadow(0 0 16px #7bdfff); transform: translate(-50%, -50%); animation: flare 1.4s ease-in-out infinite; }
@keyframes flare { 50% { transform: translate(-50%,-50%) scale(1.2); opacity: .65; } }
.battle-log { position: absolute; z-index: 4; left: 13px; right: 13px; bottom: calc(var(--safe-bottom) + 100px); min-height: 55px; padding: 10px 13px; border-radius: 15px; color: #d9d5e7; font-size: 11px; line-height: 1.35; }
.battle-actions { position: absolute; z-index: 4; left: 8px; right: 8px; bottom: calc(var(--safe-bottom) + 7px); height: 84px; padding: 6px; display: flex; border-radius: 22px; }
.battle-actions button { flex: 1; padding: 5px 2px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 2px; border: 0; border-radius: 16px; background: transparent; }
.battle-actions button:active { background: rgba(255,255,255,.1); }
.battle-actions button span { font-size: 22px; }
.battle-actions button strong { font-size: 10px; }

.toast { position: absolute; z-index: 200; left: 20px; right: 20px; bottom: calc(var(--safe-bottom) + 94px); padding: 12px 15px; border: 1px solid rgba(255,255,255,.14); border-radius: 15px; background: rgba(18,21,48,.96); box-shadow: 0 15px 35px rgba(0,0,0,.38); color: #f2effc; font-size: 12px; line-height: 1.35; opacity: 0; pointer-events: none; transform: translateY(15px); transition: .25s; }
.toast.visible { opacity: 1; transform: translateY(0); }
.loading-screen, .error-screen { position: absolute; z-index: 300; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; background: radial-gradient(circle at 50% 35%, #342870, #090b1d 58%); }
.loading-screen { transition: opacity .5s, visibility .5s; }
.app:not(.is-loading) .loading-screen { opacity: 0; visibility: hidden; }
.loading-rune { width: 86px; height: 86px; margin-bottom: 20px; display: grid; place-items: center; border: 1px solid rgba(218,194,255,.45); border-radius: 29px; background: linear-gradient(145deg, #9360df, #332270); box-shadow: 0 0 55px rgba(147,96,223,.55); font-size: 38px; animation: rune 2s ease-in-out infinite; }
@keyframes rune { 50% { transform: translateY(-8px) rotate(7deg); box-shadow: 0 0 75px rgba(89,221,255,.58); } }
.loading-screen strong { font-family: Georgia, serif; font-size: 19px; letter-spacing: .08em; }
.loading-screen span { margin-top: 7px; color: var(--muted); font-size: 11px; }
.error-screen { z-index: 310; padding: 30px; text-align: center; }
.error-screen > div { font-size: 58px; }
.error-screen h1 { margin-bottom: 7px; font-family: Georgia, serif; font-size: 25px; }
.error-screen p { max-width: 330px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.error-screen button { padding: 12px 20px; border: 1px solid rgba(255,255,255,.2); border-radius: 14px; background: #7044bf; font-weight: 800; }

@media (min-width: 700px) {
  .hud { width: min(660px, calc(100% - 28px)); left: 50%; transform: translateX(-50%); }
  .bottom-nav { width: min(560px, calc(100% - 24px)); left: 50%; transform: translateX(-50%); }
  .panel-scroll { width: min(620px, 100%); margin: auto; }
  .bottom-sheet { width: min(520px, calc(100% - 16px)); left: 50%; right: auto; transform: translate(-50%, calc(100% + 20px)); }
  .bottom-sheet.open { transform: translate(-50%, 0); }
}

@media (max-height: 650px) {
  .feature-card { height: 190px; }
  .fighter img { width: min(34vw, 145px); }
  .fighter.ally { top: 44%; }
  .battle-log { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .ambient { display: none; }
}
