:root {
  color-scheme: light;
  --ink: #18202b;
  --muted: #667184;
  --line: #d8d4c7;
  --paper: #f7f5ee;
  --panel: #fffefa;
  --washi: #fbfaf4;
  --shoji-line: rgba(127, 110, 77, 0.16);
  --shoji-soft: rgba(255, 255, 255, 0.56);
  --teal: #126b65;
  --coral: #b94b3c;
  --amber: #9b6b12;
  --blue: #2e5d91;
  --shadow: 0 12px 28px rgba(53, 43, 26, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  height: 100%;
  min-height: 100vh;
  overflow: hidden;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(90deg, var(--shoji-line) 1px, transparent 1px),
    linear-gradient(var(--shoji-line) 1px, transparent 1px),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.38) 0 2px, transparent 2px 16px);
  background-size: 92px 92px, 92px 92px, 18px 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdf7;
  color: var(--ink);
  min-height: 38px;
  padding: 0 12px;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(78, 66, 42, 0.04);
}

button:hover {
  border-color: #9aa6b8;
}

button.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: white;
}

button.danger {
  border-color: #c88b82;
  color: #7a2419;
}

button.ghost {
  background: transparent;
}

:focus-visible {
  outline: 2px solid rgba(18, 107, 101, 0.35);
  outline-offset: 2px;
}

.app-shell {
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 410px) minmax(0, 1fr);
  overflow: hidden;
}

.auth-root {
  min-height: 100dvh;
}

.auth-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(100%, 420px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-panel p {
  margin: 8px 0 20px;
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-form .field {
  display: grid;
  gap: 7px;
}

.auth-form input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 11px;
  background: #fffef9;
}

.logout-button {
  width: 100%;
  margin-top: 12px;
}

.sidebar {
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background-color: var(--washi);
  background-image:
    linear-gradient(90deg, rgba(127, 110, 77, 0.09) 1px, transparent 1px),
    linear-gradient(rgba(127, 110, 77, 0.08) 1px, transparent 1px);
  background-size: 46px 46px;
}

.sidebar-header,
.detail-header,
.report-header {
  flex: none;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.82);
  backdrop-filter: blur(6px);
}

.sidebar-header {
  z-index: 4;
}

.detail-header,
.report-header {
  position: sticky;
  top: 0;
  z-index: 3;
  box-shadow: 0 1px 0 rgba(78, 66, 42, 0.06);
}

.sidebar-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.15;
  letter-spacing: 0;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 24px;
}

h3 {
  font-size: 16px;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.meta-warning {
  color: var(--coral);
  font-weight: 700;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 9px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.pill.teal {
  border-color: #b9d8d4;
  color: var(--teal);
}

.pill.coral {
  border-color: #e6bbb4;
  color: var(--coral);
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.search-row input,
.form-grid input:not([type="range"]):not([type="checkbox"]),
.form-grid textarea,
.form-grid select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffef9;
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78);
}

.search-row input,
.form-grid input:not([type="range"]):not([type="checkbox"]),
.form-grid select {
  height: 40px;
  padding: 0 11px;
}

.form-grid textarea {
  min-height: 120px;
  resize: vertical;
  padding: 10px 11px;
}

.search-row input:focus,
.form-grid input:not([type="range"]):not([type="checkbox"]):focus,
.form-grid textarea:focus,
.form-grid select:focus {
  border-color: rgba(18, 107, 101, 0.56);
}

.scenario-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.persona-card {
  width: 100%;
  min-height: 126px;
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  text-align: left;
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(20, 28, 38, 0.05);
  overflow: hidden;
}

.persona-card.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(18, 107, 101, 0.14);
}

.portrait {
  width: 86px;
  height: 86px;
  border-radius: 8px;
  overflow: hidden;
  background: #eceff4;
  border: 1px solid var(--line);
  flex: none;
}

.portrait img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.portrait-sprite {
  background-repeat: no-repeat;
}

.card-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
  overflow: hidden;
}

.card-copy h3 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 15px;
  min-width: 0;
}

.card-name,
.scenario-id {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-copy .card-category {
  flex: 0 1 auto;
  max-width: 46%;
  justify-content: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scenario-id {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.card-copy p {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: #3d4858;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.card-copy .meta-line {
  flex-wrap: nowrap;
  gap: 6px;
  margin-top: 0;
  overflow: hidden;
  white-space: nowrap;
}

.card-copy .meta-line span {
  flex: 0 0 auto;
}

.content {
  min-width: 0;
  min-height: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.detail,
.report {
  min-height: 100%;
  background-color: rgba(255, 254, 250, 0.94);
  background-image:
    linear-gradient(90deg, rgba(127, 110, 77, 0.07) 1px, transparent 1px),
    linear-gradient(rgba(127, 110, 77, 0.06) 1px, transparent 1px);
  background-size: 68px 68px;
}

.detail-body,
.report-body {
  flex: none;
  padding: 20px;
}

.detail-body > .live-panel {
  margin-top: 0;
  margin-bottom: 18px;
}

.detail-hero {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.detail-hero .portrait {
  width: 150px;
  height: 150px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.detail-actions {
  margin-top: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 20px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: #3f4a59;
  font-size: 12px;
  font-weight: 700;
}

.field small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.checkbox-control {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin: 22px 0 0;
  color: #3f4a59;
}

.checkbox-control input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
  flex: 0 0 auto;
}

.checkbox-control span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slider-control {
  min-height: 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffef9;
  padding: 0 10px;
}

.slider-control input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

.slider-control output {
  color: var(--teal);
  font-size: 13px;
  font-weight: 700;
  text-align: right;
}

.status-strip {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.88);
  padding: 12px;
}

.status-strip strong {
  display: block;
  margin-bottom: 8px;
}

.status-strip ul,
.report-list {
  margin: 0;
  padding-left: 18px;
}

.live-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.94);
  overflow: hidden;
}

.live-panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.9);
}

.live-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 220px;
  background: #111820;
}

.live-stage img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.live-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  color: #d8dee8;
  font-size: 14px;
}

.live-placeholder[hidden] {
  display: none;
}

.live-controls,
.live-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.live-controls label,
.volume-control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #3f4a59;
  font-size: 13px;
}

.live-controls input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.live-controls input[type="range"] {
  width: 130px;
}

.live-status-row {
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.live-status-row [data-testid="live-error"] {
  color: var(--coral);
}

.live-health-grid {
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) minmax(240px, 2fr);
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  color: #3f4a59;
  font-size: 12px;
}

.live-health-grid div {
  display: grid;
  gap: 4px;
}

.live-health-grid b {
  color: var(--ink);
  font-size: 11px;
  text-transform: uppercase;
}

.live-log-list {
  max-height: 132px;
  overflow: auto;
  margin: 0;
  padding: 10px 12px 10px 28px;
  border-top: 1px solid var(--line);
  color: #3f4a59;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.live-log-list li + li {
  margin-top: 4px;
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.metric b {
  display: block;
  font-size: 28px;
  color: var(--teal);
}

.metric span,
.metric strong {
  display: block;
}

.metric span {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  overflow-wrap: anywhere;
}

.report-section {
  border-top: 1px solid var(--line);
  padding: 18px 0;
}

.report-section h3 {
  margin-bottom: 10px;
}

.coverage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.coverage-table th,
.coverage-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

.quote {
  border-left: 4px solid var(--amber);
  margin: 10px 0;
  padding: 8px 12px;
  background: #fffaf0;
}

.empty-state {
  display: grid;
  place-content: center;
  min-height: 100%;
  padding: 30px;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(520px, calc(100vw - 36px));
  border-radius: 8px;
  background: #18202b;
  color: white;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  z-index: 5;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(250px, 42dvh) minmax(0, 1fr);
    height: 100dvh;
  }

  .sidebar {
    height: 100%;
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .content {
    height: 100%;
  }

  .sidebar-header,
  .detail-header,
  .report-header {
    position: static;
  }

  .detail-hero,
  .form-grid,
  .report-grid {
    grid-template-columns: 1fr;
  }

  .detail-hero .portrait {
    width: 120px;
    height: 120px;
  }
}
