:root {
  --bg: #050816;
  --panel: rgba(10, 17, 36, 0.85);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #eaf2ff;
  --muted: #9fb3d9;
  --accent: #4fd1ff;
  --accent-2: #8b5cf6;
  --good: #34d399;
  --warn: #f59e0b;
  --bad: #f87171;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 16% 6%, #1a3b5f 0%, #070f24 44%, #040711 100%);
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
}

.portal-hero {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  align-items: center;
  gap: 0.95rem;
  width: min(1240px, calc(100% - 2rem));
  margin: 1rem auto 0.9rem;
  padding: 1rem 1.1rem;
  border-radius: 18px;
  border: 1px solid rgba(154, 218, 248, 0.25);
  background: linear-gradient(130deg, rgba(9, 20, 36, 0.86), rgba(20, 52, 82, 0.58)),
    url("../img/med-grid.svg");
  background-size: cover, 230px;
  background-repeat: no-repeat, repeat;
  box-shadow: 0 16px 34px rgba(4, 11, 20, 0.32);
  overflow: hidden;
}

.portal-copy {
  position: relative;
  z-index: 1;
}

.portal-eyebrow {
  margin: 0;
  color: #8be8ff;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.portal-hero h1 {
  margin: 0.2rem 0 0;
  font-family: "Sora", "Space Grotesk", sans-serif;
  font-size: clamp(1.8rem, 4.6vw, 2.9rem);
}

.portal-subtitle {
  margin: 0.4rem 0 0;
  color: #b8cce7;
  line-height: 1.46;
  max-width: 74ch;
}

.portal-link-wrap {
  margin: 0.55rem 0 0;
}

.portal-link {
  color: #87f2d9;
  text-decoration: none;
  font-weight: 700;
}

.portal-link:hover {
  text-decoration: underline;
}

.portal-art {
  margin: 0;
  width: min(100%, 420px);
  justify-self: end;
  filter: drop-shadow(0 14px 24px rgba(3, 10, 18, 0.45));
}

.portal-art img {
  display: block;
  width: 100%;
  height: auto;
}

input,
textarea,
select,
[contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-touch-callout: default;
}

#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.game-shell {
  position: relative;
  z-index: 1;
  width: min(1240px, calc(100% - 2rem));
  margin: 0 auto 1.6rem;
  min-height: calc(100dvh - 2.4rem);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: filter 0.22s ease, transform 0.22s ease;
}

.game-shell.tone-good {
  filter: drop-shadow(0 0 22px rgba(52, 211, 153, 0.22));
}

.game-shell.tone-warn {
  filter: drop-shadow(0 0 22px rgba(245, 158, 11, 0.22));
}

.game-shell.tone-bad {
  filter: drop-shadow(0 0 22px rgba(248, 113, 113, 0.24));
}

.game-shell.shake {
  animation: shellShake 0.34s linear;
}

@keyframes shellShake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-4px);
  }
  40% {
    transform: translateX(3px);
  }
  60% {
    transform: translateX(-2px);
  }
  80% {
    transform: translateX(2px);
  }
}

body.compact-fx .game-shell.tone-good {
  filter: drop-shadow(0 0 14px rgba(52, 211, 153, 0.2));
}

body.compact-fx .game-shell.tone-warn {
  filter: drop-shadow(0 0 14px rgba(245, 158, 11, 0.2));
}

body.compact-fx .game-shell.tone-bad {
  filter: drop-shadow(0 0 14px rgba(248, 113, 113, 0.22));
}

body.compact-fx .game-shell.shake {
  animation-duration: 0.28s;
}

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

.hud-item {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 0.9rem;
  padding: 0.75rem 1rem;
  backdrop-filter: blur(7px);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.hud-item .label {
  font-size: 0.8rem;
  color: var(--muted);
}

.hud-item .value {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.hud-item .value.hud-pop {
  animation: hudPop 0.34s ease;
}

.hud-item .value.hud-good {
  color: #9cf4cf;
}

.hud-item .value.hud-warn {
  color: #ffe08f;
}

.hud-item .value.hud-bad {
  color: #ffc3c3;
}

@keyframes hudPop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.11);
  }
  100% {
    transform: scale(1);
  }
}

.hud-item.timer.low-time .value {
  color: #ffe082;
  animation: pulseTimer 1s infinite;
}

@keyframes pulseTimer {
  0%,
  100% {
    transform: scale(1);
    text-shadow: 0 0 8px rgba(255, 225, 128, 0.4);
  }
  50% {
    transform: scale(1.06);
    text-shadow: 0 0 16px rgba(255, 225, 128, 0.75);
  }
}

.game-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, 1.08fr);
  grid-template-areas:
    "scene case"
    "log case";
  align-items: start;
  gap: 0.82rem;
  flex: 1;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 1rem;
  padding: 1rem;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  min-height: auto;
  position: relative;
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.28), transparent);
  pointer-events: none;
}

.scene-panel {
  grid-area: scene;
  min-height: 440px;
}

.case-panel {
  grid-area: case;
  min-height: 545px;
}

.log-panel {
  grid-area: log;
  min-height: 270px;
}

.scene-header h1,
.scene-header h2 {
  margin: 0;
  font-size: 1.5rem;
}

.scene-header p {
  margin: 0.35rem 0 0.9rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.scene-box {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.9rem;
  background: linear-gradient(160deg, rgba(79, 209, 255, 0.12), rgba(139, 92, 246, 0.08));
  padding: 1rem;
  overflow: hidden;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.scene-box::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    110deg,
    transparent 0%,
    rgba(255, 255, 255, 0.08) 30%,
    rgba(79, 209, 255, 0.08) 50%,
    transparent 74%
  );
  transform: translateX(-120%);
  animation: sceneScan 6.8s linear infinite;
  pointer-events: none;
  z-index: 0;
}

.scene-box::after {
  content: "";
  position: absolute;
  inset: -50%;
  background: conic-gradient(from 90deg, transparent, rgba(79, 209, 255, 0.2), transparent);
  animation: rotateHalo 10s linear infinite;
  pointer-events: none;
  z-index: 0;
}

.scene-box > * {
  position: relative;
  z-index: 1;
}

body.compact-fx .scene-box::before {
  animation-duration: 8.4s;
  opacity: 0.65;
}

@keyframes sceneScan {
  to {
    transform: translateX(120%);
  }
}

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

.ambulance-lane {
  position: absolute;
  top: 0.7rem;
  left: 0.8rem;
  right: 0.8rem;
  height: 32px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.ambulance {
  position: absolute;
  top: 3px;
  left: -36px;
  font-size: 1.3rem;
  animation: drive 7s linear infinite;
}

@keyframes drive {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(calc(100% + 72px));
  }
}

.patient-avatar {
  position: relative;
  margin: 3.25rem auto 1.2rem;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 25% 20%, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.patient-avatar.mood-good {
  animation: avatarRelief 0.5s ease;
}

.patient-avatar.mood-warn {
  animation: avatarWarn 0.5s ease;
}

.patient-avatar.mood-bad {
  animation: avatarBad 0.5s ease;
}

@keyframes avatarRelief {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(52, 211, 153, 0);
  }
  40% {
    transform: scale(1.04);
    box-shadow: 0 0 26px rgba(52, 211, 153, 0.25);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(52, 211, 153, 0);
  }
}

@keyframes avatarWarn {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.03);
    box-shadow: 0 0 22px rgba(245, 158, 11, 0.22);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(245, 158, 11, 0);
  }
}

@keyframes avatarBad {
  0% {
    transform: translateX(0);
    box-shadow: 0 0 0 rgba(248, 113, 113, 0);
  }
  22% {
    transform: translateX(-3px);
  }
  44% {
    transform: translateX(2px);
    box-shadow: 0 0 28px rgba(248, 113, 113, 0.26);
  }
  100% {
    transform: translateX(0);
    box-shadow: 0 0 0 rgba(248, 113, 113, 0);
  }
}

.avatar-emoji {
  font-size: 3rem;
  z-index: 3;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.25));
}

.pulse-ring {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  border: 1px solid rgba(79, 209, 255, 0.45);
  animation: pulseRing 2.2s infinite;
}

body.compact-fx .pulse-ring {
  animation-duration: 2.75s;
}

.pulse-ring.ring-2 {
  animation-delay: 0.6s;
}

.pulse-ring.ring-3 {
  animation-delay: 1.2s;
}

@keyframes pulseRing {
  0% {
    transform: scale(0.88);
    opacity: 0.7;
  }
  100% {
    transform: scale(1.65);
    opacity: 0;
  }
}

.stability-wrap {
  position: relative;
  z-index: 2;
}

.stability-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.stability-bar {
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

#stabilityFill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #22c55e, #a3e635);
  transition: width 0.25s linear, filter 0.25s;
}

.status-strip {
  margin-top: 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.65rem;
  border-radius: 999px;
  background: rgba(79, 209, 255, 0.13);
  border: 1px solid rgba(79, 209, 255, 0.35);
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.badge.pulse {
  animation: badgePulse 0.38s ease;
}

@keyframes badgePulse {
  0% {
    transform: scale(0.98);
  }
  45% {
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}

body.compact-fx .badge.pulse {
  animation-duration: 0.28s;
}

.controls {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
  gap: 0.58rem;
  position: relative;
  z-index: 4;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 0.7rem;
  padding: 0.7rem 1rem;
  font-weight: 700;
  color: #03111b;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

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

.btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

.btn-primary {
  background: linear-gradient(110deg, var(--accent), #39e3d0);
}

.btn-secondary {
  color: var(--text);
  background: linear-gradient(110deg, #2a3558, #202848);
}

.btn-toggle {
  min-width: 118px;
}

.btn-toggle.active {
  border: 1px solid rgba(79, 209, 255, 0.45);
  box-shadow: 0 0 0 2px rgba(79, 209, 255, 0.14) inset;
}

.btn-toggle.muted {
  opacity: 0.78;
}

.panel-title h2 {
  margin: 0;
  font-size: 1.15rem;
}

.case-panel {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.case-card {
  margin-top: 0.3rem;
  border-radius: 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
  padding: 0.82rem;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color 0.25s, transform 0.25s;
  scrollbar-gutter: stable;
}

.case-card.entry {
  animation: caseEntry 0.44s cubic-bezier(0.2, 0.85, 0.25, 1);
}

.case-card.entry-followup {
  animation: caseFollowup 0.44s cubic-bezier(0.2, 0.85, 0.25, 1);
}

.case-card.resolve-good {
  animation: caseResolveGood 0.45s ease;
}

.case-card.resolve-partial {
  animation: caseResolvePartial 0.45s ease;
}

.case-card.resolve-bad {
  animation: caseResolveBad 0.5s ease;
}

body.compact-fx .case-card.entry,
body.compact-fx .case-card.entry-followup {
  animation-duration: 0.34s;
}

body.compact-fx .case-card.resolve-good,
body.compact-fx .case-card.resolve-partial,
body.compact-fx .case-card.resolve-bad {
  animation-duration: 0.36s;
}

@keyframes caseEntry {
  0% {
    transform: translateY(10px) scale(0.985);
    opacity: 0.4;
    border-color: rgba(79, 209, 255, 0.15);
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes caseFollowup {
  0% {
    transform: translateY(8px) scale(0.99);
    opacity: 0.5;
    box-shadow: 0 0 0 rgba(245, 158, 11, 0);
  }
  60% {
    box-shadow: 0 0 24px rgba(245, 158, 11, 0.18);
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
    box-shadow: 0 0 0 rgba(245, 158, 11, 0);
  }
}

@keyframes caseResolveGood {
  0% {
    box-shadow: 0 0 0 rgba(52, 211, 153, 0);
  }
  50% {
    box-shadow: 0 0 26px rgba(52, 211, 153, 0.24);
  }
  100% {
    box-shadow: 0 0 0 rgba(52, 211, 153, 0);
  }
}

@keyframes caseResolvePartial {
  0% {
    box-shadow: 0 0 0 rgba(245, 158, 11, 0);
  }
  50% {
    box-shadow: 0 0 22px rgba(245, 158, 11, 0.2);
  }
  100% {
    box-shadow: 0 0 0 rgba(245, 158, 11, 0);
  }
}

@keyframes caseResolveBad {
  0% {
    box-shadow: 0 0 0 rgba(248, 113, 113, 0);
  }
  35% {
    box-shadow: 0 0 30px rgba(248, 113, 113, 0.24);
  }
  100% {
    box-shadow: 0 0 0 rgba(248, 113, 113, 0);
  }
}

.case-card h3 {
  margin: 0 0 0.45rem;
  font-size: 1.1rem;
}

.case-card p {
  margin: 0;
  color: #d6e2ff;
  line-height: 1.5;
  font-size: 0.87rem;
}

.case-sticky-head {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.mobile-case-dock {
  display: none;
}

.case-meta {
  display: none;
}

.case-chip {
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 0.22rem 0.55rem;
  font-size: 0.72rem;
  color: #d9ebff;
  background: rgba(255, 255, 255, 0.05);
}

.case-chip.diff-easy {
  border-color: rgba(52, 211, 153, 0.5);
  color: #95f5ce;
}

.case-chip.diff-medium {
  border-color: rgba(79, 209, 255, 0.52);
  color: #a7eaff;
}

.case-chip.diff-hard {
  border-color: rgba(245, 158, 11, 0.58);
  color: #ffd18a;
}

.case-chip.diff-critical {
  border-color: rgba(248, 113, 113, 0.62);
  color: #ffc3c3;
}

.case-data-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.42rem;
}

.case-block {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.6rem;
  padding: 0.42rem 0.46rem;
  background: rgba(255, 255, 255, 0.02);
}

.case-block h4 {
  margin: 0 0 0.35rem;
  color: #9fc0eb;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.identity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
}

.identity-list li {
  border-radius: 0.46rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.03);
  padding: 0.3rem 0.42rem;
  font-size: 0.74rem;
  color: #d5e8ff;
  line-height: 1.35;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.summary-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
}

.summary-list li {
  border-radius: 0.46rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.03);
  padding: 0.3rem 0.42rem;
  font-size: 0.74rem;
  color: #d5e8ff;
  line-height: 1.35;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.identity-list li span,
.summary-list li span {
  color: #9db3d8;
  font-size: 0.67rem;
  font-weight: 600;
}

.identity-list li strong,
.summary-list li strong {
  font-size: 0.75rem;
  color: #eaf4ff;
}

.case-card.idle {
  opacity: 0.72;
}

.case-card.critical {
  border-color: rgba(248, 113, 113, 0.65);
  animation: criticalShake 0.8s ease-in-out infinite alternate;
}

@keyframes criticalShake {
  from {
    transform: translateX(-1px);
  }
  to {
    transform: translateX(1px);
  }
}

.vitals {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
}

.vitals li {
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  padding: 0.32rem 0.48rem;
  font-size: 0.74rem;
  color: #daedff;
  line-height: 1.35;
  display: flex;
  justify-content: space-between;
  gap: 0.35rem;
}

.vitals li span {
  color: #9db3d8;
  font-size: 0.68rem;
}

.vitals li strong {
  color: #eaf4ff;
  font-size: 0.76rem;
}

.exam-text {
  margin: 0;
  padding: 0.24rem 0.1rem 0.1rem;
  border-radius: 0.5rem;
  border: none;
  background: transparent;
  font-size: 0.75rem;
  line-height: 1.42;
  color: #d3e5ff;
}

.actions {
  margin-top: 0.2rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

.action-btn {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.75rem;
  padding: 0.72rem 0.65rem;
  background: linear-gradient(145deg, rgba(79, 209, 255, 0.1), rgba(139, 92, 246, 0.1));
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  min-height: 62px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  will-change: transform;
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.action-btn.appear {
  animation: actionAppear 0.3s ease both;
  animation-delay: var(--appear-delay, 0ms);
}

body.compact-fx .action-btn.appear {
  animation-duration: 0.24s;
}

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

.action-btn:hover {
  transform: translateY(-3px);
  border-color: rgba(79, 209, 255, 0.45);
  box-shadow: 0 8px 22px rgba(79, 209, 255, 0.14);
}

.action-btn:active {
  transform: translateY(-1px) scale(0.988);
}

.action-btn .name {
  font-weight: 700;
  line-height: 1.3;
  display: block;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.action-btn .hint {
  display: none;
}

.action-btn.good {
  border-color: rgba(52, 211, 153, 0.75);
  background: linear-gradient(145deg, rgba(52, 211, 153, 0.18), rgba(16, 185, 129, 0.12));
}

.action-btn.partial {
  border-color: rgba(245, 158, 11, 0.8);
}

.action-btn.bad {
  border-color: rgba(248, 113, 113, 0.75);
  background: linear-gradient(145deg, rgba(248, 113, 113, 0.18), rgba(239, 68, 68, 0.1));
}

.guideline-note {
  margin-top: 0.2rem;
  border-left: 4px solid rgba(79, 209, 255, 0.65);
  background: rgba(79, 209, 255, 0.09);
  border-radius: 0.6rem;
  padding: 0.55rem 0.7rem;
  color: #d8edff;
  font-size: 0.88rem;
  min-height: 65px;
  line-height: 1.45;
}

.debrief-panel {
  margin-top: 0.18rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.5rem 0.62rem;
}

.debrief-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.36rem;
}

.debrief-head h3 {
  margin: 0;
  font-size: 0.88rem;
}

.debrief-head span {
  font-size: 0.74rem;
  color: #b8d2f0;
}

.debrief-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
  max-height: 160px;
  overflow: auto;
}

.debrief-list.compact {
  max-height: 220px;
}

.debrief-list li {
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 0.56rem;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.42rem 0.5rem;
}

.debrief-list li.debrief-empty {
  color: #a9c1e4;
  font-size: 0.8rem;
}

.debrief-list .debrief-main {
  display: flex;
  justify-content: space-between;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: #e5f1ff;
  margin-bottom: 0.16rem;
}

.debrief-list .debrief-main strong {
  font-size: 0.8rem;
}

.debrief-list .debrief-main .tone-good {
  color: #8cf0c4;
}

.debrief-list .debrief-main .tone-warn {
  color: #ffd28c;
}

.debrief-list .debrief-main .tone-bad {
  color: #ffb8b8;
}

.debrief-list .debrief-sub {
  font-size: 0.72rem;
  color: #afc9ea;
  line-height: 1.38;
}

.event-log {
  margin: 0.8rem 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: 445px;
  overflow: auto;
  scrollbar-gutter: stable;
}

.event-log li {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.6rem;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.55rem 0.65rem;
  font-size: 0.84rem;
  line-height: 1.4;
}

.event-log li.event-entry {
  animation: logEntry 0.26s ease;
}

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

.event-log li.good {
  border-color: rgba(52, 211, 153, 0.45);
}

.event-log li.warn {
  border-color: rgba(245, 158, 11, 0.46);
}

.event-log li.bad {
  border-color: rgba(248, 113, 113, 0.45);
}

.tap-ripple {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
  transform: translate(-50%, -50%) scale(0.6);
  animation: tapRipple 0.5s ease-out forwards;
  pointer-events: none;
  z-index: 3;
}

body.compact-fx .tap-ripple {
  animation-duration: 0.38s;
}

@keyframes tapRipple {
  to {
    transform: translate(-50%, -50%) scale(18);
    opacity: 0;
  }
}

.float-feedback {
  position: absolute;
  right: 1rem;
  top: 1rem;
  font-weight: 700;
  animation: floatUp 1.2s ease-out forwards;
  pointer-events: none;
}

.float-feedback.good {
  color: var(--good);
}

.float-feedback.warn {
  color: #ffd18a;
}

.float-feedback.bad {
  color: var(--bad);
}

@keyframes floatUp {
  from {
    transform: translateY(0);
    opacity: 1;
  }
  to {
    transform: translateY(-28px);
    opacity: 0;
  }
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(3, 6, 12, 0.68);
  z-index: 30;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(620px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 1rem;
  background: linear-gradient(165deg, #0c1732, #0a1228);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  max-height: 92vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-card h2 {
  margin: 0;
}

.modal-card p {
  color: #d1e3ff;
}

.score-submit {
  margin-top: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.7rem;
  padding: 0.65rem 0.7rem;
  background: rgba(255, 255, 255, 0.03);
}

.score-submit label {
  display: block;
  font-size: 0.8rem;
  color: #a9c2e8;
  margin-bottom: 0.45rem;
}

.score-submit-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.score-submit-row input {
  flex: 1;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.55rem;
  background: rgba(4, 10, 22, 0.7);
  color: var(--text);
  font-size: 1rem;
  padding: 0.58rem 0.65rem;
  outline: none;
}

.score-submit-row input:focus {
  border-color: rgba(79, 209, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(79, 209, 255, 0.16);
}

.save-score-info {
  margin-top: 0.45rem;
  font-size: 0.78rem;
  color: #a8c2e8;
  min-height: 1.15rem;
}

.modal-actions {
  margin-top: 0.65rem;
  display: flex;
  gap: 0.55rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.leaderboard-card {
  width: min(680px, 100%);
}

.leaderboard-list {
  margin: 0.7rem 0 0;
  padding: 0 0 0 1.2rem;
  max-height: 48vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.leaderboard-list li {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.6rem;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.52rem 0.58rem;
  list-style-position: inside;
}

.leaderboard-list .entry-main {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: #eef6ff;
}

.leaderboard-list .entry-meta {
  margin-top: 0.18rem;
  font-size: 0.76rem;
  color: #a8c1e7;
}

.leaderboard-list .entry-kpis {
  margin-top: 0.2rem;
  font-size: 0.73rem;
  color: #8fd9ff;
}

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

.result-grid div {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.65rem;
  padding: 0.6rem;
  background: rgba(255, 255, 255, 0.03);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.result-grid span {
  color: var(--muted);
  font-size: 0.82rem;
}

.result-grid strong {
  font-size: 1.2rem;
}

.result-debrief {
  margin-top: 0.72rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.62rem;
}

.result-debrief h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.disclaimer {
  margin-top: 0.85rem;
  font-size: 0.78rem;
  color: #9cb2dc;
}

#streakText.streak-pop {
  animation: streakPop 0.34s ease;
  color: #9cf4cf;
}

#streakText.combo-hot {
  color: #ffd98d;
  text-shadow: 0 0 12px rgba(245, 158, 11, 0.28);
}

@keyframes streakPop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

.scene-panel.danger-pulse .scene-box {
  animation: urgentPulse 0.95s ease-in-out infinite;
  border-color: rgba(248, 113, 113, 0.42);
}

.game-shell.tension-warn .scene-box {
  border-color: rgba(245, 158, 11, 0.4);
  animation: tensionWarnGlow 1.6s ease-in-out infinite;
}

.game-shell.tension-critical .scene-box {
  border-color: rgba(248, 113, 113, 0.54);
  animation: tensionCriticalGlow 0.88s ease-in-out infinite;
}

.hud-item.timer.red-zone .value {
  color: #ffb28f;
  text-shadow: 0 0 14px rgba(239, 68, 68, 0.36);
}

body.compact-fx .scene-panel.danger-pulse .scene-box {
  animation-duration: 1.25s;
}

@keyframes urgentPulse {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(248, 113, 113, 0);
  }
  50% {
    box-shadow: 0 0 24px rgba(248, 113, 113, 0.16);
  }
}

@keyframes tensionWarnGlow {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(245, 158, 11, 0);
  }
  50% {
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.22);
  }
}

@keyframes tensionCriticalGlow {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(248, 113, 113, 0);
  }
  50% {
    box-shadow: 0 0 28px rgba(248, 113, 113, 0.3);
  }
}

@media (hover: hover) {
  .panel:hover {
    border-color: rgba(255, 255, 255, 0.18);
  }
}

@media (min-width: 1420px) {
  .game-shell {
    width: min(1380px, calc(100% - 2.2rem));
  }

  .game-grid {
    grid-template-columns: minmax(0, 1fr) minmax(460px, 1.06fr);
  }
}

@media (min-width: 1071px) {
  .panel {
    min-height: 0;
  }

  .case-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    overflow: hidden;
  }

  .case-card {
    min-height: 0;
    overflow: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(132, 172, 235, 0.45) rgba(255, 255, 255, 0.03);
  }

  .scene-panel {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .log-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .event-log {
    margin-top: 0.6rem;
    max-height: none;
    min-height: 0;
    flex: 1;
  }
}

@media (max-width: 1070px) {
  .portal-hero {
    grid-template-columns: minmax(0, 1fr);
  }

  .portal-art {
    justify-self: start;
    width: min(100%, 520px);
  }

  .game-shell {
    width: min(1240px, calc(100% - 1rem));
    margin: 0.6rem auto 1rem;
    min-height: calc(100dvh - 1.1rem);
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    position: sticky;
    top: calc(0.32rem + env(safe-area-inset-top));
    z-index: 18;
    margin-bottom: 0.35rem;
  }

  body.er-mobile-running .game-shell {
    padding-top: 6.1rem;
  }

  body.er-mobile-running .hud {
    position: fixed;
    top: calc(0.32rem + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    width: min(calc(100% - 1rem), 900px);
    margin: 0;
    z-index: 20;
    border: 1px solid rgba(151, 201, 255, 0.26);
    border-radius: 0.9rem;
    padding: 0.3rem;
    background: linear-gradient(155deg, rgba(7, 15, 31, 0.92), rgba(11, 31, 55, 0.8));
    backdrop-filter: blur(12px);
    box-shadow: 0 14px 30px rgba(2, 8, 18, 0.36);
  }

  .game-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "case"
      "scene";
  }

  .case-panel {
    order: 1;
    min-height: auto;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: 0.5rem;
    max-height: none;
    overflow: visible;
  }

  .scene-panel {
    order: 2;
    min-height: auto;
  }

  .panel {
    min-height: auto;
    padding: 0.88rem;
  }

  .log-panel {
    display: none;
  }

  .event-log {
    max-height: 180px;
  }

  .actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    position: relative;
    z-index: 2;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(7, 13, 30, 0.92);
    border-radius: 0.75rem;
    padding: 0.42rem;
    backdrop-filter: blur(8px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2);
  }

  body.er-mobile-running.er-mobile-has-case .game-shell {
    padding-bottom: calc(8.2rem + env(safe-area-inset-bottom));
  }

  body.er-mobile-running.er-mobile-has-case .mobile-case-dock {
    display: flex;
    flex-direction: column;
    gap: 0.28rem;
    position: fixed;
    left: 50%;
    bottom: calc(0.32rem + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    width: min(calc(100% - 1rem), 900px);
    z-index: 22;
    border: 1px solid rgba(166, 214, 255, 0.25);
    border-radius: 0.8rem;
    background: linear-gradient(152deg, rgba(8, 18, 36, 0.95), rgba(14, 31, 58, 0.9));
    padding: 0.5rem 0.6rem;
    box-shadow: 0 12px 28px rgba(2, 8, 18, 0.33);
    backdrop-filter: blur(12px);
  }

  .mobile-case-label {
    margin: 0;
    color: #96c8f7;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  #mobileCaseDockTitle {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.28;
    color: #eaf4ff;
    font-weight: 700;
  }

  #mobileCaseDockDesc {
    margin: 0;
    font-size: 0.76rem;
    line-height: 1.34;
    color: #c6def8;
    max-height: 5.1em;
    overflow: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(142, 188, 240, 0.45) transparent;
  }

  .scene-header p {
    margin-bottom: 0.55rem;
    font-size: 0.84rem;
  }

  .scene-box {
    padding: 0.75rem;
  }

  .patient-avatar {
    margin: 2.9rem auto 0.9rem;
    width: 110px;
    height: 110px;
  }

  .case-card {
    padding: 0.72rem;
    min-height: 0;
    overflow: visible;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .guideline-note {
    min-height: 0;
    padding: 0.45rem 0.62rem;
    font-size: 0.82rem;
  }

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

  .case-data-grid {
    grid-template-columns: 1fr;
  }

  .summary-list {
    grid-template-columns: 1fr;
  }

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

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

  .score-submit-row .btn {
    width: 100%;
  }

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

@media (max-width: 640px) {
  .portal-art {
    width: 100%;
  }

  .game-shell {
    gap: 0.52rem;
  }

  body.er-mobile-running .game-shell {
    padding-top: 6.65rem;
  }

  .panel {
    padding: 0.75rem;
  }

  .hud-item {
    padding: 0.58rem 0.72rem;
  }

  .hud-item .value {
    font-size: 1.08rem;
  }

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

  body.er-mobile-running.er-mobile-has-case .game-shell {
    padding-bottom: calc(8.9rem + env(safe-area-inset-bottom));
  }

  body.er-mobile-running.er-mobile-has-case .mobile-case-dock {
    width: calc(100% - 0.8rem);
    bottom: calc(0.22rem + env(safe-area-inset-bottom));
    padding: 0.46rem 0.52rem;
    border-radius: 0.74rem;
  }

  #mobileCaseDockTitle {
    font-size: 0.84rem;
  }

  #mobileCaseDockDesc {
    font-size: 0.74rem;
    max-height: 5.4em;
  }

  .action-btn {
    min-height: 78px;
    padding: 0.62rem 0.64rem;
  }

  .scene-header p {
    display: none;
  }

  .identity-list {
    grid-template-columns: 1fr;
  }

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

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

  .btn-toggle {
    min-width: 0;
  }
}

@media (max-width: 430px) {
  .case-panel {
    max-height: none;
  }

  .hud {
    gap: 0.5rem;
    margin-bottom: 0.55rem;
  }

  body.er-mobile-running .game-shell {
    padding-top: 6.55rem;
  }

  .hud-item {
    padding: 0.52rem 0.62rem;
    border-radius: 0.72rem;
  }

  .hud-item .label {
    font-size: 0.72rem;
  }

  .hud-item .value {
    font-size: 0.98rem;
  }

  .status-strip {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.82rem;
  }

  .controls {
    gap: 0.45rem;
  }

  .btn {
    padding: 0.62rem 0.72rem;
    font-size: 0.86rem;
  }

  .scene-box {
    padding: 0.65rem;
  }

  .ambulance-lane {
    height: 28px;
  }

  .patient-avatar {
    margin: 2.35rem auto 0.7rem;
    width: 96px;
    height: 96px;
  }

  .avatar-emoji {
    font-size: 2.4rem;
  }

  .case-card {
    padding: 0.62rem;
    gap: 0.42rem;
  }

  .case-card h3 {
    font-size: 1rem;
  }

  .case-card p {
    font-size: 0.82rem;
    line-height: 1.42;
  }

  .case-block {
    padding: 0.38rem 0.42rem;
  }

  .case-block h4 {
    font-size: 0.64rem;
  }

  .identity-list li,
  .summary-list li,
  .vitals li {
    padding: 0.28rem 0.38rem;
    font-size: 0.7rem;
  }

  .identity-list li strong,
  .summary-list li strong,
  .vitals li strong {
    font-size: 0.72rem;
  }

  .actions {
    gap: 0.46rem;
  }

  body.er-mobile-running.er-mobile-has-case .game-shell {
    padding-bottom: calc(9.5rem + env(safe-area-inset-bottom));
  }

  body.er-mobile-running.er-mobile-has-case .mobile-case-dock {
    bottom: calc(0.18rem + env(safe-area-inset-bottom));
  }

  .action-btn {
    min-height: 80px;
    padding: 0.62rem 0.6rem;
    border-radius: 0.66rem;
  }

  .action-btn .name {
    font-size: 0.82rem;
  }

  .guideline-note {
    font-size: 0.78rem;
    line-height: 1.36;
    padding: 0.42rem 0.54rem;
  }
}

@media (max-height: 760px) and (min-width: 1071px) {
  .game-shell {
    margin-top: 0.6rem;
    margin-bottom: 0.6rem;
  }

  .scene-header p {
    margin-bottom: 0.45rem;
    font-size: 0.82rem;
  }

  .patient-avatar {
    margin: 2.55rem auto 0.8rem;
    width: 108px;
    height: 108px;
  }
}

.powered-by {
  position: relative;
  z-index: 1;
  width: min(1240px, calc(100% - 2rem));
  margin: 0 auto 1rem;
  text-align: center;
}

.powered-by a {
  color: #99d8f5;
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 600;
}

.powered-by a:hover {
  text-decoration: underline;
}

@media (max-width: 820px) {
  .portal-hero {
    margin-top: 0.72rem;
    padding: 0.84rem;
  }

  .portal-art {
    display: none;
  }

  .game-shell {
    width: min(1240px, calc(100% - 1.2rem));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
