:root {
  --bg: #070b14;
  --bg-soft: #0f172a;
  --panel: rgba(14, 21, 37, 0.82);
  --panel-2: rgba(20, 30, 52, 0.76);
  --border: rgba(129, 159, 255, 0.22);
  --text: #ecf2ff;
  --muted: #9fb2d8;
  --primary: #7f9cff;
  --accent: #48d7b0;
  --danger: #ff788e;
  --ok: #7de0a8;
  --shadow: 0 20px 42px rgba(0, 0, 0, 0.35);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: radial-gradient(1100px 500px at -5% -10%, #1a2b56 0%, transparent 60%),
    radial-gradient(900px 500px at 105% 0%, #0f3f44 0%, transparent 58%), var(--bg);
}

body {
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

.bg-grid,
.bg-orb {
  position: fixed;
  pointer-events: none;
  z-index: 0;
}

.bg-grid {
  inset: 0;
  opacity: 0.09;
  background-image: linear-gradient(rgba(127, 156, 255, 0.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(127, 156, 255, 0.35) 1px, transparent 1px);
  background-size: 32px 32px;
}

.bg-orb {
  width: 420px;
  height: 420px;
  border-radius: 999px;
  filter: blur(90px);
  opacity: 0.3;
}

.orb-1 {
  left: -140px;
  top: 80px;
  background: #5e6fff;
}

.orb-2 {
  right: -140px;
  top: -40px;
  background: #1ec8a3;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 14px clamp(14px, 4vw, 42px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(127, 156, 255, 0.16);
  background: rgba(7, 11, 20, 0.7);
}

.logo {
  margin: 0;
  font-size: clamp(1.08rem, 2.2vw, 1.35rem);
  letter-spacing: 0.3px;
}

.tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.ui-version {
  display: inline-flex;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(127, 156, 255, 0.3);
  background: rgba(127, 156, 255, 0.14);
  font-size: 0.7rem;
  color: #dce7ff;
}

#app,
.scene {
  position: relative;
  z-index: 1;
}

.content-wrap {
  width: min(1200px, 95vw);
  margin: 26px auto 40px;
}

.micro {
  margin: 0 0 8px;
  color: #8fe6d0;
  font-size: 0.74rem;
  letter-spacing: 0.45px;
}

.hero-title {
  margin: 0 0 10px;
  font-size: clamp(1.65rem, 4vw, 2.5rem);
  line-height: 1.1;
}

.hero-title.small {
  font-size: clamp(1.18rem, 2.8vw, 1.65rem);
}

.body-copy,
.hint {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.62;
}

.panel,
.role-card,
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(9px);
}

.roles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
}

.role-card {
  padding: 14px;
}

.role-card h3 {
  margin: 0 0 8px;
  font-size: 1.02rem;
}

.role-card p {
  margin: 0 0 10px;
  color: var(--muted);
}

.topic-genres {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.genre-badge {
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(127, 156, 255, 0.3);
  background: rgba(127, 156, 255, 0.12);
  font-size: 0.75rem;
}

.player-gender-chooser {
  margin: 0 0 16px;
  padding: 12px 14px;
}

.start-actions {
  margin: 0 0 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.scene-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.gender-options {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.gender-options label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.game-layout {
  width: min(1320px, 95vw);
  margin: 18px auto 38px;
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(300px, 1fr);
  gap: 16px;
  align-items: stretch;
}

.roomchat-layout {
  min-height: calc(100vh - 96px);
  max-height: calc(100vh - 96px);
}

.story-panel {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
  padding: 14px;
  background: linear-gradient(165deg, rgba(14, 21, 37, 0.92), rgba(12, 18, 32, 0.88));
}

.story-head {
  margin-bottom: 10px;
}

.scene-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(127, 156, 255, 0.25);
  background: rgba(10, 16, 28, 0.86);
  margin-bottom: 10px;
}

.scene-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.84rem;
}

.scene-image-btn {
  min-height: 35px;
  padding: 7px 10px;
  font-size: 0.79rem;
}

.scene-image-wrap {
  margin: 0 0 10px;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid rgba(127, 156, 255, 0.2);
  background: rgba(8, 13, 24, 0.92);
}

.scene-image-status {
  margin-bottom: 8px;
  font-size: 0.74rem;
}

.scene-image-wrap img {
  width: 100%;
  max-width: min(100%, 320px);
  aspect-ratio: 1 / 1;
  object-fit: cover;
  margin: 0 auto;
  display: block;
  border-radius: 12px;
  border: 1px solid rgba(127, 156, 255, 0.26);
}

.story-feed {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border-radius: 14px;
  border: 1px solid rgba(127, 156, 255, 0.2);
  background: linear-gradient(180deg, rgba(6, 10, 18, 0.9), rgba(9, 14, 25, 0.96));
  padding: 14px;
  margin-bottom: 10px;
}

.chat-notice {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-left: 3px solid rgba(127, 156, 255, 0.9);
  border-radius: 10px;
  background: rgba(127, 156, 255, 0.1);
  color: #d5e1ff;
  white-space: pre-wrap;
  line-height: 1.55;
}

.bubble {
  margin: 0 0 11px;
  padding: 10px 12px;
  border-radius: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.58;
}

.bubble.user {
  margin-left: auto;
  max-width: min(80%, 600px);
  border: 1px solid rgba(127, 156, 255, 0.35);
  background: linear-gradient(180deg, rgba(103, 137, 248, 0.28), rgba(77, 113, 225, 0.18));
}

.bubble.ai {
  max-width: 100%;
  border: 1px solid rgba(129, 159, 255, 0.2);
  background: rgba(22, 34, 58, 0.7);
}

.bubble-letter {
  font-family: "Georgia", "Times New Roman", serif;
}

.bubble-rich {
  background: rgba(19, 30, 51, 0.82);
}

.speaker {
  display: block;
  margin-bottom: 4px;
  color: #9edcf8;
  font-size: 0.75rem;
  font-weight: 700;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 10px;
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(72, 215, 176, 0.12);
  color: #baf3e3;
}

.turn-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#turnInput {
  width: 100%;
  min-height: 66px;
  max-height: 160px;
  resize: vertical;
  padding: 11px 12px;
  border-radius: 14px;
  border: 1px solid rgba(127, 156, 255, 0.3);
  background: rgba(8, 13, 22, 0.95);
  color: var(--text);
  font: inherit;
}

.input-hint {
  margin-top: 8px;
  font-size: 0.8rem;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
  padding: 12px;
  background: linear-gradient(165deg, rgba(16, 24, 42, 0.92), rgba(14, 19, 31, 0.9));
}

.events-sidebar {
  min-height: 0;
}

.hud-card {
  border-radius: 14px;
  border: 1px solid rgba(127, 156, 255, 0.18);
  background: var(--panel-2);
  padding: 10px;
}

.hud-card h3 {
  margin: 0 0 8px;
  font-size: 0.94rem;
}

#events {
  max-height: min(45vh, 420px);
  overflow: auto;
  padding-right: 2px;
}

.event-empty {
  font-size: 0.88rem;
  color: var(--muted);
}

.event-item {
  margin: 0 0 8px;
  padding: 9px;
  border-radius: 11px;
  border: 1px solid rgba(127, 156, 255, 0.18);
  background: rgba(11, 18, 33, 0.82);
  cursor: pointer;
}

.event-item:hover {
  border-color: rgba(127, 156, 255, 0.38);
}

.event-item.is-selected {
  border-color: rgba(72, 215, 176, 0.52);
  background: rgba(72, 215, 176, 0.1);
}

.event-item.status-failed {
  border-color: rgba(255, 120, 142, 0.45);
}

.event-item.status-resolved {
  border-color: rgba(125, 224, 168, 0.45);
}

.event-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.event-pill {
  border-radius: 999px;
  border: 1px solid rgba(127, 156, 255, 0.3);
  background: rgba(127, 156, 255, 0.12);
  padding: 2px 7px;
  font-size: 0.72rem;
  text-transform: uppercase;
}

.event-detail {
  margin: 0 0 5px;
  color: #d5e1fc;
  font-size: 0.85rem;
  line-height: 1.5;
}

.event-meta {
  display: grid;
  gap: 3px;
  font-size: 0.74rem;
  color: var(--muted);
}

.metric-row {
  margin: 0 0 9px;
}

.metric-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.metric-label {
  font-size: 0.8rem;
}

.metric-value {
  font-size: 0.8rem;
  color: #cfe0ff;
}

.metric-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(127, 156, 255, 0.14);
  overflow: hidden;
}

.metric-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #7f9cff, #48d7b0);
}

.metric-status {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}

.ghost-btn {
  border: 1px solid rgba(127, 156, 255, 0.4);
  background: rgba(127, 156, 255, 0.1);
  color: #dce8ff;
  border-radius: 10px;
  min-height: 38px;
  padding: 7px 12px;
  font: inherit;
  font-size: 0.86rem;
  cursor: pointer;
}

.ghost-btn:hover {
  background: rgba(127, 156, 255, 0.2);
}

.ghost-btn.danger {
  border-color: rgba(169, 66, 66, 0.45);
  color: #6e2222;
  background: #f5dede;
}

.ghost-btn:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.custom-role-input,
select,
input,
textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(127, 156, 255, 0.3);
  background: rgba(8, 13, 22, 0.94);
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}

dialog {
  width: min(560px, 92vw);
  color: var(--text);
}

dialog::backdrop {
  background: rgba(4, 8, 15, 0.6);
}

.settings-sheet,
.setup-card {
  padding: 14px;
}

.settings-sheet label,
.setup-card label {
  display: grid;
  gap: 6px;
  margin: 0 0 10px;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
  padding: 0;
}

.setup-gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(5, 9, 17, 0.74);
  padding: 16px;
}

.setup-card {
  width: min(540px, 100%);
}

.ghost-btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.event-item:focus-visible {
  outline: 2px solid rgba(127, 156, 255, 0.92);
  outline-offset: 2px;
}

@media (max-width: 1024px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .roomchat-layout {
    min-height: auto;
    max-height: none;
  }

  .story-panel,
  .side-panel {
    min-height: auto;
    height: auto;
  }

  .story-feed {
    max-height: 55vh;
  }

  #events {
    max-height: 36vh;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .scene-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .turn-form {
    flex-direction: column;
    align-items: stretch;
  }

  .send-btn {
    width: 100%;
  }

  .bubble.user,
  .bubble.ai {
    max-width: 94%;
  }

  .story-feed {
    min-height: 280px;
    max-height: 48vh;
  }

  .roles {
    grid-template-columns: 1fr;
  }

  .start-actions {
    grid-template-columns: 1fr;
  }

  .scene-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
}

/* UI v8 visual reset */
:root {
  --bg: #f3f6fc;
  --bg-soft: #eaf0fb;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-2: rgba(248, 251, 255, 0.96);
  --border: rgba(93, 121, 198, 0.18);
  --text: #0f1e3d;
  --muted: #5e6f96;
  --primary: #496de7;
  --accent: #1fb691;
  --danger: #d95f72;
  --ok: #279f6d;
}

html,
body {
  background: linear-gradient(180deg, #f7f9fe, #eef3fc) fixed;
}

.bg-grid {
  opacity: 0.04;
}

.orb-1 {
  background: #8ea8ff;
}

.orb-2 {
  background: #78d8be;
}

.topbar {
  background: rgba(248, 251, 255, 0.86);
  border-bottom-color: rgba(93, 121, 198, 0.16);
}

.ui-version {
  background: rgba(73, 109, 231, 0.12);
  color: #1f356e;
}

.panel,
.role-card,
dialog {
  border-color: rgba(93, 121, 198, 0.16);
  box-shadow: 0 12px 28px rgba(39, 63, 122, 0.12);
}

.story-panel,
.side-panel {
  background: rgba(255, 255, 255, 0.96);
}

.scene-bar,
.scene-image-wrap,
.story-feed,
#turnInput,
.hud-card,
.event-item,
.metric-bar,
.ghost-btn,
.custom-role-input,
select,
input,
textarea {
  background: #fff;
}

.story-feed {
  border-color: rgba(93, 121, 198, 0.16);
}

.bubble.user {
  border-color: rgba(73, 109, 231, 0.28);
  background: linear-gradient(180deg, rgba(73, 109, 231, 0.12), rgba(73, 109, 231, 0.07));
}

.bubble.ai {
  border-color: rgba(93, 121, 198, 0.2);
  background: #f6f9ff;
}

.chat-notice {
  border-left-color: var(--accent);
  background: rgba(31, 182, 145, 0.1);
  color: #204e43;
}

.event-item.is-selected {
  background: rgba(73, 109, 231, 0.08);
  border-color: rgba(73, 109, 231, 0.34);
}

/* Hard chatbox reshape */
.turn-form {
  display: block;
}

.composer-shell {
  border: 1px solid rgba(73, 109, 231, 0.28);
  border-radius: 24px;
  background: linear-gradient(180deg, #ffffff, #f5f8ff);
  box-shadow: 0 14px 30px rgba(45, 73, 144, 0.16);
  padding: 10px;
}

#turnInput {
  min-height: 90px;
  max-height: 190px;
  border-radius: 16px;
  border: 1px solid rgba(73, 109, 231, 0.2);
  color: #10244b;
  padding: 12px 13px;
}

.composer-foot {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.composer-meta {
  color: #5a6e97;
  font-size: 0.76rem;
}

.send-btn {
  border-radius: 999px;
  min-width: 98px;
  font-weight: 700;
}

.story-feed {
  border-radius: 26px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92), 0 10px 22px rgba(45, 73, 144, 0.09);
}

@media (max-width: 760px) {
  .turn-form {
    display: block;
  }

  .composer-foot {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Modern premium pass v10 */
.topbar {
  border-bottom: 1px solid rgba(88, 120, 210, 0.2);
  box-shadow: 0 10px 24px rgba(29, 48, 98, 0.08);
}

.story-panel,
.side-panel {
  border-radius: 22px;
}

.story-head .hero-title {
  letter-spacing: -0.02em;
}

.scene-bar {
  border-radius: 16px;
  border-color: rgba(88, 120, 210, 0.22);
}

.story-feed {
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  border: 1px solid rgba(88, 120, 210, 0.16);
}

.bubble {
  position: relative;
  border-radius: 16px;
}

.bubble.user::after {
  content: "";
  position: absolute;
  right: -7px;
  bottom: 10px;
  width: 12px;
  height: 12px;
  background: inherit;
  border-right: 1px solid rgba(73, 109, 231, 0.28);
  border-bottom: 1px solid rgba(73, 109, 231, 0.28);
  transform: rotate(-35deg);
}

.bubble.ai {
  border-left: 3px solid rgba(88, 120, 210, 0.28);
}

.chat-notice {
  border-radius: 12px;
  font-size: 0.91rem;
}

.event-item {
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.event-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(41, 63, 124, 0.12);
}

.hud-card {
  border-radius: 16px;
}

.composer-shell {
  border-radius: 26px;
  border-color: rgba(88, 120, 210, 0.24);
  box-shadow: 0 18px 34px rgba(37, 62, 129, 0.14);
}

#turnInput {
  border-radius: 18px;
}

.send-btn {
  background: linear-gradient(180deg, #4d74ea, #3e63d2);
  border-color: transparent;
  color: #f5f9ff;
  box-shadow: 0 8px 16px rgba(52, 85, 182, 0.28);
}

.send-btn:hover {
  background: linear-gradient(180deg, #567cf0, #466cdb);
}

/* WCAG AA warm palette v11 */
:root {
  --bg: #f6f0e5;
  --bg-soft: #efe4d4;
  --panel: rgba(255, 250, 242, 0.96);
  --panel-2: rgba(252, 245, 236, 0.98);
  --border: rgba(109, 83, 59, 0.28);
  --text: #2e2117;
  --muted: #5f4a38;
  --primary: #6b4f36;
  --accent: #7d5f44;
  --danger: #7f2e2e;
  --ok: #1f5b3f;
}

html,
body {
  color: var(--text);
  background: linear-gradient(180deg, #f8f2e9, #eee1d0) fixed;
}

.topbar {
  background: rgba(252, 245, 236, 0.9);
  border-bottom-color: rgba(109, 83, 59, 0.24);
}

.tagline,
.hint,
.composer-meta,
.metric-status,
.event-meta,
.role-card p {
  color: #4f3d2e;
}

.panel,
.role-card,
dialog,
.hud-card,
.event-item,
.scene-bar,
.scene-image-wrap,
.story-feed,
.composer-shell,
#turnInput,
.ghost-btn,
input,
select,
textarea {
  border-color: rgba(109, 83, 59, 0.28);
  background: #fffaf2;
}

.story-feed {
  background: linear-gradient(180deg, #fffaf2, #fdf5ea);
}

.speaker {
  color: #5a3f2c;
}

.bubble.ai {
  color: #2f241a;
  border-left-color: rgba(109, 83, 59, 0.4);
  background: #fff7ec;
}

.bubble.user {
  color: #2f241a;
  border-color: rgba(109, 83, 59, 0.46);
  background: linear-gradient(180deg, #f2e2cc, #ead5b8);
}

.bubble.user::after {
  border-right-color: rgba(109, 83, 59, 0.46);
  border-bottom-color: rgba(109, 83, 59, 0.46);
}

.chat-notice {
  color: #3f2f22;
  border-left-color: #6b4f36;
  background: #f4e5d2;
}

.ghost-btn {
  color: #2f241a;
  background: #f5e9d9;
  border-color: rgba(109, 83, 59, 0.42);
}

.ghost-btn:hover {
  background: #eddcc8;
}

.send-btn {
  color: #fffaf2;
  background: linear-gradient(180deg, #7b5d40, #65492f);
  box-shadow: 0 8px 14px rgba(83, 58, 34, 0.3);
}

.send-btn:hover {
  background: linear-gradient(180deg, #886748, #705236);
}

#turnInput {
  color: #2c2016;
  font-size: 0.98rem;
  line-height: 1.55;
}

.micro {
  color: #6b4f36;
}

.event-pill {
  color: #3d2d20;
  background: #f3e4d1;
  border-color: rgba(109, 83, 59, 0.35);
}

@media (max-width: 760px) {
  body {
    font-size: 15px;
  }

  .story-feed {
    min-height: 310px;
    max-height: 52vh;
  }

  #turnInput {
    min-height: 102px;
    font-size: 1rem;
  }

  .composer-meta {
    font-size: 0.8rem;
  }

  .event-detail {
    font-size: 0.9rem;
  }
}
