:root {
  --bg: #dccdb7;
  --bg-elev: #e8dcc9;
  --bg-soft: #f4ecdf;
  --surface: rgba(249, 242, 230, 0.9);
  --surface-strong: #f3e8d7;
  --border: #c5ab84;
  --text: #2e2012;
  --muted: #715e47;
  --accent: #b86732;
  --accent-2: #d69a49;
  --danger: #af4f43;
  --input: #fbf3e7;
  --shadow: 0 22px 48px rgba(81, 57, 28, 0.16);
}

body.theme-dark {
  --bg: #403631;
  --bg-elev: #51443e;
  --bg-soft: #62534b;
  --surface: rgba(94, 80, 71, 0.9);
  --surface-strong: #6e5d53;
  --border: #9b7f68;
  --text: #f3e7d6;
  --muted: #d7c0a6;
  --accent: #d38c4f;
  --accent-2: #c2a165;
  --danger: #cf7768;
  --input: #67584f;
  --shadow: 0 24px 54px rgba(14, 10, 8, 0.24);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  min-height: 100dvh;
  background: radial-gradient(circle at 15% 20%, rgba(214, 154, 73, 0.22) 0%, transparent 42%),
    radial-gradient(circle at 80% 0%, rgba(108, 137, 129, 0.18) 0%, transparent 28%),
    var(--bg);
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.bg-atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 999px;
  filter: blur(80px);
  opacity: 0.45;
}

.orb-1 {
  width: 360px;
  height: 360px;
  background: rgba(214, 154, 73, 0.6);
  left: -90px;
  top: -100px;
}

.orb-2 {
  width: 430px;
  height: 430px;
  background: rgba(110, 136, 126, 0.55);
  right: -120px;
  bottom: -160px;
}

.grid-noise {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(46, 32, 18, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(46, 32, 18, 0.035) 1px, transparent 1px);
  background-size: 40px 40px;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(92, 73, 49, 0.22);
  backdrop-filter: blur(6px);
}

.login-panel {
  width: min(430px, 100%);
  background: linear-gradient(180deg, rgba(250, 245, 236, 0.96), rgba(242, 233, 219, 0.96));
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin: 0 0 0.3rem 0;
}

.login-help {
  margin: 0 0 0.9rem 0;
  color: var(--muted);
  font-size: 0.92rem;
}

#login-form,
#register-form {
  display: grid;
  gap: 0.45rem;
}

#login-form input,
#register-form input {
  width: 100%;
  padding: 0.62rem 0.72rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input);
  color: var(--text);
}

/* Prevent iOS Safari from zooming focused text fields. */
#login-form input,
#register-form input,
#player-input,
.feedback-text,
.new-game-fields input {
  font-size: 16px;
}

#btn-login,
#btn-register,
#btn-send,
#btn-voice-send,
#btn-new-game,
#btn-create-game,
#btn-send-feedback,
#btn-drawer-new-game,
.new-game-mode-actions button,
.new-game-actions button,
.btn-start-standard,
.btn-select-custom-template {
  border: none;
  border-radius: 12px;
  cursor: pointer;
  padding: 0.6rem 0.95rem;
  background: linear-gradient(120deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #0b1a24;
  font-weight: 700;
}

#btn-login:disabled,
#btn-register:disabled,
#btn-send:disabled,
#btn-voice-send:disabled,
#btn-create-game:disabled,
#btn-drawer-new-game:disabled,
.btn-start-standard:disabled,
.btn-select-custom-template:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary,
.btn-secondary-auth,
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.52rem 0.8rem;
  cursor: pointer;
}

.btn-ghost {
  color: var(--muted);
}

.login-error,
.games-list-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.15rem 0;
}

#app {
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.8rem;
  padding: 1rem;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.8rem;
  align-items: center;
  background: linear-gradient(180deg, rgba(247, 239, 226, 0.9), rgba(241, 231, 214, 0.9));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0.7rem 0.9rem;
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 60;
}

.topbar-left {
  min-width: 0;
  justify-self: start;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.4rem;
  background: transparent;
  border: none;
  padding: 0;
  color: inherit;
  cursor: pointer;
}

.home-link {
  width: 2.5rem;
  height: 2.5rem;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 249, 241, 0.74);
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.home-link svg {
  width: 1.12rem;
  height: 1.12rem;
  display: block;
  fill: currentColor;
}

.home-link:hover {
  transform: translateY(-1px);
  border-color: rgba(157, 98, 54, 0.36);
  background: rgba(255, 250, 244, 0.94);
}

.brand-link:hover .brand-title {
  color: var(--accent);
}

.brand-title {
  margin: 0;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  transition: color 140ms ease;
}

.brand-subtitle {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.topbar-title-block,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.topbar-title-block {
  min-width: 0;
  gap: 0.85rem;
  align-self: stretch;
}

.topbar-right {
  justify-self: end;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-left: auto;
}

.topbar-title-separator {
  width: 1px;
  align-self: stretch;
  background: linear-gradient(180deg, transparent, rgba(157, 98, 54, 0.36), transparent);
}

.topbar-title-copy {
  min-width: 0;
  display: grid;
  gap: 0.1rem;
}

.topbar-title-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.68rem;
  font-weight: 800;
}

.topbar-story-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.98rem;
  font-weight: 700;
}

.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.25rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(247, 239, 226, 0.82);
  color: var(--text);
  white-space: nowrap;
}

.topbar-turn {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  font-size: 0.84rem;
  color: var(--muted);
}

.turn-count-icon {
  width: 0.92rem;
  height: 0.92rem;
  flex: 0 0 auto;
}

.topbar-game {
  font-size: 0.8rem;
  font-weight: 700;
}

.theme-toggle {
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 249, 241, 0.74);
  color: var(--text);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.theme-toggle:hover {
  transform: translateY(-1px);
  border-color: rgba(157, 98, 54, 0.36);
  background: rgba(255, 250, 244, 0.94);
}

.language-switcher {
  position: relative;
}

.language-toggle {
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 249, 241, 0.74);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: 0.78rem;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.language-toggle:hover {
  transform: translateY(-1px);
  border-color: rgba(157, 98, 54, 0.36);
  background: rgba(255, 250, 244, 0.94);
}

.language-toggle-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.language-menu {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  min-width: 12rem;
  padding: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 249, 241, 0.98);
  box-shadow: 0 22px 44px rgba(55, 35, 18, 0.16);
  display: grid;
  gap: 0.2rem;
  z-index: 90;
}

.language-menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 0.62rem 0.72rem;
  text-align: left;
}

.language-menu-item:hover,
.language-menu-item.is-active {
  background: rgba(157, 98, 54, 0.12);
}

.language-menu-code {
  font-size: 0.73rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.language-menu-label {
  margin-left: auto;
  font-weight: 700;
}

.topbar-action {
  min-height: 2.5rem;
  padding: 0.5rem 0.82rem;
  font-size: 0.88rem;
}

.workspace {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 0.8rem;
  min-height: 0;
  overflow: hidden;
}

.workspace-landing {
  grid-template-columns: minmax(0, 1fr);
}

.workspace-story {
  grid-template-columns: minmax(0, 1fr);
}

.main {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(250, 245, 236, 0.92), rgba(243, 234, 219, 0.96));
  backdrop-filter: blur(10px);
  overflow: hidden;
  z-index: 10;
}

.landing-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: clamp(1rem, 2.6vw, 1.7rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: fadeIn 220ms ease;
}

.landing-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.95fr);
  gap: 1rem;
  align-items: stretch;
}

.landing-hero,
.landing-games,
.landing-how {
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.landing-hero {
  position: relative;
  overflow: hidden;
  padding: clamp(1.2rem, 3vw, 2rem);
  background:
    radial-gradient(circle at top right, rgba(214, 154, 73, 0.18), transparent 34%),
    radial-gradient(circle at left center, rgba(110, 136, 126, 0.16), transparent 42%),
    linear-gradient(150deg, rgba(250, 244, 233, 0.98), rgba(237, 227, 210, 0.98));
}

.landing-kicker,
.landing-section-label {
  margin: 0;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.77rem;
  font-weight: 700;
}

.landing-title {
  margin: 0.6rem 0 0;
  max-width: 11ch;
  font-size: clamp(2.4rem, 6vw, 4.9rem);
  line-height: 0.95;
}

.landing-subtitle {
  margin: 1rem 0 0;
  max-width: 58ch;
  color: #4d3b28;
  font-size: 1.02rem;
  line-height: 1.55;
}

.landing-actions {
  margin-top: 1.4rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.landing-action-card {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0.7rem;
  padding: 0.85rem;
  border-radius: 18px;
  border: 1px solid rgba(184, 103, 50, 0.12);
  background: rgba(255, 250, 243, 0.72);
  backdrop-filter: blur(8px);
}

.story-choice-button {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: 48px;
  padding: 0.72rem 0.95rem;
  border: none;
  border-radius: 12px;
  background: linear-gradient(120deg, var(--accent) 0%, var(--accent-2) 100%);
  color: var(--text);
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

.story-choice-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(81, 57, 28, 0.18);
  filter: brightness(1.03);
}

.story-choice-content {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.story-choice-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  background: rgba(255, 246, 235, 0.7);
  border: 1px solid rgba(85, 58, 30, 0.14);
  color: var(--text);
}

.story-choice-icon svg {
  width: 1rem;
  height: 1rem;
  display: block;
  fill: currentColor;
}

.story-choice-label {
  display: inline-block;
  min-width: 0;
  line-height: 1.25;
}

.story-choice-button-compact {
  min-height: 64px;
  justify-content: flex-start;
}

.story-choice-button-compact .story-choice-icon {
  background: rgba(255, 246, 235, 0.82);
}

.landing-action-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.48;
}

.landing-games {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  background: linear-gradient(180deg, rgba(248, 241, 229, 0.98), rgba(241, 232, 217, 0.98));
}

.landing-games-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.8rem;
}

.landing-games-header h2,
.landing-how-header h2 {
  margin: 0;
}

.landing-games-subtitle {
  margin: 0.3rem 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.landing-games-list {
  display: grid;
  gap: 0.55rem;
}

.landing-game-item {
  background: linear-gradient(180deg, rgba(252, 247, 239, 0.98), rgba(242, 234, 220, 0.98));
}

.landing-how {
  padding: 1rem;
  background: linear-gradient(180deg, rgba(249, 242, 230, 0.96), rgba(241, 233, 219, 0.98));
}

.landing-how-header {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
}

.landing-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.landing-step {
  min-height: 172px;
  padding: 0.95rem;
  border-radius: 18px;
  border: 1px solid rgba(184, 103, 50, 0.12);
  background: linear-gradient(180deg, rgba(255, 250, 244, 0.92), rgba(244, 236, 224, 0.96));
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.landing-step-index {
  color: #9d6236;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.landing-step h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.45;
}

.story-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: clamp(0.95rem, 2.2vw, 1.35rem);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(252, 247, 239, 0.86), rgba(240, 231, 217, 0.92)),
    linear-gradient(135deg, rgba(214, 154, 73, 0.08), transparent 40%);
}

.story-shell-header {
  display: grid;
  gap: 0.55rem;
}

.sheet-title {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
}

.story-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: flex-end;
  gap: 0.28rem;
  padding: 0 0.3rem;
  margin-bottom: -1px;
  position: relative;
  z-index: 2;
}

.story-tab {
  position: relative;
  border: 1px solid rgba(85, 58, 30, 0.16);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  padding: 0.82rem 1.08rem 0.72rem;
  background: linear-gradient(180deg, rgba(231, 215, 193, 0.95), rgba(223, 205, 180, 0.95));
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
  white-space: nowrap;
  transform: translateY(8px);
  box-shadow: inset 0 -8px 0 rgba(165, 135, 101, 0.16);
}

.story-tab:hover {
  color: var(--text);
  border-color: rgba(157, 98, 54, 0.32);
}

.story-tab::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 5px;
  border-radius: 999px;
  background: transparent;
}

.story-tab.is-active {
  background: rgba(252, 247, 239, 1);
  color: var(--text);
  border-color: rgba(157, 98, 54, 0.34);
  transform: translateY(0);
  box-shadow: 0 10px 16px rgba(81, 57, 28, 0.08);
  z-index: 3;
}

.story-tab.is-active::after {
  background: rgba(252, 247, 239, 1);
}

.story-mobile-hint {
  display: none;
  margin: -0.1rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.story-pager {
  flex: 1;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.story-pager::-webkit-scrollbar {
  display: none;
}

.story-track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 100%;
  width: 100%;
  min-width: 100%;
  height: 100%;
}

.story-stage {
  min-width: 0;
  min-height: 0;
  display: flex;
  scroll-snap-align: start;
}

.dossier-sheet {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: clamp(1rem, 2.4vw, 1.4rem);
  border: 1px solid rgba(157, 98, 54, 0.22);
  border-radius: 30px;
  background:
    linear-gradient(180deg, rgba(253, 248, 241, 0.98), rgba(244, 235, 222, 0.98));
  box-shadow: 0 22px 46px rgba(81, 57, 28, 0.11);
  overflow: hidden;
}

.sheet-meta {
  display: flex;
  justify-content: flex-start;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.sheet-tag,
.sheet-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.34rem 0.62rem;
  border-radius: 999px;
  border: 1px solid rgba(85, 58, 30, 0.12);
  background: rgba(255, 251, 245, 0.88);
  color: var(--muted);
  font-size: 0.8rem;
}

.sheet-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(260px, 0.95fr);
  gap: 1rem;
  align-items: stretch;
  overflow: hidden;
}

.sheet-reading {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  overflow: hidden;
}

.sheet-title {
  font-size: clamp(1.6rem, 3vw, 2.35rem);
}

.sheet-support {
  margin: -0.45rem 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.context-stream {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: 100%;
  overflow-y: auto;
  padding: 1rem;
  border: 1px dashed rgba(157, 98, 54, 0.24);
  border-radius: 20px;
  background: rgba(255, 252, 247, 0.7);
  white-space: pre-wrap;
  line-height: 1.75;
  font-size: 1.02rem;
}

.context-cursor {
  display: inline-block;
  margin-left: 2px;
  color: var(--accent);
  animation: blink 0.9s step-end infinite;
}

.mission-card-primary {
  align-self: start;
  padding: 1.2rem;
  border-radius: 24px;
  border: 1px solid rgba(184, 103, 50, 0.28);
  background:
    linear-gradient(180deg, rgba(240, 220, 193, 0.86), rgba(247, 237, 222, 0.96));
  box-shadow: 0 16px 28px rgba(81, 57, 28, 0.1);
}

.mission-label {
  margin: 0;
  color: #9d6236;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 0.78rem;
  font-weight: 800;
}

.mission-copy {
  margin: 0.7rem 0 0;
  line-height: 1.6;
  font-size: 1.08rem;
  font-weight: 700;
}

/* ── Context 2/3 + 1/3 layout ──────────────────────────── */

.context-layout {
  display: flex;
  flex-direction: row;
  gap: 1rem;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.context-main {
  flex: 2;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.context-main .sheet-body {
  flex: 1;
  min-height: 0;
}

/* ── Memory chat panel (1/3) ────────────────────────────── */

.context-memory-panel {
  flex: 1;
  min-width: 220px;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  border: 1px solid rgba(184, 103, 50, 0.22);
  border-radius: 20px;
  background: rgba(255, 252, 247, 0.72);
  padding: 1rem;
  overflow: hidden;
}

.memory-panel-head {
  flex-shrink: 0;
  border-bottom: 1px solid rgba(157, 98, 54, 0.16);
  padding-bottom: 0.7rem;
}

.memory-panel-title {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 800;
  color: #9d6236;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.memory-panel-subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.memory-chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-right: 2px;
}

.memory-chat-entry {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.memory-chat-question {
  align-self: flex-end;
  background: rgba(184, 103, 50, 0.12);
  border-radius: 12px 12px 4px 12px;
  padding: 0.45rem 0.7rem;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink);
  max-width: 90%;
  word-break: break-word;
}

.memory-chat-answer {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(157, 98, 54, 0.18);
  border-radius: 4px 12px 12px 12px;
  padding: 0.45rem 0.7rem;
  font-size: 0.84rem;
  color: var(--ink);
  line-height: 1.55;
  max-width: 95%;
  word-break: break-word;
}

.memory-chat-answer.is-empty {
  color: var(--muted);
  font-style: italic;
}

.memory-chat-answer.is-loading {
  color: var(--muted);
  font-style: italic;
}

.memory-chat-answer.is-unavailable {
  color: var(--muted);
  font-style: italic;
}

.memory-chat-composer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(157, 98, 54, 0.14);
}

.memory-chat-input {
  width: 100%;
  box-sizing: border-box;
  resize: none;
  border: 1px solid rgba(184, 103, 50, 0.3);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
  font-size: 0.84rem;
  font-family: inherit;
  line-height: 1.45;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}

.memory-chat-input:focus {
  border-color: rgba(184, 103, 50, 0.6);
}

.memory-chat-send {
  align-self: flex-end;
  padding: 0.4rem 1rem;
  border: none;
  border-radius: 10px;
  background: var(--accent, #b86732);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}

.memory-chat-send:hover:not(:disabled) {
  opacity: 0.88;
}

.memory-chat-send:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Dark mode */
body.theme-dark .context-memory-panel {
  background: linear-gradient(180deg, rgba(108, 91, 81, 0.96), rgba(92, 78, 69, 0.98));
  border-color: rgba(184, 103, 50, 0.3);
}

body.theme-dark .memory-chat-answer {
  background: rgba(60, 45, 35, 0.7);
  border-color: rgba(184, 103, 50, 0.25);
}

body.theme-dark .memory-chat-question {
  background: rgba(184, 103, 50, 0.22);
}

body.theme-dark .memory-chat-input {
  background: rgba(50, 38, 28, 0.85);
  color: var(--ink);
  border-color: rgba(184, 103, 50, 0.35);
}

/* Responsive: ocultar panel en pantallas pequeñas */
@media (max-width: 900px) {
  .context-layout {
    flex-direction: column;
  }
  .context-memory-panel {
    max-width: none;
    flex: none;
    height: 280px;
  }
}

.story-stage-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  flex-wrap: wrap;
  padding-top: 0.95rem;
  border-top: 1px solid rgba(157, 98, 54, 0.16);
}

.story-characters-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  padding-right: 0.08rem;
}

.character-sheet-card {
  display: grid;
  gap: 0.65rem;
  align-content: start;
  padding: 1rem;
  border-radius: 24px;
  border: 1px solid rgba(157, 98, 54, 0.16);
  background: rgba(255, 250, 244, 0.82);
}

.character-sheet-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.character-sheet-card h3 {
  margin: 0;
  font-size: 1.1rem;
}

.character-sheet-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.character-sheet-personality {
  color: var(--muted);
}

.character-sheet-public-mission {
  padding: 0.72rem 0.85rem;
  border-radius: 16px;
  border: 1px solid rgba(184, 103, 50, 0.22);
  background: linear-gradient(180deg, rgba(255, 236, 210, 0.9), rgba(249, 224, 190, 0.78));
  color: #8f4d1f;
  font-weight: 700;
}

.mission-public-block {
  display: grid;
  gap: 0.3rem;
  margin-top: 0.85rem;
  padding-top: 0.8rem;
  border-top: 1px solid rgba(157, 98, 54, 0.14);
}

.mission-public-label {
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 800;
}

.mission-public-copy {
  margin: 0;
  color: var(--accent);
  line-height: 1.45;
  font-size: 0.95rem;
  font-weight: 700;
}

.chat-stage-brief {
  display: flex;
  align-items: stretch;
}

.chat-stage-brief-item {
  display: grid;
  gap: 0.35rem;
  align-content: start;
  padding: 0.72rem 0.95rem;
  border-radius: 18px;
  border: 1px solid rgba(157, 98, 54, 0.16);
  background: rgba(255, 250, 244, 0.8);
  min-height: 100%;
}

.chat-stage-brief-mission {
  width: 100%;
}

.chat-stage-brief-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.chat-stage-brief-dismiss {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  line-height: 1;
  transition: background 120ms ease, color 120ms ease, transform 120ms ease;
}

.chat-stage-brief-dismiss:hover,
.chat-stage-brief-dismiss:focus-visible {
  background: rgba(157, 98, 54, 0.12);
  color: var(--accent);
  outline: none;
}

.chat-stage-brief-dismiss:active {
  transform: scale(0.96);
}

.chat-stage-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 800;
}

.story-mission-inline {
  display: block;
  line-height: 1.45;
  font-size: 0.96rem;
  font-weight: 700;
}

.story-empty-state {
  margin: 0;
  padding: 1rem;
  border: 1px dashed rgba(157, 98, 54, 0.24);
  border-radius: 20px;
  background: rgba(255, 252, 247, 0.7);
  color: var(--muted);
}

.error-banner {
  padding: 0.7rem 0.95rem;
  color: #ffd2d8;
  background: rgba(224, 53, 89, 0.2);
  border-bottom: 1px solid rgba(224, 53, 89, 0.35);
}

.victory-overlay {
  position: absolute;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1.2rem, 2.4vw, 2rem);
  background: rgba(8, 14, 26, 0.78);
  backdrop-filter: blur(8px) saturate(120%);
  animation: fadeIn 220ms ease;
}

.victory-overlay::before,
.victory-overlay::after {
  content: "";
  position: absolute;
  width: 180%;
  height: 180%;
  left: -40%;
  top: -95%;
  pointer-events: none;
  opacity: 0.22;
  background: repeating-linear-gradient(
    90deg,
    #ffd761 0 8px,
    #31d5a3 8px 16px,
    #52a2ff 16px 24px,
    #ff8bb4 24px 32px
  );
  animation: confettiRain 2.2s linear infinite;
}

.victory-overlay::after {
  animation-delay: 1.1s;
  opacity: 0.16;
}

.victory-overlay-panel {
  position: relative;
  width: min(940px, 100%);
  min-height: min(70vh, 620px);
  border: 1px solid rgba(82, 162, 255, 0.34);
  border-radius: 24px;
  padding: clamp(1.4rem, 3vw, 2.6rem);
  background: linear-gradient(145deg, rgba(21, 40, 71, 0.95), rgba(12, 24, 44, 0.95));
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  animation: victoryPop 320ms ease, victoryGlow 2.1s ease-in-out infinite;
}

.victory-kicker {
  position: relative;
  z-index: 1;
  margin-bottom: 0.9rem;
  color: var(--muted);
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.victory-title {
  position: relative;
  z-index: 1;
  margin: 0;
  font-size: clamp(2.1rem, 6vw, 4.3rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.05;
}

.victory-subtitle {
  position: relative;
  z-index: 1;
  margin: 1rem 0 0;
  color: #d7ecff;
  font-size: clamp(1rem, 2vw, 1.3rem);
  max-width: 58ch;
}

.victory-note {
  position: relative;
  z-index: 1;
  margin-top: 1.1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 0.2rem 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.72rem;
}

.msg {
  max-width: min(78%, 760px);
  padding: 0.68rem 0.8rem;
  border-radius: 14px;
  border: 1px solid transparent;
  animation: rise 260ms ease;
}

.msg-system {
  align-self: center;
  width: min(90%, 780px);
  background: rgba(227, 214, 197, 0.58);
  border-color: rgba(157, 98, 54, 0.18);
}

.msg-agent {
  background: rgba(244, 235, 222, 0.9);
  border-color: rgba(157, 98, 54, 0.18);
}

.msg-player {
  margin-left: auto;
  background: rgba(239, 219, 191, 0.86);
  border-color: rgba(184, 103, 50, 0.24);
}

.msg-author {
  font-size: 0.73rem;
  color: var(--muted);
  margin-bottom: 0.22rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.msg-content {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.42;
}

.msg-streaming .msg-content::after {
  content: "▌";
  margin-left: 1px;
  animation: blink 0.9s step-end infinite;
}

.chat-thinking {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.8rem;
  border: 1px solid rgba(157, 98, 54, 0.16);
  border-radius: 999px;
  background: rgba(255, 251, 245, 0.78);
  color: var(--muted);
}

.chat-thinking-spinner {
  width: 0.9rem;
  height: 0.9rem;
  border: 2px solid rgba(157, 98, 54, 0.18);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

.input-area {
  display: grid;
  gap: 0.55rem;
  border-top: 1px solid var(--border);
  padding: 0.85rem 0 0;
  background: transparent;
  min-width: 0;
  overflow-x: clip;
}

.input-shell {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  width: 100%;
  padding: 0.3rem 0.35rem 0.3rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--input);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.input-shell:focus-within {
  border-color: rgba(184, 103, 50, 0.5);
  box-shadow: 0 0 0 3px rgba(184, 103, 50, 0.08);
}

.input-shell-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

#player-input {
  flex: 1;
  width: 100%;
  min-width: 0;
  background: transparent;
  color: var(--text);
  border: none;
  border-radius: 0;
  padding: 0.45rem 0;
  box-shadow: none;
}

#player-input:focus {
  outline: none;
}

.btn-voice {
  position: relative;
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn-voice:hover:not(:disabled),
.btn-voice:focus-visible {
  color: var(--accent);
  background: rgba(184, 103, 50, 0.08);
}

.btn-voice svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: currentColor;
}

.btn-voice.is-recording {
  background: rgba(175, 79, 67, 0.12);
  color: var(--danger);
  box-shadow: 0 0 0 3px rgba(175, 79, 67, 0.08);
}

.btn-voice.is-unavailable {
  color: rgba(113, 94, 71, 0.72);
}

.btn-voice.is-unavailable::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transform: rotate(-45deg);
}

.btn-voice:disabled {
  opacity: 0.8;
  cursor: not-allowed;
}

.input-shell #btn-send {
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.input-shell #btn-send svg {
  width: 1.05rem;
  height: 1.05rem;
  fill: currentColor;
}

.input-shell #btn-send:disabled {
  opacity: 0.5;
}

.voice-composer {
  margin-top: 0.55rem;
  display: grid;
  gap: 0.55rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid rgba(157, 98, 54, 0.16);
  border-radius: 16px;
  background: rgba(255, 250, 243, 0.72);
  min-width: 0;
  overflow-x: hidden;
}

.voice-composer-header {
  display: flex;
  justify-content: space-between;
  gap: 0.55rem;
  align-items: center;
  min-width: 0;
}

.voice-composer-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.voice-status-title {
  display: none;
}

.voice-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  padding: 0.22rem 0.48rem;
  border-radius: 999px;
  background: rgba(184, 103, 50, 0.12);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.voice-dismiss {
  min-height: 28px;
  padding: 0.18rem 0.58rem;
  border-radius: 999px;
  font-size: 0.74rem;
  line-height: 1;
}

.voice-status-copy {
  margin: -0.1rem 0 0;
  color: var(--muted);
  line-height: 1.35;
  font-size: 0.84rem;
}

.voice-transcript-live,
.voice-transcript-editor,
.voice-preview {
  width: 100%;
  max-width: 100%;
}

.voice-transcript-live {
  min-height: 52px;
  padding: 0.65rem 0.75rem;
  border: 1px dashed rgba(157, 98, 54, 0.2);
  border-radius: 14px;
  background: rgba(255, 252, 247, 0.64);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
}

.voice-transcript-live.is-recording::after {
  content: " REC";
  color: var(--danger);
  font-weight: 800;
}

.voice-preview {
  border-radius: 10px;
  height: 36px;
  min-width: 0;
}

.voice-transcript-editor-wrap {
  display: block;
  min-width: 0;
}

.voice-transcript-editor {
  width: 100%;
  min-height: 78px;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--input);
  color: var(--text);
  resize: vertical;
  box-shadow: none;
}

.voice-composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  min-width: 0;
  flex-wrap: wrap;
}

.voice-action {
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.voice-action svg {
  width: 1.05rem;
  height: 1.05rem;
  fill: currentColor;
}

.voice-composer.is-error {
  border-color: rgba(175, 79, 67, 0.28);
}

.voice-composer.is-recording {
  border-color: rgba(175, 79, 67, 0.3);
  box-shadow: 0 0 0 1px rgba(175, 79, 67, 0.08) inset;
}

.right-rail {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(249, 242, 230, 0.92), rgba(242, 233, 219, 0.96));
  backdrop-filter: blur(10px);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-height: 0;
  overflow: hidden;
  z-index: 10;
}

.rail-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-strong);
  padding: 0.7rem;
}

.rail-card h2 {
  margin: 0 0 0.45rem;
  font-size: 0.84rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.rail-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.metric {
  padding: 0.48rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 250, 244, 0.84);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  margin-bottom: 0.12rem;
}

.metric-label-icon {
  margin-bottom: 0.2rem;
}

.metric strong {
  font-size: 0.95rem;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.52rem;
  border: 1px solid var(--border);
  background: rgba(248, 241, 229, 0.96);
  color: var(--text);
  border-radius: 999px;
  padding: 0.25rem 0.64rem 0.25rem 0.3rem;
  cursor: pointer;
  max-width: 240px;
  min-height: 2.5rem;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #2e2012;
  font-weight: 800;
}

.user-name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* In partida, collapse the user chip to an avatar-only circle so the
   topbar-right reads as a row of uniform 2.5rem circular icons, matching
   the standard-layout pattern used by the other skins. The name stays
   visible in landing where there is more horizontal room. */
body[data-in-game="1"] .user-chip {
  width: 2.5rem;
  min-height: 2.5rem;
  max-width: 2.5rem;
  padding: 0;
  justify-content: center;
  gap: 0;
}
body[data-in-game="1"] .user-chip .user-name { display: none; }

.user-menu {
  position: absolute;
  top: 4.2rem;
  right: 1rem;
  z-index: 40;
  width: 220px;
  padding: 0.35rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(248, 241, 229, 0.98), rgba(240, 231, 217, 0.98));
  box-shadow: var(--shadow);
}

.user-menu button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 0.5rem 0.55rem;
  cursor: pointer;
}

.user-menu button:hover:not(:disabled) {
  background: rgba(238, 228, 211, 0.92);
}

.story-panel-overlay,
.games-drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 65;
  background: rgba(4, 8, 16, 0.5);
}

.story-panel {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 70;
  width: min(420px, 92vw);
  background: linear-gradient(180deg, rgba(248, 241, 229, 0.98), rgba(239, 230, 216, 0.98));
  border-right: 1px solid var(--border);
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  box-shadow: var(--shadow);
  animation: slideInLeft 220ms ease;
}

.story-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.story-panel-header h3 {
  margin: 0;
}

.story-panel-content {
  flex: 1;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.5;
  color: var(--text);
  background: rgba(255, 251, 245, 0.85);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem;
}

.briefing-modal {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: flex;
  justify-content: flex-start;
  align-items: stretch;
  padding: 1rem;
  background: rgba(4, 8, 16, 0.45);
  animation: fadeIn 200ms ease;
}

.briefing-panel {
  width: min(430px, 95vw);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(248, 241, 229, 0.98), rgba(240, 231, 217, 0.98));
  box-shadow: var(--shadow);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  animation: slideInLeft 260ms ease;
}

.briefing-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.briefing-header h2 {
  margin: 0;
  font-size: 1.02rem;
}

.briefing-section {
  border: 1px solid var(--border);
  background: rgba(255, 250, 244, 0.84);
  border-radius: 12px;
  padding: 0.65rem;
}

.briefing-section h3 {
  margin: 0 0 0.45rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.briefing-content {
  line-height: 1.48;
  color: var(--text);
}

.feedback-modal {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(4, 8, 16, 0.56);
  animation: fadeIn 200ms ease;
}

.feedback-panel {
  width: min(560px, 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(248, 241, 229, 0.98), rgba(240, 231, 217, 0.98));
  box-shadow: var(--shadow);
  padding: 1rem;
  display: grid;
  gap: 0.65rem;
}

.feedback-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.feedback-label {
  color: var(--muted);
  font-size: 0.84rem;
}

.feedback-text {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input);
  color: var(--text);
  padding: 0.72rem;
  line-height: 1.44;
}

.feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.char-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem;
  margin-bottom: 0.45rem;
  background: rgba(255, 250, 244, 0.82);
}

.char-item:last-child {
  margin-bottom: 0;
}

.sidebar-content dl {
  margin: 0;
}

.sidebar-content dt {
  color: var(--muted);
  font-weight: 600;
  margin-top: 0.25rem;
}

.sidebar-content dd {
  margin: 0 0 0 0.4rem;
}

.games-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  width: min(420px, 95vw);
  background: linear-gradient(180deg, rgba(248, 241, 229, 0.98), rgba(239, 230, 216, 0.98));
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.games-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.games-drawer-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  gap: 0.45rem;
}

.games-drawer-actions {
  border-top: 1px solid var(--border);
  padding-top: 0.55rem;
}

.game-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 250, 244, 0.9);
  color: var(--text);
  padding: 0.58rem;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.game-item:hover {
  border-color: rgba(157, 98, 54, 0.32);
  background: rgba(247, 238, 226, 0.96);
  transform: translateY(-1px);
}

.game-item.is-active {
  border-color: var(--accent);
}

.game-item-title {
  display: block;
  font-weight: 700;
  margin-bottom: 0.18rem;
}

.game-item-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.76rem;
  color: var(--muted);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 8, 16, 0.52);
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(248, 241, 229, 0.98), rgba(240, 231, 217, 0.98));
  border-radius: 14px;
  padding: 1.1rem;
}

.loading-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

.new-game-modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(4, 8, 16, 0.5);
}

.new-game-panel {
  width: min(560px, 100%);
  border-radius: 16px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(248, 241, 229, 0.98), rgba(240, 231, 217, 0.98));
  padding: 1rem;
  box-shadow: var(--shadow);
}

.new-game-help,
.standard-template-card p,
.games-list-state,
.loading-message,
.new-game-fields label,
.new-game-fields input::placeholder,
.standard-template-meta {
  color: var(--muted);
}

.new-game-fields input {
  width: 100%;
  background: var(--input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.58rem 0.7rem;
}

.new-game-step.hidden {
  display: none;
}

.new-game-mode-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.new-game-fields {
  display: grid;
  gap: 0.45rem;
}

.new-game-actions {
  margin-top: 0.95rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.new-game-actions .btn-secondary,
.new-game-mode-actions .btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.new-game-mode-actions .story-choice-button {
  justify-content: flex-start;
}

.standard-templates-list {
  max-height: 48vh;
  overflow-y: auto;
  display: grid;
  gap: 0.6rem;
}

.standard-template-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem;
  background: rgba(255, 250, 244, 0.88);
}

.standard-template-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(49, 213, 163, 0.25);
}

.standard-template-card h4 {
  margin: 0 0 0.35rem;
}

.template-muted {
  opacity: 0.52;
  pointer-events: none;
  filter: grayscale(0.35);
}

.template-status-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.12rem 0.45rem;
  font-size: 0.72rem;
  border-radius: 6px;
  background: var(--line);
  color: var(--muted);
  vertical-align: middle;
}

.standard-templates-divider {
  margin: 0.8rem 0 0.4rem;
  padding: 0.3rem 0;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  border-top: 1px solid var(--line);
}

body.theme-dark .login-screen {
  background: rgba(33, 26, 22, 0.34);
}

body.theme-dark .login-panel,
body.theme-dark .main,
body.theme-dark .landing-hero,
body.theme-dark .landing-games,
body.theme-dark .landing-how,
body.theme-dark .right-rail,
body.theme-dark .story-panel,
body.theme-dark .briefing-panel,
body.theme-dark .feedback-panel,
body.theme-dark .games-drawer,
body.theme-dark .loading-content,
body.theme-dark .new-game-panel {
  background: linear-gradient(180deg, rgba(93, 79, 71, 0.96), rgba(77, 66, 59, 0.98));
}

body.theme-dark .topbar {
  background: linear-gradient(180deg, rgba(88, 75, 67, 0.92), rgba(74, 64, 57, 0.94));
}

body.theme-dark .topbar-status,
body.theme-dark .theme-toggle,
body.theme-dark .language-toggle,
body.theme-dark .home-link,
body.theme-dark .user-chip,
body.theme-dark .story-choice-icon,
body.theme-dark .sheet-tag,
body.theme-dark .sheet-chip,
body.theme-dark .context-stream,
body.theme-dark .character-sheet-card,
body.theme-dark .chat-stage-brief-item,
body.theme-dark .story-empty-state,
body.theme-dark .chat-thinking,
body.theme-dark .metric,
body.theme-dark .story-panel-content,
body.theme-dark .briefing-section,
body.theme-dark .char-item,
body.theme-dark .game-item,
body.theme-dark .standard-template-card,
body.theme-dark .landing-game-item {
  background: rgba(112, 95, 85, 0.82);
}

body.theme-dark .theme-toggle:hover,
body.theme-dark .language-toggle:hover,
body.theme-dark .home-link:hover,
body.theme-dark .game-item:hover {
  background: rgba(127, 108, 96, 0.92);
}

body.theme-dark .language-menu {
  background: rgba(23, 27, 34, 0.98);
}

body.theme-dark .character-sheet-public-mission {
  border-color: rgba(211, 140, 79, 0.28);
  background: linear-gradient(180deg, rgba(112, 77, 47, 0.88), rgba(92, 62, 39, 0.8));
  color: #ffe0ba;
}

body.theme-dark .mission-public-block {
  border-top-color: rgba(215, 192, 166, 0.16);
}

body.theme-dark .landing-action-card,
body.theme-dark .landing-step,
body.theme-dark .dossier-sheet,
body.theme-dark .mission-card-primary {
  background: linear-gradient(180deg, rgba(108, 91, 81, 0.96), rgba(92, 78, 69, 0.98));
}

body.theme-dark .story-shell {
  background:
    linear-gradient(180deg, rgba(88, 75, 67, 0.88), rgba(74, 64, 57, 0.92)),
    linear-gradient(135deg, rgba(211, 140, 79, 0.08), transparent 40%);
}

body.theme-dark .voice-composer {
  background: rgba(110, 94, 84, 0.82);
  border-color: rgba(215, 192, 166, 0.16);
}

body.theme-dark .voice-status-badge {
  background: rgba(211, 140, 79, 0.18);
  color: #ffd3a9;
}

body.theme-dark .voice-transcript-live {
  background: rgba(94, 80, 71, 0.78);
  border-color: rgba(215, 192, 166, 0.22);
}

body.theme-dark .story-tab {
  background: linear-gradient(180deg, rgba(99, 84, 75, 0.96), rgba(84, 72, 65, 0.96));
  border-color: rgba(215, 192, 166, 0.18);
  box-shadow: inset 0 -8px 0 rgba(48, 36, 30, 0.2);
}

body.theme-dark .story-tab:hover {
  border-color: rgba(215, 192, 166, 0.3);
}

body.theme-dark .story-tab.is-active,
body.theme-dark .story-tab.is-active::after {
  background: rgba(120, 102, 91, 1);
}

body.theme-dark .landing-subtitle,
body.theme-dark .mission-copy,
body.theme-dark .msg-content,
body.theme-dark .briefing-content {
  color: var(--text);
}

body.theme-dark .landing-step-index,
body.theme-dark .mission-label {
  color: #f0bc88;
}

body.theme-dark .msg-system {
  background: rgba(120, 102, 91, 0.62);
}

body.theme-dark .msg-agent {
  background: rgba(111, 95, 85, 0.9);
}

body.theme-dark .msg-player {
  background: rgba(142, 112, 79, 0.9);
}

body.theme-dark .user-menu {
  background: linear-gradient(180deg, rgba(93, 79, 71, 0.98), rgba(78, 67, 60, 0.98));
}

body.theme-dark .user-menu button:hover:not(:disabled) {
  background: rgba(129, 110, 98, 0.36);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@keyframes rise {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes victoryPop {
  from {
    transform: translateY(-6px) scale(0.98);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes victoryGlow {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(49, 213, 163, 0);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(49, 213, 163, 0.12);
  }
}

@keyframes confettiRain {
  from {
    transform: translateY(-65%) rotate(10deg);
  }
  to {
    transform: translateY(65%) rotate(10deg);
  }
}

@keyframes slideInLeft {
  from {
    transform: translateX(-18px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sheet-body,
  .chat-stage-brief {
    grid-template-columns: 1fr;
  }

  .landing-grid,
  .landing-steps {
    grid-template-columns: 1fr 1fr;
  }

  .story-characters-grid {
    grid-template-columns: 1fr 1fr;
  }

  .right-rail {
    order: -1;
  }
}

@media (max-width: 760px) {
  #app {
    height: 100dvh;
    padding: 0.55rem;
    gap: 0.55rem;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.45rem;
    padding: 0.4rem 0.5rem;
    border-radius: 16px;
    backdrop-filter: none;
  }

  .topbar-left {
    display: flex;
    align-items: center;
  }

  .topbar-title-block {
    display: none;
  }

  .topbar-right {
    min-width: 0;
    justify-self: stretch;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 0.32rem;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    padding-bottom: 0.05rem;
  }

  .topbar-right::-webkit-scrollbar {
    display: none;
  }

  .topbar-status {
    display: none;
  }

  .home-link,
  .theme-toggle,
  .language-toggle,
  .skin-switcher-toggle,
  .user-chip,
  .topbar-action {
    min-height: 2.2rem;
    height: 2.2rem;
  }

  .home-link,
  .theme-toggle,
  .language-toggle,
  .skin-switcher-toggle {
    width: 2.2rem;
    min-width: 2.2rem;
    padding: 0;
  }
  .skin-switcher-toggle svg { width: 1rem; height: 1rem; }

  .topbar-action {
    padding: 0.35rem 0.62rem;
    font-size: 0.76rem;
    border-radius: 999px;
    white-space: nowrap;
  }

  #btn-new-game.topbar-action {
    padding-inline: 0.58rem;
  }

  .user-chip {
    max-width: 2.2rem;
    min-width: 2.2rem;
    width: 2.2rem;
    justify-content: center;
    padding: 0;
    gap: 0;
  }

  .user-name {
    display: none;
  }

  #btn-open-feedback,
  #btn-new-game {
    display: none;
  }

  .user-avatar {
    width: 1.7rem;
    height: 1.7rem;
    font-size: 0.76rem;
  }

  /* Topbar dropdown menus (skin/language) escape .topbar-right clipping:
     parent has overflow-x:auto/overflow-y:hidden for horizontal scroll, which
     would clip any absolutely-positioned descendant. Use fixed positioning
     anchored to the top-right of the viewport so the menu is always visible. */
  .skin-menu:not(.hidden),
  .language-menu:not(.hidden),
  .user-menu:not(.hidden) {
    position: fixed;
    top: 3.3rem;
    right: 0.55rem;
    left: auto;
    max-width: calc(100vw - 1.1rem);
    z-index: 1000;
  }

  .story-shell {
    padding: 0.7rem;
    gap: 0.55rem;
  }

  .story-tabs {
    gap: 0.14rem;
    padding: 0 0.08rem;
  }

  .story-tab {
    padding: 0.56rem 0.72rem 0.48rem;
    font-size: 0.84rem;
    transform: translateY(5px);
  }

  .dossier-sheet {
    padding: 0.8rem;
    border-radius: 20px;
  }

  .sheet-body,
  .story-characters-grid {
    grid-template-columns: 1fr;
  }

  .context-stream {
    padding: 0.85rem;
    font-size: 0.94rem;
    line-height: 1.62;
  }

  .mission-card-primary {
    padding: 0.92rem;
    border-radius: 20px;
  }

  .mission-copy {
    font-size: 0.98rem;
    line-height: 1.5;
  }

  .story-characters-grid {
    gap: 0.58rem;
  }

  .character-sheet-card {
    padding: 0.82rem;
    border-radius: 18px;
    gap: 0.5rem;
  }

  .character-sheet-card h3 {
    font-size: 0.98rem;
  }

  .character-sheet-card p {
    font-size: 0.9rem;
    line-height: 1.45;
  }

  .chat-stage-brief-item {
    padding: 0.68rem 0.8rem;
    border-radius: 16px;
  }

  .story-mission-inline {
    font-size: 0.92rem;
    line-height: 1.38;
  }

  .chat {
    padding: 0.8rem 0.08rem 0.32rem;
    gap: 0.58rem;
  }

  .msg {
    max-width: 96%;
    padding: 0.58rem 0.68rem;
  }

  .msg-content {
    font-size: 0.92rem;
    line-height: 1.38;
  }

  .landing-view {
    padding: 0.8rem;
  }

  .landing-grid,
  .landing-actions,
  .landing-steps {
    grid-template-columns: 1fr;
  }

  .landing-title {
    max-width: none;
    font-size: clamp(2.1rem, 12vw, 3.4rem);
  }

  .landing-subtitle,
  .landing-action-copy,
  .landing-step h3 {
    font-size: 0.94rem;
    line-height: 1.45;
  }

  .landing-games-header {
    flex-direction: column;
  }

  #btn-landing-custom,
  #btn-landing-standard,
  #btn-landing-all-games {
    width: 100%;
  }

  .landing-step {
    min-height: auto;
  }

  .msg {
    max-width: 92%;
  }

  .input-area {
    gap: 0.5rem;
  }

  .input-shell {
    padding-left: 0.75rem;
    padding-right: 0.3rem;
    border-radius: 14px;
  }

  .voice-composer {
    padding: 0.7rem;
  }

  .voice-composer-actions {
    justify-content: stretch;
  }

  .voice-action,
  .voice-composer-actions > button {
    flex: 1 1 calc(33.333% - 0.35rem);
    min-width: 0;
  }

  .voice-status-badge {
    margin-left: auto;
  }

  .right-rail {
    display: none;
  }

  .story-panel,
  .games-drawer,
  .briefing-panel,
  .feedback-panel {
    width: 100%;
    max-width: 100%;
  }

  .victory-overlay {
    padding: 0.75rem;
  }

  .victory-overlay-panel {
    min-height: min(72vh, 620px);
    border-radius: 18px;
    padding: 1.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .victory-overlay::before,
  .victory-overlay::after,
  .victory-overlay-panel,
  .victory-title,
  .msg {
    animation: none !important;
  }
}

/* ========== Skin switcher (shared chrome — appears in any skin) ========== */
.skin-switcher {
  position: relative;
  display: inline-flex;
}
.skin-switcher.hidden { display: none; }
.skin-switcher-toggle {
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(248, 241, 229, 0.96);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.skin-switcher-toggle:hover {
  background: rgba(247, 235, 215, 1);
  border-color: var(--accent);
}
.skin-switcher-toggle svg { width: 1.1rem; height: 1.1rem; fill: currentColor; }
body.theme-dark .skin-switcher-toggle {
  background: rgba(94, 80, 71, 0.9);
}
.skin-menu {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 50;
  min-width: 180px;
  padding: 0.3rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(248, 241, 229, 0.98), rgba(240, 231, 217, 0.98));
  box-shadow: var(--shadow);
}
body.theme-dark .skin-menu {
  background: linear-gradient(180deg, rgba(94, 80, 71, 0.98), rgba(82, 70, 62, 0.98));
}
.skin-menu.hidden { display: none; }
.skin-menu-item {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
  text-transform: capitalize;
}
.skin-menu-item:hover:not(:disabled) {
  background: rgba(238, 228, 211, 0.92);
}
body.theme-dark .skin-menu-item:hover:not(:disabled) {
  background: rgba(120, 100, 88, 0.6);
}
.skin-menu-item.is-active { font-weight: 700; }
.skin-menu-item-check {
  display: inline-flex;
  width: 16px;
  height: 16px;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}
.skin-menu-item-check svg { width: 14px; height: 14px; fill: currentColor; }

.user-menu-skins {
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border);
}
.user-menu-skins.hidden { display: none; }
.user-menu-section-label {
  margin: 0.25rem 0.55rem 0.3rem;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.user-menu-skins-list .skin-menu-item {
  padding: 0.45rem 0.55rem;
  font-size: 0.9rem;
}

#menu-feedback { display: none; }
@media (max-width: 760px) {
  #menu-feedback { display: block; }
}
