:root {
  --bg: #020305;
  --bg-soft: #06080d;
  --bg-panel: rgba(5, 8, 12, 0.9);
  --bg-panel-strong: rgba(2, 5, 9, 0.96);
  --line: rgba(188, 202, 220, 0.22);
  --line-soft: rgba(188, 202, 220, 0.12);
  --text: #e8edf3;
  --text-soft: #b6c2cf;
  --text-muted: #8b98a7;
  --accent: #f0a563;
  --accent-soft: rgba(240, 165, 99, 0.25);
  --alert: #f0a563;
  --radius: 4px;
  --radius-lg: 6px;
  --shadow: rgba(0, 0, 0, 0.48);
  --transition: 220ms ease;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -20%, rgba(61, 88, 118, 0.18) 0%, transparent 45%),
    linear-gradient(180deg, #020305 0%, #03060b 52%, #010204 100%);
  letter-spacing: 0.015em;
}

#app {
  position: relative;
  min-height: 100vh;
  padding: 20px 26px calc(34px + env(safe-area-inset-bottom));
  overflow-x: hidden;
  overflow-y: auto;
}

.ambient-base {
  position: absolute;
  inset: -10% -10% auto;
  height: 70vh;
  background:
    radial-gradient(circle at 18% 22%, rgba(110, 132, 156, 0.14) 0%, transparent 52%),
    radial-gradient(circle at 80% 10%, rgba(67, 83, 101, 0.18) 0%, transparent 42%);
  filter: blur(24px);
  pointer-events: none;
  z-index: 0;
  animation: ambientShift 16s ease-in-out infinite;
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(224, 241, 255, 0.014) 0px,
    rgba(224, 241, 255, 0.014) 1px,
    transparent 2px,
    transparent 4px
  );
  mix-blend-mode: screen;
  opacity: 0.36;
  z-index: 0;
}

@keyframes ambientShift {
  0%,
  100% {
    transform: translateY(0) scale(1);
    opacity: 0.9;
  }
  50% {
    transform: translateY(-16px) scale(1.02);
    opacity: 0.62;
  }
}

main {
  position: relative;
  z-index: 2;
}

.hidden {
  display: none !important;
}

.screen {
  animation: fadeIn 320ms ease;
}

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

.topbar {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: auto auto auto;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(5, 8, 12, 0.94) 0%, rgba(3, 6, 10, 0.98) 100%);
  backdrop-filter: blur(10px);
  box-shadow: 0 14px 36px var(--shadow);
}

.brand-title {
  font-size: 18px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.brand-subtitle {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.13em;
}

.status-grid {
  display: flex;
  gap: 10px;
  align-items: center;
}

.status-item {
  min-width: 98px;
  border: 1px solid var(--line-soft);
  border-radius: 3px;
  padding: 6px 8px;
  background: rgba(6, 11, 16, 0.85);
}

.status-item span {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
}

.status-item strong {
  display: block;
  margin-top: 2px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
}

.top-controls {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

button,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--text);
  background: rgba(6, 10, 16, 0.88);
  padding: 9px 14px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}

button:hover {
  border-color: rgba(221, 171, 129, 0.64);
  background: rgba(13, 19, 27, 0.95);
}

button:active {
  transform: translateY(1px);
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary {
  border-color: rgba(240, 165, 99, 0.5);
  color: #ffd8ba;
  background: linear-gradient(180deg, rgba(47, 29, 15, 0.96), rgba(29, 18, 10, 0.98));
}

.ghost {
  background: rgba(7, 11, 17, 0.7);
}

.toggle.is-off {
  color: #ffd8ba;
  border-color: rgba(240, 165, 99, 0.62);
  background: rgba(44, 26, 14, 0.72);
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--bg-panel) 0%, rgba(4, 7, 11, 0.96) 100%);
  box-shadow: 0 18px 42px var(--shadow);
}

.screen-title {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(380px, 1.2fr);
  gap: 18px;
  align-items: stretch;
}

.title-controls,
.title-ideas {
  padding: 20px;
}

.title-ideas {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.title-ideas-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.title-ideas-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-ideas-header h2 {
  margin: 0;
  font-size: 20px;
  text-transform: uppercase;
}

.app-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.app-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex-shrink: 0;
}

.app-heading h1 {
  margin: 0;
  font-size: clamp(26px, 3.1vw, 36px);
  line-height: 1.05;
  color: var(--text);
  text-shadow: 0 0 14px rgba(240, 165, 99, 0.14);
}

.title-controls-subhead {
  margin: 0 0 12px;
  font-size: 20px;
  text-transform: uppercase;
}

.caption {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1 {
  margin: 8px 0 12px;
  font-size: clamp(27px, 3.2vw, 37px);
  line-height: 1.12;
  text-transform: uppercase;
}

.lead {
  margin: 0;
  color: var(--text-soft);
  line-height: 1.6;
}

.controls {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.mode-help {
  margin: 10px 0 0;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.45;
}

.mode-help strong {
  color: var(--text);
  font-weight: 600;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 3px;
  border: 1px solid var(--line-soft);
  background: rgba(5, 8, 13, 0.9);
  gap: 4px;
}

.segmented button {
  border: none;
  padding: 8px 13px;
  color: var(--text-muted);
  background: transparent;
}

.segmented button.is-active {
  color: var(--text);
  background: rgba(240, 165, 99, 0.24);
}

.divider {
  height: 1px;
  margin: 18px 0;
  background: linear-gradient(to right, transparent, var(--line), transparent);
}

label {
  display: block;
  margin-bottom: 7px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--text);
  background: rgba(2, 5, 9, 0.8);
  padding: 12px;
  resize: vertical;
  line-height: 1.4;
}

textarea:focus {
  outline: none;
  border-color: rgba(168, 199, 226, 0.42);
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.api-key-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--text);
  background: rgba(2, 5, 9, 0.8);
  padding: 12px;
  line-height: 1.4;
}

.api-key-input:focus {
  outline: none;
  border-color: rgba(168, 199, 226, 0.42);
}

.inline-link {
  color: #ffd8ba;
  text-underline-offset: 2px;
}

.screen-api-key {
  min-height: 74vh;
  display: grid;
  place-items: center;
}

.api-key-card {
  width: min(720px, 94vw);
  padding: 24px;
}

.card {
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  overflow: hidden;
  background: rgba(4, 8, 13, 0.82);
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.card:hover {
  border-color: rgba(240, 165, 99, 0.46);
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

.card-media {
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  display: block;
  background: rgba(12, 22, 32, 0.9);
}

.card-media-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 16;
  background: rgba(12, 22, 32, 0.9);
}

.card-media-wrap .card-media {
  width: 100%;
  height: 100%;
}

.card-media.is-pending {
  opacity: 0;
}

.card-media-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: linear-gradient(
    120deg,
    rgba(10, 18, 26, 0.86),
    rgba(12, 24, 36, 0.9),
    rgba(10, 18, 26, 0.86)
  );
}

.card-body {
  padding: 12px;
}

.card-title {
  font-size: 17px;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.card-body p {
  margin: 0 0 12px;
  color: var(--text-soft);
  line-height: 1.45;
}

.card-line {
  height: 10px;
  margin-top: 8px;
  border-radius: 999px;
  background: rgba(167, 190, 210, 0.15);
}

.placeholder {
  pointer-events: none;
}

.shimmer {
  position: relative;
  overflow: hidden;
}

.shimmer::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(208, 229, 243, 0.18), transparent);
  animation: shimmer 1.8s infinite;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

.screen-scene {
  display: grid;
  grid-template-columns: minmax(330px, 1.15fr) minmax(280px, 0.85fr);
  gap: 16px;
}

.scene-left {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.media-frame {
  position: relative;
  min-height: 350px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: rgba(5, 11, 17, 0.8);
}

.media-frame img,
.media-frame video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

#scene-image.is-pending {
  opacity: 0;
}

.media-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 13px;
}

.scene-image-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(8, 14, 22, 0.52);
  backdrop-filter: blur(2px);
  z-index: 2;
}

.story {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg-panel-strong);
  padding: 16px;
}

.scene-text p {
  margin: 0 0 10px;
  line-height: 1.6;
  color: #d3dde8;
}

.scene-right {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-content: start;
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 16px;
  text-transform: uppercase;
}

.actions {
  padding: 14px;
  grid-column: 1 / -1;
}

.skills-panel,
.inventory-panel {
  padding: 14px;
}

.action-list {
  display: grid;
  gap: 8px;
}

.action-submit-row {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.action-button {
  width: 100%;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: rgba(3, 7, 12, 0.86);
  color: var(--text);
  padding: 10px 12px;
  text-align: left;
  line-height: 1.35;
}

.action-button:hover {
  border-color: rgba(184, 214, 239, 0.44);
}

.skills-list,
.inventory-list {
  display: grid;
  gap: 8px;
}

.skill-row,
.inventory-row {
  border: 1px solid var(--line-soft);
  border-radius: 3px;
  padding: 10px;
  background: rgba(2, 6, 10, 0.84);
  transition: border-color var(--transition), background var(--transition);
}

.skill-row.is-changed,
.inventory-row.is-new,
.inventory-row.is-increased {
  border-color: rgba(240, 165, 99, 0.56);
  background: rgba(61, 38, 20, 0.35);
}

.skill-header,
.inventory-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.skill-name,
.inventory-name {
  font-size: 14px;
  text-transform: uppercase;
}

.skill-domain,
.inventory-count {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.skill-value {
  font-size: 13px;
  color: var(--text-soft);
}

.skill-delta {
  font-size: 11px;
  color: #b5d6f0;
}

.inventory-note {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.4;
}

.inventory-badge {
  display: inline-flex;
  margin-top: 6px;
  border: 1px solid rgba(173, 205, 230, 0.45);
  border-radius: 3px;
  padding: 2px 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #ffd8ba;
}

.empty-list {
  border: 1px dashed var(--line-soft);
  border-radius: 10px;
  padding: 10px;
  color: var(--text-muted);
  font-size: 12px;
}

.screen-loading {
  min-height: 70vh;
  display: grid;
  place-items: center;
}

.loader-layout {
  width: min(920px, 95vw);
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(280px, 1fr);
  gap: 14px;
}

.loader-layout.no-hints {
  width: min(520px, 95vw);
  grid-template-columns: minmax(320px, 520px);
  justify-content: center;
}

.loader-card {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 24px;
  background: rgba(3, 7, 12, 0.94);
  text-align: left;
}

.loader-grid {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.loader-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(165, 197, 224, 0.62);
  animation: pulse 1.1s infinite ease-in-out;
}

.loader-dot:nth-child(2) {
  animation-delay: 0.14s;
}

.loader-dot:nth-child(3) {
  animation-delay: 0.28s;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(0.72);
    opacity: 0.45;
  }
  50% {
    transform: scale(1);
    opacity: 1;
  }
}

.loader-text {
  margin-bottom: 8px;
  font-size: 18px;
  text-transform: uppercase;
}

.loader-subtext {
  margin: 0;
  color: var(--text-soft);
  line-height: 1.5;
}

.loading-hints-panel {
  padding: 20px;
}

.loading-hints-panel h3 {
  margin: 0 0 10px;
  font-size: 16px;
  text-transform: uppercase;
}

.loader-hints {
  margin: 0;
  padding-left: 18px;
  list-style: disc;
  display: grid;
  gap: 6px;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  padding: 10px 14px;
  border: 1px solid rgba(227, 180, 145, 0.5);
  border-radius: 3px;
  background: rgba(36, 24, 20, 0.92);
  color: #f7d3bc;
  z-index: 8;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(2, 6, 10, 0.72);
  backdrop-filter: blur(4px);
  z-index: 12;
}

.modal-card {
  width: min(520px, 92vw);
  border: 1px solid rgba(229, 165, 127, 0.4);
  border-radius: 4px;
  background: rgba(9, 15, 23, 0.96);
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.52);
  padding: 20px;
}

.modal-card h3 {
  margin: 0 0 10px;
  font-size: 20px;
  text-transform: uppercase;
}

.modal-card p {
  margin: 0;
  color: var(--text-soft);
  line-height: 1.55;
}

.metrics-card {
  border-color: var(--line);
}

.metrics-note {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.metrics-grid {
  margin-top: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  overflow: hidden;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.metric-row:last-child {
  border-bottom: none;
}

.metric-row span {
  color: var(--text-soft);
  font-size: 13px;
}

.metric-row strong {
  font-weight: 600;
}

.metric-row.total {
  background: rgba(137, 169, 198, 0.12);
}

.metrics-card h4 {
  margin: 16px 0 8px;
  font-size: 14px;
  color: var(--text);
  text-transform: uppercase;
}

.metrics-breakdown {
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 10px 12px;
  max-height: 200px;
  overflow: auto;
}

.metrics-breakdown-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(143, 175, 196, 0.1);
}

.metrics-breakdown-row:last-child {
  border-bottom: none;
}

.metrics-breakdown-row span {
  color: var(--text-soft);
  font-size: 13px;
}

.modal-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 1080px) {
  .screen-title,
  .screen-scene {
    grid-template-columns: 1fr;
  }

  .loader-layout {
    grid-template-columns: 1fr;
  }

  .loader-layout.no-hints {
    width: min(520px, 95vw);
    grid-template-columns: 1fr;
  }

  .topbar {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .scene-right {
    grid-template-columns: 1fr;
  }

  .actions {
    grid-column: auto;
  }

  .top-controls {
    justify-content: flex-start;
  }

  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  #app {
    padding: 14px 14px calc(42px + env(safe-area-inset-bottom));
  }

  .status-grid {
    width: 100%;
    justify-content: flex-start;
  }

  .top-controls {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .top-controls button {
    min-width: 0;
    padding: 8px 6px;
    font-size: 12px;
    line-height: 1.15;
    white-space: normal;
    text-align: center;
  }

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

  .title-ideas-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .title-ideas-meta {
    width: 100%;
    justify-content: space-between;
  }

  .action-submit-row {
    flex-direction: column;
    align-items: stretch;
  }
}
