:root { color-scheme: dark; --bg: #050d13; --panel: #0c1c29; --card: #182d3d; --line: #365367; --text: #e9f2fa; --muted: #b0c4d5; --mint: #a1e4c5; }
* { box-sizing: border-box; }
html { height: 100%; overflow: hidden; }
body { margin: 0; height: 100vh; height: 100dvh; overflow: hidden; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); display: grid; place-items: center; background: radial-gradient(ellipse at 50% 35%, #142a35 0%, var(--bg) 70%); color: var(--text); font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
a { color: var(--mint); }
.selection-shell { width: min(1200px, 100%); height: 100%; max-height: 900px; min-height: 0; overflow: hidden; background: var(--panel); border: 1px solid #1c3444; border-radius: 26px; box-shadow: 0 28px 90px #0008; }
.selection-layout { display: grid; grid-template-columns: minmax(260px, .8fr) minmax(0, 1.4fr); height: 100%; min-height: 0; margin: 0; overflow: hidden; }
.world-selection, .world-preview { min-width: 0; min-height: 0; padding: 28px; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-gutter: stable; scroll-padding: 16px; }
h1 { font-size: 25px; line-height: 1.2; letter-spacing: -.4px; margin: 0 0 22px; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.world-option { position: relative; cursor: pointer; display: block; }
.world-option input { position: absolute; left: 15px; top: 50%; opacity: 0; width: 1px; height: 1px; }
.world-card { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 16px; align-items: center; padding: 12px; border: 2px solid var(--line); border-radius: 14px; background: var(--card); min-height: 104px; transition: background .15s, border-color .15s; }
.world-card img { display: block; aspect-ratio: 16/10; width: 100%; height: auto; object-fit: cover; border-radius: 8px; }
.world-copy { display: grid; gap: 7px; }
.world-copy strong { font-size: 22px; line-height: 1.2; }
.world-option input:checked + .world-card { border-color: var(--mint); background: #183b38; }
.world-option input:focus-visible + .world-card { outline: 3px solid #fff0a0; outline-offset: 3px; }
.world-option:hover .world-card { border-color: #c1dbeb; }
.world-option input:disabled + .world-card { opacity: .65; cursor: wait; }
.world-preview { background: #112433; display: flex; flex-direction: column; container-type: inline-size; overflow: hidden; scrollbar-gutter: auto; gap: 12px; }
.world-gallery { position: relative; flex: 1 1 0; min-height: 0; overflow: hidden; border-radius: 16px; background: var(--card); }
.world-gallery:focus-visible { outline: 3px solid #fff0a0; outline-offset: 2px; }
#previewTitle { position: absolute; z-index: 1; inset: 0 0 auto; margin: 0; padding: 14px 18px; background: #0009; color: white; font-size: clamp(18px, 3.5cqi, 25px); line-height: 1.2; text-align: center; }
.preview-image { display: block; width: 100%; height: 100%; min-height: 0; object-fit: cover; }
.gallery-arrow, .gallery-count { position: absolute; z-index: 2; background: #0009; color: white; opacity: 0; transition: opacity .15s; }
.gallery-arrow { top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border: 1px solid #ffffff50; border-radius: 50%; font: 32px/1 system-ui; cursor: pointer; }
.gallery-previous { left: 12px; }
.gallery-next { right: 12px; }
.gallery-count { bottom: 12px; left: 50%; transform: translateX(-50%); border-radius: 20px; padding: 5px 12px; font-size: 12px; }
.world-gallery:hover .gallery-arrow, .world-gallery:focus-within .gallery-arrow, .world-gallery:hover .gallery-count, .world-gallery:focus-within .gallery-count { opacity: 1; }
.world-gallery .gallery-arrow:disabled { opacity: 0; }
.world-gallery:hover .gallery-arrow:disabled, .world-gallery:focus-within .gallery-arrow:disabled { opacity: .4; }
#previewDescription { flex: 0 0 auto; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.4; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.play-action { flex: 0 0 auto; min-width: 0; }
#playWorld { width: 100%; min-height: 66px; display: flex; align-items: center; justify-content: center; gap: 24px; padding: 16px 22px; border: 0; border-radius: 12px; background: var(--mint); color: #10332a; font: 750 23px/1.3 system-ui; cursor: pointer; }
#playWorld:hover { background: #b9f5d8; }
button:focus-visible, a:focus-visible { outline: 3px solid #fff0a0; outline-offset: 3px; }
button:disabled { cursor: default; opacity: .6; }
#playWorld:disabled { cursor: wait; }
#playStatus { font-size: 16px; line-height: 1.5; color: var(--muted); margin: 14px 0 0; }
#playStatus:empty, #characterStatus:empty { display: none; }
#playStatus[data-error=true] { color: #ffc1b5; }
.launch-setup { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: 20px; align-items: center; margin-bottom: 18px; }
.launch-fields { display: grid; min-width: 0; width: 100%; gap: 16px; }
.launch-fields label { display: grid; grid-template-columns: 88px minmax(0, 1fr); align-items: center; gap: 12px; font-size: 14px; font-weight: 600; color: var(--muted); min-width: 0; }
.launch-fields input { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); font: inherit; font-size: 16px; padding: 12px; min-height: 48px; }
.launch-fields input:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; }
.launch-avatar { position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; width: 120px; border: 1px solid var(--line); border-radius: 14px; background: radial-gradient(ellipse at 50% 70%, #24433f, var(--panel)); padding: 10px; font: inherit; cursor: pointer; }
.avatar-caption { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }
#launchAvatarPreview { display: grid; place-items: center; width: 100%; flex: 1; min-height: 100px; }
#launchAvatarPreview svg { display: block; width: 100%; max-width: 110px; height: 120px; }
.avatar-settings-overlay { position: absolute; inset: 0; display: grid; align-content: center; text-align: center; padding: 8px; background: #000a; color: #fff; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; }
.launch-avatar:hover .avatar-settings-overlay, .launch-avatar:focus-visible .avatar-settings-overlay { opacity: 1; }
#avatarSettings { width: min(440px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 22px; border: 1px solid var(--line); border-radius: 22px; background: var(--panel); color: var(--text); box-shadow: 0 24px 90px #0009; }
#avatarSettings::backdrop { background: #02080dc9; backdrop-filter: blur(5px); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.dialog-heading h2 { font-size: 26px; margin: 0; }
#closeSettings { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); font-size: 30px; cursor: pointer; }
#closeSettings:hover { background: #294457; }
.character-stage { height: 260px; min-height: 160px; background: radial-gradient(ellipse at 55% 35%, #284556, #182d3d 75%); border-radius: 20px; display: grid; place-items: center; }
.character { width: min(100%, 260px); height: auto; max-height: 52dvh; }
.character-colors legend { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
#landingColors { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 7px; }
#landingColors button, .animation-controls button { border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); cursor: pointer; min-height: 44px; font: inherit; font-size: 13px; padding: 8px 4px; }
#landingColors button { display: grid; justify-items: center; gap: 6px; font-size: 11px; }
#landingColors .swatch { width: 26px; height: 26px; border-radius: 50%; }
#landingColors button[aria-pressed=true], .animation-controls button[aria-pressed=true] { border-color: var(--mint); background: #183b38; }
.animation-controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 18px; }
#characterStatus { color: var(--muted); font-size: 13px; margin-bottom: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (max-width: 960px) {
  .world-selection, .world-preview { padding: 20px; }
  .world-card { grid-template-columns: 86px minmax(0, 1fr); gap: 12px; }
  .world-copy strong { font-size: 20px; }
}
@media (max-width: 700px) {
  body { padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .selection-shell { border-radius: 18px; }
  .selection-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 26fr) minmax(0, 74fr); }
  .world-selection, .world-preview { padding: 18px; }
  h1 { margin-bottom: 16px; }
  .world-card { min-height: 80px; padding: 9px; }
  #playWorld { font-size: 22px; min-height: 64px; }
}
@container (max-width: 480px) {
  .launch-setup { grid-template-columns: minmax(0, 1fr) 64px; gap: 10px; margin-bottom: 10px; }
  .launch-avatar { width: 64px; padding: 5px; }
  .avatar-caption { font-size: 10px; }
  #launchAvatarPreview { min-height: 50px; }
  #launchAvatarPreview svg { height: 64px; }
  .launch-fields { gap: 8px; }
  .launch-fields label { grid-template-columns: minmax(0, 1fr); gap: 3px; font-size: 11px; }
  .launch-fields input { padding: 7px; min-height: 34px; }
  #playWorld { min-height: 44px; padding: 10px; font-size: 17px; }
}
@media (max-height: 650px) {
  .world-selection, .world-preview { padding: 12px; }
  .world-preview { gap: 8px; }
  .launch-setup { margin-bottom: 8px; gap: 10px; }
  .launch-fields { gap: 6px; }
  .launch-fields input { min-height: 34px; padding: 6px 8px; }
  .launch-avatar { padding: 5px; }
  #launchAvatarPreview { min-height: 40px; }
  #launchAvatarPreview svg { height: 60px; }
  #playWorld { min-height: 40px; padding: 8px; font-size: 17px; }
  #previewTitle { padding: 8px 12px; }
  #playStatus { font-size: 12px; margin-top: 6px; }
}
@media (max-width: 400px) { #landingColors { grid-template-columns: repeat(3, 1fr); } }
@media (hover: none) {
  .world-gallery .gallery-arrow, .gallery-count { opacity: 1; }
  .world-gallery .gallery-arrow:disabled { opacity: .4; }
  .avatar-settings-overlay { inset: auto 0 0; opacity: 1; font-size: 11px; padding: 5px; }
  .launch-avatar { padding-bottom: 36px; }
}
@media (prefers-reduced-motion: reduce) { .world-card { transition: none; } }

.selection-heading { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:22px; }
.selection-heading h1 { margin:0; }
.selection-heading button { min-height:44px; padding:10px 14px; border:1px solid var(--line); border-radius:10px; background:var(--card); color:var(--text); font:inherit; cursor:pointer; }

.purchase-return { padding:12px; margin-bottom:12px; border:1px solid var(--mint); border-radius:10px; font-size:14px; }
.purchase-return[hidden], .purchase-return [hidden] { display:none; }
.purchase-return p { margin:0; }
.purchase-return button { margin-top:8px; min-height:44px; padding:8px 12px; border:1px solid var(--line); border-radius:8px; background:var(--card); color:var(--text); font:inherit; cursor:pointer; }
body:has(.purchase-return:not([hidden])) .world-preview { overflow-y:auto; }
