:root {
  color-scheme: dark;
  font-family: "Inter", "Microsoft YaHei", system-ui, sans-serif;
  color: #ecf2fc;
  background: #0c1524;
  --surface: #142136;
  --border: #30435e;
  --muted: #a9bdd7;
  --accent: #a8d3ff;
  --page-gutter: clamp(16px, 2.5vw, 42px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { display: flex; flex-direction: column; min-height: 100dvh; margin: 0; background: radial-gradient(ellipse at 54% 0%, #1c2e49 0, #0c1524 48rem); }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .48; cursor: default; }
:is(a, button, input, select):focus-visible { outline: 2px solid #9ecfff; outline-offset: 3px; }

.topbar { display: flex; align-items: center; gap: 24px; min-height: 58px; padding: 8px var(--page-gutter); background: #101b2c; border-bottom: 1px solid #263650; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; font-size: 19px; font-weight: 720; }
.logo { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid #456183; border-radius: 11px; color: #def0ff; background: #233954; }
.topbar nav { display: flex; gap: 4px; white-space: nowrap; }
.topbar nav a { padding: 8px 13px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.topbar nav a:hover, .topbar nav a[aria-current="page"] { background: #223651; color: #f4f8ff; }
.header-status { color: #f5cba0; font-size: 12px; }

.lobby-main { width: min(100% - var(--page-gutter) * 2, 1680px); margin: 0 auto; padding: clamp(18px, 2.8vw, 36px) 0 24px; }
.page-heading, .section-title { display: flex; gap: 16px; align-items: center; justify-content: space-between; margin: 0 0 17px; }
.page-heading h1, .section-title h1 { min-width: 0; margin: 0; font-size: clamp(25px, 3.7vw, 38px); font-weight: 730; line-height: 1.18; overflow-wrap: anywhere; }
.page-heading .secondary, .section-title .secondary { flex: none; }
.quiet { margin: 9px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: clamp(12px, 1.4vw, 20px); }
.project-card { display: block; overflow: hidden; border: 1px solid var(--border); border-radius: 15px; background: var(--surface); transition: border-color .16s, background-color .16s; }
.project-card:hover { border-color: #799ec9; background: #1a2b43; }
.project-cover { position: relative; isolation: isolate; overflow: hidden; aspect-ratio: 1.72; background: radial-gradient(circle at 35% 15%, #486d98, #1e304e 72%); }
.project-cover::before, .project-cover::after, .project-cover span { content: ""; position: absolute; }
.project-cover[data-scene="mushroom"] { background: #6caecb url("/mushroom-project-cover.png") left center / cover no-repeat; image-rendering: pixelated; }
.project-cover[data-scene="turns"] { background: radial-gradient(ellipse at 54% 30%, #526f9c, #293856 73%); }
.project-cover[data-scene="turns"]::before { height: 64%; aspect-ratio: 1; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-11deg); border-radius: 14%; background: repeating-linear-gradient(0deg, transparent 0 31%, #7494bf 31% 34%), repeating-linear-gradient(90deg, #c7d9ed 0 31%, #7494bf 31% 34%); box-shadow: 0 7px #284263, 0 16px 30px #14234099; }
.project-cover[data-scene="turns"]::after { content: "✦"; top: 49%; left: 50%; transform: translate(-50%, -50%) rotate(-11deg); color: #385a83; font-size: clamp(22px, 4vw, 46px); }
.project-cover[data-scene="turns"] span { inset: 0; background: radial-gradient(circle at 24% 28%, #bfd7f2 0 1%, transparent 1.6%), radial-gradient(circle at 74% 70%, #bfd7f2 0 .8%, transparent 1.5%); }
.project-cover[data-scene="shared"]::before { inset: 0; background: radial-gradient(circle at 22% 29%, #ffd883 0 1%, transparent 1.5%), radial-gradient(circle at 61% 37%, #d0edff 0 2%, transparent 2.5%), radial-gradient(circle at 73% 71%, #ffd883 0 1%, transparent 1.5%); }
.project-details { position: relative; padding: 15px 45px 16px 16px; }
.project-details h2 { margin: 0; font-size: 16px; font-weight: 670; line-height: 1.4; overflow-wrap: anywhere; }
.project-details p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.project-arrow { position: absolute; top: 17px; right: 15px; color: #b7d3f1; }

.panel { border: 1px solid var(--border); border-radius: 15px; background: var(--surface); }
.primary, .secondary { display: inline-flex; justify-content: center; align-items: center; min-height: 42px; padding: 9px 13px; border: 1px solid transparent; border-radius: 9px; font-size: 13px; font-weight: 650; white-space: nowrap; }
.primary { background: var(--accent); color: #102441; }
.primary:hover:enabled, a.primary:hover { background: #c6e4ff; }
.secondary { background: #1e3049; color: #dfedff; border-color: #3c5676; }
.secondary:hover:enabled, a.secondary:hover { background: #2a4262; }

#play { display: flex; flex: 1; flex-direction: column; gap: 10px; width: calc(100% - 2 * clamp(10px, 1.25vw, 24px)); padding: 12px 0 max(12px, env(safe-area-inset-bottom)); }
#play .page-heading { margin: 0; }
#play .page-heading h1 { font-size: clamp(20px, 2.3vw, 28px); }
#play .page-heading .secondary { min-height: 34px; padding-block: 6px; }
.game-shell { position: relative; flex: 1; min-height: 280px; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: 13px; }
.game-shell.is-playing { min-height: 420px; }
#game-frame, #game-placeholder, #room-art { position: absolute; inset: 0; width: 100%; height: 100%; }
#game-frame { display: block; border: 0; }
#room-art { aspect-ratio: auto; }
.room-dock { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface); }
#room-panel { display: grid; grid-template-columns: minmax(170px, .85fr) minmax(280px, 1.25fr) auto; }
.dock-project, .dock-members { min-width: 0; }
#room-project-control { margin: 0; }
#room-project-select { margin: 0; }
#room-project-meta { display: block; margin: 4px 0 0; color: var(--muted); font-size: 11px; }
#room-project-meta:empty, #room-project-name:empty, .room-panel p:empty { display: none; }
.room-panel h2 { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
#entry-copy { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.entry-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.entry-actions input { width: min(100%, 180px); margin: 0; }
#entry-panel:has(#enter-community-room:not([hidden])) #enter-room { background: #243651; color: #deebff; }
.room-panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.room-panel-heading h2 { font-size: 12px; }
.room-count { color: var(--muted); font-size: 12px; white-space: nowrap; }
#players { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.player { display: flex; align-items: center; gap: 6px; min-height: 37px; padding: 4px 7px; background: #192a41; border: 1px solid transparent; border-radius: 8px; }
.player[data-state="empty"] { background: transparent; border: 1px dashed #41556e; color: var(--muted); }
.player-avatar { display: grid; flex: none; place-items: center; width: 25px; height: 25px; border-radius: 7px; background: #334e73; color: #dceaff; font-size: 12px; }
.player:nth-child(2) .player-avatar { background: #4d426a; }
.player[data-state="empty"] .player-avatar { background: transparent; color: var(--muted); }
.player strong { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 13px; font-weight: 600; }
.player-tag { flex: none; color: var(--muted); font-size: 11px; }
.player-presence { flex: none; width: 7px; height: 7px; border-radius: 50%; background: #788ba8; }
.player[data-state="online"] .player-presence { background: #82dfb7; }
.room-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.room-actions #game-agent[aria-pressed="true"] { background: var(--accent); color: #102441; }
.dock-controls { position: relative; }
.agent-options { position: absolute; z-index: 3; right: 12px; bottom: calc(100% + 8px); width: min(350px, calc(100% - 24px)); padding: 12px; display: grid; gap: 8px; box-shadow: 0 12px 28px #060d1eaa; }
.room-dock:has(.agent-options) { position: relative; }
.agent-options select { width: 100%; }
.agent-options button { justify-self: start; }
.agent-options p { margin: 0; }
#room-start-hint { margin: 0 0 4px; font-size: 11px; text-align: end; }

label { display: block; color: var(--muted); font-size: 13px; }
input, select { width: 100%; min-width: 0; min-height: 42px; margin-top: 6px; padding: 8px 10px; border: 1px solid #405777; border-radius: 8px; background: #0e1a2d; color: #ecf2fc; font-size: 13px; }
input::placeholder { color: #9bb0cd; }
.join-form { display: flex; gap: 9px; width: min(100%, 540px); padding: 14px; }
.join-form input { margin: 0; }
.publish { padding: 20px; }
#publish-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.publish-fields { display: grid; gap: 12px; }
.upload-box { position: relative; min-height: 160px; overflow: hidden; border: 1px dashed #577296; border-radius: 12px; background: #1c2c44; }
.upload-box:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.upload-box input { position: absolute; inset: 0; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.upload-box label { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; height: 100%; padding: 18px; color: #dbe9fc; pointer-events: none; overflow-wrap: anywhere; }
.upload-icon { font-size: 27px; }
#published { display: grid; gap: 12px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
#published-link { color: var(--accent); font-size: 13px; overflow-wrap: anywhere; }
#published>div { display: flex; gap: 8px; flex-wrap: wrap; }
#toast { position: fixed; z-index: 10; left: 50%; bottom: 20px; width: max-content; max-width: calc(100vw - 32px); transform: translateX(-50%); padding: 10px 14px; border-radius: 8px; background: #2a405f; color: #f5f9ff; opacity: 0; pointer-events: none; font-size: 13px; }
#toast.show { opacity: 1; }

@media (max-width: 720px) {
  .topbar { gap: 8px; flex-wrap: wrap; }
  .header-status { flex-basis: 100%; }
  #room-panel { grid-template-columns: 1fr; gap: 10px; }
  #entry-panel { align-items: flex-start; flex-direction: column; gap: 8px; }
  .room-actions > * { flex: 1; }
  #room-start-hint { text-align: start; }
  #publish-form { grid-template-columns: 1fr; }
}
@media (max-width: 400px) {
  :root { --page-gutter: 10px; }
  .topbar { padding-inline: 10px; }
  .topbar nav a { padding-inline: 8px; }
}
@media (prefers-reduced-motion: reduce) { .project-card { transition: none; } }
