*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

html,
body {
  min-height: 100%;
}

body {
  line-height: 1.42;
}

img,
svg {
  display: block;
}

button,
input,
textarea,
select {
  font: inherit;
}

a {
  color: inherit;
}

main {
  width: 100%;
}

.page-shell {
  min-height: 100vh;
  padding: 0 14px 14px;
}

body.has-app-header .page-shell {
  margin-top: 0;
}

body.has-app-header .page-shell > .container {
  margin-top: 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0;
}

.header-shell {
  padding: 0 14px 6px;
}

.site-header {
  margin-bottom: 0;
  padding: 1px 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 4px;
}

.page-title {
  font-size: 1.9rem;
  line-height: 1.1;
}

.header-top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.header-brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 1.38rem;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: -0.02em;
}

.header-brand-logo {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  object-fit: contain;
}

.header-spacer {
  flex: 1;
}

.header-email {
  color: var(--muted);
  font-size: 0.92rem;
}

.header-credits {
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  padding: 3px 10px;
  background: var(--surface-raised, #f3f3f3);
  border: 1px solid var(--border);
  border-radius: 4px;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.header-credits--negative {
  color: #c0392b;
  border-color: #c0392b44;
  background: #c0392b11;
}

.header-subnav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 8px;
  margin-top: 0;
  padding-top: 6px;
  border-top: 1px solid rgba(15, 23, 42, 0.14);
}

.header-subnav-section {
  min-height: 36px;
}

.header-subnav-section-nav {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.header-subnav-section-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

.header-subnav-section-end {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.header-subnav-links {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.header-game-title {
  font-family: var(--font-sans);
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.1;
  text-align: center;
  color: var(--accent);
  background: rgba(99, 102, 241, 0.04);
  border-left: 3px solid var(--accent);
  padding: 6px 6px 6px 12px;
  border-radius: 4px;
  letter-spacing: 0.01em;
}

.header-subnav-section-end .game-intro-actions {
  margin-left: 0;
  justify-content: flex-end;
}

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

.nav-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-card {
  max-width: 620px;
  margin: 0 auto;
  padding: 18px;
}

.landing-hero {
  text-align: center;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 100px);
}

.landing-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.landing-title h1 {
  margin: 0;
  line-height: 1;
}

.landing-title-logo {
  width: 84px;
  height: 84px;
  flex: 0 0 auto;
  object-fit: contain;
}

.landing-login-form {
  width: min(280px, 100%);
  margin-top: 16px;
}

.landing-login-form input,
.landing-login-form .landing-cta-btn {
  min-height: 40px;
}

.landing-login-form .action-row {
  width: 100%;
}

.landing-cta-btn {
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: 0;
  width: 100%;
  justify-content: center;
}

.landing-notice {
  width: min(560px, 100%);
  background: transparent;
}

.landing-form-message {
  margin-top: 4px;
  width: 100%;
}

.landing-inline-feedback {
  width: 100%;
  min-height: 38px;
  margin: 4px 0 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  opacity: 0;
  transition: opacity 120ms ease;
}

.landing-inline-feedback.is-visible {
  opacity: 1;
}

.landing-inline-feedback.is-success {
  border-color: #86efac;
  background: #f0fdf4;
}

.landing-inline-feedback.is-error {
  border-color: #fca5a5;
  background: #fef2f2;
}

.form-grid {
  display: grid;
  gap: 10px;
}

label {
  font-size: 0.9rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.checkbox-row input[type="checkbox"] {
  width: auto;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.create-game-form {
  padding: 10px;
}

.create-game-form label {
  gap: 2px;
  font-size: 0.85rem;
}

.create-game-form input,
.create-game-form textarea,
.create-game-form select {
  padding: 6px 8px;
}

.create-game-form textarea {
  min-height: 72px;
}

.create-game-section {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.create-game-initial-grid {
  gap: 6px;
}

.create-game-title-meta {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  padding-bottom: 2px;
}

.create-game-slug-preview {
  margin: 0;
}

.create-game-characters-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 0;
}

.create-game-item {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  background: #fff;
}

.create-game-item .character-header {
  grid-column: 1 / -1;
  padding-bottom: 2px;
}

.create-game-span-2 {
  grid-column: 1 / -1;
}

.btn.small {
  padding: 3px 8px;
  font-size: 0.82rem;
}

.provider-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.provider-buttons {
  flex: 1;
}

.provider-feedback-slot {
  width: min(420px, 48%);
  min-height: 38px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  visibility: hidden;
}

.provider-feedback-slot.is-visible {
  visibility: visible;
}

.provider-feedback-slot.is-success {
  border-color: #86efac;
  background: #f0fdf4;
}

.provider-feedback-slot.is-error {
  border-color: #fca5a5;
  background: #fef2f2;
}

.notice {
  border-radius: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: #fff;
}

.notice.good {
  border-color: #86efac;
  background: #f0fdf4;
}

.notice.bad {
  border-color: #fca5a5;
  background: #fef2f2;
}

.cards-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.game-card {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-intro {
  padding: 10px 12px;
}

.game-intro-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.game-intro-copy {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: 1 1 420px;
  min-width: 0;
  flex-wrap: wrap;
}

.game-intro h2 {
  font-size: 1.35rem;
  margin: 0;
}

.game-intro p {
  color: var(--muted);
  margin: 0;
  flex: 1 1 320px;
}

.game-intro-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.game-intro-actions .notice {
  margin: 0;
}

.reset-modal-dialog {
  border: 0;
  padding: 0;
  margin: auto;
  width: min(440px, calc(100vw - 24px));
  background: transparent;
  overflow: visible;
}

.reset-modal-dialog[open] {
  position: fixed;
  inset: 0;
  max-height: fit-content;
}

.reset-modal-dialog::backdrop {
  background: rgba(15, 23, 42, 0.36);
  backdrop-filter: blur(1.5px);
}

.reset-modal-card {
  width: 100%;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reset-modal-card h3 {
  font-size: 1rem;
  margin: 0;
}

.reset-modal-message {
  margin: 0;
  color: var(--muted);
}

.reset-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  gap: 10px;
  min-height: 0;
}

.game-characters {
  display: flex;
  align-items: stretch;
  min-height: 0;
  overflow: hidden;
}

.character-panel {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.character-intro {
  padding: 8px 10px;
}

.character-intro p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.character-panel-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0;
}

.character-grid {
  display: grid;
  gap: 8px;
  width: 100%;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 150px;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  padding-right: 2px;
  align-content: start;
}

.character-summary {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 150px;
  text-align: left;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  transition: opacity 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.character-summary.is-active {
  border-color: var(--accent);
  background: var(--accent-subtle, #eef2ff);
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.12);
}

.character-summary.is-inactive {
  opacity: 0.62;
}

.character-summary:disabled {
  cursor: default;
}

.character-summary h4 {
  font-size: 1.03rem;
}

.character-summary p {
  color: var(--muted);
  font-size: 0.92rem;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.character-summary.is-blurred {
  filter: blur(3px);
  opacity: 0.65;
}


.character-id {
  font-size: 0.82rem;
  color: var(--muted);
}

.character-placeholder {
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  color: var(--muted);
  border-style: dashed;
}

.chat-panel {
  min-height: 0;
  padding: 0;
  display: flex;
  overflow: hidden;
}

.chat-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.chat-header {
  border-bottom: 2px solid var(--accent);
  padding: 8px 10px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.messages {
  overflow-y: auto;
  min-height: 0;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 8px 10px;
  max-width: 94%;
}

.message.user {
  align-self: flex-end;
  background: #fff7ed;
  border-color: #fdba74;
}

.message.character {
  align-self: flex-start;
  background: #f5f3ff;
  border-color: #c4b5fd;
}

.message.is-streaming {
  opacity: 0.94;
}

.message-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 3px;
}

.composer {
  border-top: 1px solid var(--border);
  padding: 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  position: relative;
  background: #fff;
}

.composer textarea {
  min-height: 64px;
  max-height: 180px;
}

.composer .btn {
  align-self: end;
}

.character-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.character-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.inline-meta {
  font-size: 0.84rem;
  color: var(--muted);
}

@media (max-width: 980px) {
  .game-layout {
    display: flex;
    flex-direction: column;
    min-height: auto;
    height: auto !important;
  }

  .chat-panel {
    order: -1;
    min-height: 56vh;
  }

  .game-characters {
    overflow: visible;
    align-items: stretch;
  }

  .character-panel {
    height: auto;
  }

  .character-grid {
    height: auto;
    overflow: visible;
    grid-auto-rows: 150px;
    align-content: start;
  }

  .character-placeholder {
    display: none;
  }
}

@media (max-width: 720px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 0;
  }

  .header-top-row {
    width: 100%;
  }

  .header-email {
    width: 100%;
    order: 3;
  }

  .header-spacer {
    display: none;
  }

  .header-subnav {
    grid-template-columns: 1fr;
    margin-top: 2px;
    padding-top: 8px;
  }

  .header-subnav-section {
    min-height: 0;
  }

  .provider-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .provider-feedback-slot {
    width: 100%;
  }

  .header-shell {
    padding: 0 10px 6px;
  }

  .page-shell {
    padding: 10px;
  }

  body.has-app-header .page-shell {
    margin-top: 0;
  }

  body.has-app-header .page-shell > .container {
    margin-top: 0;
  }

  .hero {
    padding-top: 52px;
  }
}

@media (min-width: 860px) {
  .create-game-initial-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .create-game-milestone-item,
  .create-game-character-item {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .game-intro-actions {
    width: 100%;
    margin-left: 0;
  }
}

/* Battery credit icon */
.battery-svg {
  cursor: pointer;
  width: 36px;
  height: 18px;
  background: none;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  color: var(--fg);
  flex: 0 0 auto;
}

.battery-svg svg {
  display: block;
}

/* Credit purchase modal */
.credit-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.credit-modal {
  min-width: 280px;
  padding: 24px;
  position: relative;
}

/* Collapsible intro band */
.intro-band {
  width: 100%;
  background: var(--surface-raised, #f3f3f3);
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
  margin-bottom: 8px;
}

.intro-band__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 14px;
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.intro-band__inner p {
  flex: 1;
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.intro-band__toggle {
  flex: 0 0 auto;
  align-self: flex-start;
}

.intro-pill {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface-raised, #f3f3f3);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.85rem;
  margin-bottom: 8px;
  font: inherit;
}

@media (min-width: 981px) {
  .game-page-shell {
    min-height: 0;
    overflow: hidden;
  }

  .game-page-container {
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    gap: 0;
  }
}
