:root {
  --background: #f8f5f0;
  --foreground: #171717;
  --muted-foreground: #666666;
  --panel: #ffffff;
  --border: #171717;
  --danger: #dc2626;
  --warn: #f59e0b;
  --success: #16a34a;
  --shadow: 12px 12px 0 0 rgba(0, 0, 0, 1);
  --shadow-soft: 0 14px 30px rgba(0, 0, 0, 0.12);
  --font-sans: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button {
  cursor: pointer;
  background: none;
  color: inherit;
}

.page-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
}

.app-shell {
  width: 100%;
  max-width: 520px;
  height: min(860px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  background: var(--background);
  border: 4px solid var(--border);
  box-shadow: var(--shadow);
  position: relative;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px;
  border-bottom: 4px solid var(--border);
  background: var(--foreground);
  color: var(--background);
}

.header-title,
.header-status {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-title h1 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1;
}

.status-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  opacity: 0.8;
}

.icon-wrap,
.icon-button svg,
.button-icon svg,
.inline-icon svg {
  width: 1em;
  height: 1em;
  display: inline-block;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-wrap {
  width: 20px;
  height: 20px;
}

.icon-button {
  border: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
  transition: opacity 0.18s ease;
}

.icon-button:hover {
  opacity: 1;
}

.app-main {
  flex: 1;
  min-height: 500px;
  display: flex;
  flex-direction: column;
  padding: 16px;
}

.screen-host,
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.screen {
  animation: screen-enter 0.24s ease;
}

.screen-intro {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 32px;
}

.intro-block {
  width: 100%;
}

.fingerprint-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 32px;
  border: 2px solid var(--border);
  display: grid;
  place-items: center;
  transform: rotate(45deg);
}

.fingerprint-mark .icon-wrap {
  width: 32px;
  height: 32px;
  transform: rotate(-45deg);
}

.screen h2,
.screen h3,
.screen h4 {
  font-family: var(--font-mono);
  text-transform: uppercase;
  margin: 0;
  letter-spacing: -0.02em;
}

.intro-title {
  font-size: clamp(2rem, 5vw, 2.6rem);
  font-weight: 800;
}

.intro-divider {
  width: 48px;
  height: 4px;
  background: var(--foreground);
  margin: 16px auto 0;
}

.intro-copy {
  margin: 16px auto 0;
  max-width: 320px;
  color: var(--muted-foreground);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.55;
  text-transform: uppercase;
}

.screen-meta {
  text-align: center;
}

.screen-meta h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.screen-meta p {
  margin: 4px 0 0;
  color: var(--muted-foreground);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
}

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

.scenario-list {
  margin-top: 20px;
}

.scenario-card {
  border: 2px solid var(--border);
  background: var(--background);
  padding: 12px;
  text-align: left;
  transition: background 0.18s ease, color 0.18s ease, transform 0.08s ease;
}

.scenario-card:hover,
.action-card:hover,
.ghost-button:hover,
.button.button-outline:hover {
  background: var(--foreground);
  color: var(--background);
}

.scenario-card:active,
.action-card:active,
.ghost-button:active,
.button:active {
  transform: translateY(1px);
}

.scenario-card.is-selected {
  background: var(--foreground);
  color: var(--background);
}

.scenario-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

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

.scenario-name {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 700;
  text-transform: uppercase;
}

.scenario-difficulty,
.status-chip,
.subtle-chip {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.difficulty-easy { color: var(--success); }
.difficulty-medium { color: #d97706; }
.difficulty-hard { color: #ea580c; }
.difficulty-very-hard { color: var(--danger); }

.scenario-card.is-selected .scenario-difficulty {
  color: inherit;
  opacity: 0.8;
}

.scenario-description {
  margin-top: 4px;
  opacity: 0.7;
  font-size: 10px;
  line-height: 1.35;
}

.scenario-time {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}

.scenario-best {
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 9px;
  opacity: 0.6;
  text-transform: uppercase;
}

.button,
.ghost-button,
.action-card {
  border: 2px solid var(--border);
  font-family: var(--font-mono);
  font-weight: 700;
  text-transform: uppercase;
  transition: background 0.18s ease, color 0.18s ease, transform 0.08s ease, opacity 0.18s ease;
}

.button {
  padding: 16px 24px;
  background: var(--foreground);
  color: var(--background);
}

.button:hover {
  opacity: 0.92;
}

.button.button-outline {
  background: var(--background);
  color: var(--foreground);
}

.button-full {
  width: 100%;
}

.button-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.button-spacer {
  margin-top: auto;
}

.game-topbar,
.result-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(23, 23, 23, 0.2);
  color: var(--muted-foreground);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.game-topbar strong,
.result-topbar strong {
  color: var(--foreground);
}

.game-topbar .scenario-time,
.result-topbar .scenario-time {
  color: inherit;
}

.scene-frame {
  position: relative;
  height: 160px;
  border: 2px solid var(--border);
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.scene-pattern {
  position: absolute;
  inset: 0;
  opacity: 0.05;
  background-image: radial-gradient(currentColor 1px, transparent 1px);
  background-size: 20px 20px;
  pointer-events: none;
}

.scene-effect {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 56px;
  line-height: 1;
  pointer-events: none;
  z-index: 30;
  animation: effect-pop 0.85s ease forwards;
}

.scene-actors {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100%;
  padding-bottom: 20px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 32px;
}

.actor {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.actor-label {
  margin-bottom: 4px;
  color: var(--muted-foreground);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.actor-emoji {
  font-size: 3rem;
  line-height: 1;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.08));
}

.actor-emoji.actor-human.is-calm {
  animation: breathe 3s ease-in-out infinite;
}

.actor-emoji.actor-human.is-alert {
  animation: subtle-shift 0.5s linear infinite;
}

.actor-emoji.actor-human.is-angry {
  animation: angry-shift 0.15s linear infinite;
}

.actor-emoji.actor-cat.cat-triggered {
  animation: cat-hop 0.3s ease;
  transform-origin: bottom center;
}

.scene-status {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  background: rgba(248, 245, 240, 0.8);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
}

.metrics-block {
  display: grid;
  gap: 10px;
}

.meter-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.meter-shell {
  width: 100%;
  height: 20px;
  padding: 2px;
  border: 2px solid var(--border);
  background: var(--background);
}

.meter-fill {
  height: 100%;
  width: 0;
  background: var(--foreground);
  transition: width 0.4s ease, background 0.25s ease;
}

.meter-fill.anger-mid {
  background: var(--warn);
}

.meter-fill.anger-high {
  background: var(--danger);
}

.danger-text {
  color: var(--danger);
}

.feed-zone {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted-foreground);
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
}

.feed-zone .is-live {
  color: var(--success);
  font-weight: 700;
}

.log-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  color: var(--muted-foreground);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.log-panel {
  position: relative;
  height: 72px;
  overflow-y: auto;
  padding: 8px;
  border: 2px solid var(--border);
  background: rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(1px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
}

.log-entry {
  display: flex;
  gap: 8px;
  font-weight: 500;
}

.log-entry.alert {
  color: #d97706;
}

.log-time {
  min-width: 70px;
  opacity: 0.5;
  flex-shrink: 0;
}

.action-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 12px;
}

.action-card {
  padding: 10px;
  text-align: left;
  background: var(--background);
  font-size: 10px;
}

.result-panel {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  border: 4px solid var(--border);
  text-align: center;
}

.result-panel.success {
  background: var(--foreground);
  color: var(--background);
}

.result-emoji {
  position: relative;
  z-index: 10;
  font-size: 3.75rem;
  line-height: 1;
  animation: result-pop 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.result-title {
  position: relative;
  z-index: 10;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.25;
}

.result-copy {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 280px;
  padding-top: 12px;
  margin-top: 4px;
  border-top: 1px solid rgba(23, 23, 23, 0.3);
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.result-panel.success .result-copy {
  border-top-color: rgba(248, 245, 240, 0.3);
}

.result-copy .caption {
  margin-bottom: 4px;
  font-size: 12px;
  opacity: 0.7;
}

.result-copy p {
  margin: 8px 0 0;
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 1.45;
  text-transform: none;
  opacity: 0.75;
}

.result-fingerprint {
  position: absolute;
  right: -40px;
  bottom: -40px;
  width: 176px;
  height: 176px;
  opacity: 0.05;
  pointer-events: none;
}

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

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 90px;
  padding: 12px;
  border: 2px solid var(--border);
  font-family: var(--font-mono);
}

.stat-card.alt {
  background: #f1ede6;
}

.stat-label {
  margin-bottom: 4px;
  color: var(--muted-foreground);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
}

.stat-value.smaller {
  font-size: 1.6rem;
}

.stat-sub {
  margin-top: 2px;
  font-size: 9px;
  text-transform: uppercase;
  opacity: 0.6;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 2px dashed var(--border);
}

.ghost-button {
  background: var(--background);
  padding: 16px;
}

.ghost-button:hover {
  background: #ebe6dd;
  color: var(--foreground);
}

.app-footer {
  padding: 8px;
  border-top: 2px solid var(--border);
  color: var(--muted-foreground);
  font-family: var(--font-mono);
  font-size: 10px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 100;
  display: grid;
  gap: 8px;
  width: min(320px, calc(100vw - 32px));
}

.toast {
  border: 2px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow-soft);
  padding: 12px;
  animation: toast-in 0.2s ease;
}

.toast.destructive {
  background: #fff1f2;
}

.toast-title {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.toast-copy {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.4;
}

.scanlines::before {
  content: " ";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.05) 50%),
    linear-gradient(90deg, rgba(255, 0, 0, 0.02), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.02));
  background-size: 100% 4px, 3px 100%;
  pointer-events: none;
  opacity: 0.6;
  z-index: 50;
}

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
  border-left: 2px solid var(--border);
}

::-webkit-scrollbar-thumb {
  background: var(--foreground);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted-foreground);
}

.scene-shake {
  animation: scene-shake 0.3s ease;
}

.scene-flash {
  animation: scene-flash 0.2s ease;
}

.icon-pulse {
  animation: pulse 1.25s ease-in-out infinite;
}

@keyframes screen-enter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes scene-shake {
  0% { transform: translate(0, 0); }
  20% { transform: translate(3px, -2px); }
  40% { transform: translate(-3px, 2px); }
  60% { transform: translate(2px, 1px); }
  80% { transform: translate(-2px, -1px); }
  100% { transform: translate(0, 0); }
}

@keyframes scene-flash {
  0% { filter: brightness(1); }
  50% { filter: brightness(1.35); }
  100% { filter: brightness(1); }
}

@keyframes effect-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8) rotate(var(--effect-rotate, 0deg));
  }
  25% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.15) rotate(var(--effect-rotate, 0deg));
  }
  65% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(var(--effect-rotate, 0deg));
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9) rotate(var(--effect-rotate, 0deg));
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

@keyframes subtle-shift {
  0%, 100% { transform: translateX(-1px); }
  50% { transform: translateX(1px); }
}

@keyframes angry-shift {
  0%, 100% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
}

@keyframes cat-hop {
  0% { transform: scale(1) translateY(0) rotate(0deg); }
  40% { transform: scale(1.1) translateY(-15px) rotate(-5deg); }
  70% { transform: scale(1.08) translateY(-8px) rotate(5deg); }
  100% { transform: scale(1) translateY(0) rotate(0deg); }
}

@keyframes result-pop {
  0% {
    opacity: 0;
    transform: scale(0) rotate(0deg);
  }
  70% {
    opacity: 1;
    transform: scale(1.08) rotate(-10deg);
  }
  85% {
    transform: scale(1.02) rotate(10deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

@keyframes log-enter {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@media (min-width: 640px) {
  .page-shell {
    padding: 32px;
  }

  .app-main {
    padding: 24px;
  }

  .header-title h1 {
    font-size: 1rem;
  }

  .scenario-card,
  .result-panel,
  .stat-card {
    padding: 16px;
  }

  .action-card {
    padding: 12px;
    font-size: 12px;
  }

  .result-title {
    font-size: 1.25rem;
  }

  .result-actions {
    flex-direction: row;
  }

  .result-actions > * {
    flex: 1;
  }
}
