:root {
  --bg-a: #061225;
  --bg-b: #0b2b4b;
  --bg-c: #123f62;
  --ink: #e8f5ff;
  --muted: #a9c4dd;
  --accent: #77ffd7;
  --accent-2: #9fd5ff;
  --danger: #ff9f9f;
  --warn: #ffd28a;
  --panel: rgba(8, 24, 42, 0.82);
  --panel-border: rgba(132, 198, 242, 0.23);
}

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

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  background: radial-gradient(980px 620px at 8% 0%, rgba(39, 141, 208, 0.26), transparent 60%),
    radial-gradient(860px 520px at 92% 4%, rgba(95, 220, 190, 0.2), transparent 62%),
    linear-gradient(160deg, var(--bg-a) 12%, var(--bg-b) 58%, var(--bg-c) 100%);
}

.shell {
  width: min(1320px, 95vw);
  margin: 0 auto;
  padding: 1rem 0 1.9rem;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 520px);
  gap: 0.9rem;
  align-items: center;
  padding: 0.95rem;
  border-radius: 22px;
  border: 1px solid rgba(141, 215, 255, 0.24);
  background: linear-gradient(136deg, rgba(5, 20, 36, 0.8), rgba(18, 56, 86, 0.5));
  box-shadow: 0 20px 38px rgba(3, 11, 20, 0.34);
  animation: riseIn 360ms ease-out both;
}

.eyebrow {
  margin: 0;
  font-size: 0.77rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin: 0.2rem 0 0;
  font-family: "Sora", "Space Grotesk", sans-serif;
  font-size: clamp(2.1rem, 4.9vw, 3.4rem);
}

.subtitle {
  margin: 0.5rem 0 0;
  color: var(--muted);
  line-height: 1.45;
  max-width: 70ch;
}

.link-line {
  margin: 0.72rem 0 0;
}

.link-line a {
  color: #c7e7ff;
  text-decoration: none;
  border-bottom: 1px dashed rgba(146, 218, 255, 0.4);
}

.hero-art {
  margin: 0;
  width: min(100%, 520px);
  justify-self: end;
  filter: drop-shadow(0 20px 30px rgba(3, 11, 20, 0.42));
}

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

.layout {
  margin-top: 0.95rem;
  display: grid;
  grid-template-columns: minmax(0, 1.62fr) minmax(300px, 0.92fr);
  gap: 0.9rem;
}

.panel {
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  animation: riseIn 420ms ease-out both;
}

.layout .panel:nth-child(2) {
  animation-delay: 90ms;
}

.monitor-panel {
  padding: 0.82rem;
  display: grid;
  gap: 0.7rem;
}

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

.hud-item {
  border: 1px solid rgba(150, 211, 247, 0.2);
  border-radius: 14px;
  padding: 0.48rem 0.58rem;
  background: rgba(11, 36, 60, 0.6);
  transition: transform 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

.hud-item.pulse {
  transform: translateY(-1px) scale(1.015);
  border-color: rgba(130, 241, 214, 0.6);
  background: rgba(16, 48, 75, 0.9);
}

.hud-item .label {
  display: block;
  color: #aac8e4;
  font-size: 0.74rem;
}

.hud-item strong {
  font-size: 1.24rem;
  line-height: 1.2;
}

.hud-item.timer strong {
  color: #ffe0a8;
}

.monitor-frame {
  position: relative;
  border-radius: 18px;
  border: 1px solid rgba(140, 208, 249, 0.22);
  background: rgba(7, 24, 42, 0.8);
  overflow: hidden;
}

.monitor-shell {
  width: 100%;
  height: auto;
  display: block;
}

.strip-stage {
  position: absolute;
  left: 6.6%;
  right: 6.6%;
  top: 10.2%;
  bottom: 21.7%;
  border-radius: 11px;
  overflow: hidden;
  background: #fdf6f7;
  border: 1px solid rgba(255, 255, 255, 0.45);
}

.strip-stage img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #fff9fa;
  transition: opacity 220ms ease, transform 220ms ease;
}

.strip-stage img.is-swapping {
  opacity: 0.34;
  transform: scale(1.015);
}

.status-line {
  border: 1px solid rgba(151, 211, 245, 0.2);
  border-radius: 13px;
  background: rgba(12, 37, 60, 0.65);
  padding: 0.5rem 0.62rem;
  display: flex;
  justify-content: space-between;
  gap: 0.55rem;
  align-items: center;
  font-size: 0.9rem;
}

.status-line p {
  margin: 0;
  overflow-wrap: anywhere;
}

#streakText {
  color: #b7ffd7;
  font-weight: 700;
}

.control-panel {
  padding: 0.82rem;
  display: grid;
  gap: 0.7rem;
}

.block {
  border: 1px solid rgba(143, 206, 244, 0.2);
  border-radius: 14px;
  padding: 0.65rem;
  background: rgba(10, 33, 53, 0.66);
}

.block h2 {
  margin: 0;
  font-family: "Sora", "Space Grotesk", sans-serif;
  font-size: 1.06rem;
}

label {
  display: grid;
  gap: 0.34rem;
  font-size: 0.86rem;
  margin-top: 0.55rem;
  color: #c9e4fb;
}

input,
select {
  border-radius: 11px;
  border: 1px solid rgba(155, 214, 245, 0.3);
  background: rgba(5, 18, 32, 0.72);
  color: #eef8ff;
  font: inherit;
  padding: 0.58rem 0.66rem;
}

input::placeholder {
  color: #7ea6c7;
}

.row {
  margin-top: 0.58rem;
  display: flex;
  gap: 0.48rem;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid rgba(156, 218, 250, 0.3);
  border-radius: 11px;
  color: #e7f7ff;
  font: inherit;
  font-weight: 700;
  padding: 0.56rem 0.8rem;
  background: rgba(16, 49, 77, 0.8);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, filter 120ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

.btn:disabled {
  opacity: 0.52;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(118deg, #6cf1cf, #a3ffd9);
  color: #072034;
  border-color: rgba(141, 255, 224, 0.72);
}

.btn-ghost {
  background: rgba(11, 39, 63, 0.65);
}

.btn-mini {
  padding: 0.35rem 0.55rem;
  font-size: 0.79rem;
}

#questionText {
  margin: 0.55rem 0 0;
  color: #c9e5fb;
  line-height: 1.43;
}

.options {
  margin-top: 0.58rem;
  display: grid;
  gap: 0.45rem;
}

.option-btn {
  width: 100%;
  text-align: left;
  border-radius: 11px;
  border: 1px solid rgba(150, 211, 244, 0.28);
  background: rgba(10, 36, 58, 0.75);
  color: #e8f3ff;
  font: inherit;
  padding: 0.55rem 0.6rem;
  min-height: 46px;
  line-height: 1.35;
  white-space: normal;
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease, background-color 120ms ease;
}

.option-btn.option-enter {
  animation: optionRise 280ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.option-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(123, 241, 216, 0.55);
}

.option-btn.correct {
  border-color: rgba(124, 244, 217, 0.78);
  background: linear-gradient(118deg, rgba(42, 138, 114, 0.4), rgba(18, 69, 57, 0.42));
}

.option-btn.wrong {
  border-color: rgba(255, 152, 152, 0.76);
  background: linear-gradient(118deg, rgba(123, 34, 34, 0.36), rgba(67, 15, 15, 0.42));
}

.explanation {
  margin: 0.52rem 0 0;
  color: #9dc5e6;
  font-size: 0.81rem;
  line-height: 1.4;
  min-height: 40px;
}

.leaderboard-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
}

#leaderboardInfo {
  margin: 0.48rem 0 0;
  color: #afd3ef;
  font-size: 0.82rem;
}

.leaderboard-list {
  margin: 0.48rem 0 0;
  padding: 0 0 0 1.05rem;
  max-height: 240px;
  overflow: auto;
  display: grid;
  gap: 0.42rem;
}

.leaderboard-list li {
  border: 1px solid rgba(153, 212, 245, 0.2);
  border-radius: 10px;
  background: rgba(12, 37, 61, 0.65);
  padding: 0.46rem 0.52rem;
  list-style-position: inside;
}

.entry-main {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.88rem;
}

.entry-sub {
  margin-top: 0.16rem;
  font-size: 0.75rem;
  color: #9ebfdd;
}

.powered-by {
  margin-top: 0.92rem;
  text-align: center;
}

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

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

.mobile-strip-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: #d7ebfb;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.mobile-strip-head strong {
  color: #9bf7d7;
  font-size: 0.74rem;
}

.mobile-strip-frame {
  margin-top: 0.35rem;
  border-radius: 11px;
  overflow: hidden;
  border: 1px solid rgba(155, 214, 247, 0.38);
  background: #fdf6f7;
}

#mobileStripImage {
  width: 100%;
  height: 92px;
  object-fit: contain;
  background: #fff9fa;
  display: block;
}

.result-modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 11, 19, 0.78);
  display: grid;
  place-items: center;
  padding: 0.9rem;
  z-index: 30;
}

.result-modal.hidden {
  display: none;
}

.result-card {
  width: min(560px, 94vw);
  border-radius: 16px;
  border: 1px solid rgba(150, 214, 246, 0.28);
  background: linear-gradient(170deg, rgba(5, 18, 32, 0.96), rgba(15, 47, 74, 0.93));
  padding: 0.82rem;
}

.result-card h2 {
  margin: 0;
  font-family: "Sora", "Space Grotesk", sans-serif;
}

#resultSummary {
  margin: 0.45rem 0 0;
  color: #bad5ee;
}

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

.result-grid div {
  border: 1px solid rgba(153, 214, 245, 0.24);
  border-radius: 12px;
  background: rgba(12, 37, 60, 0.68);
  padding: 0.5rem;
  display: grid;
  gap: 0.22rem;
}

.result-grid span {
  color: #a9c9e4;
  font-size: 0.78rem;
}

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

.save-row {
  margin-top: 0.62rem;
}

.save-row label {
  margin: 0;
  color: #d0e9fd;
}

.save-input-row {
  margin-top: 0.38rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.44rem;
}

#saveInfo {
  margin: 0.42rem 0 0;
  color: #a2c7e7;
  font-size: 0.8rem;
}

.result-actions {
  margin-top: 0.62rem;
  display: flex;
  gap: 0.48rem;
  flex-wrap: wrap;
}

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

@keyframes optionRise {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.992);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

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

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

@media (max-width: 720px) {
  .shell {
    width: min(96vw, 96vw);
  }

  .hero {
    padding: 0.78rem;
  }

  .subtitle {
    font-size: 0.9rem;
  }

  .monitor-panel,
  .control-panel {
    padding: 0.68rem;
  }

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

  .status-line {
    flex-direction: column;
    align-items: flex-start;
  }

  .save-input-row {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 820px) {
  .hero-art {
    display: none;
  }
}

@media (max-width: 900px) {
  html,
  body {
    scroll-padding-top: calc(8rem + env(safe-area-inset-top));
  }

  body.running-ecg .layout {
    gap: 0.66rem;
  }

  body.running-ecg .monitor-panel {
    position: sticky;
    top: calc(0.52rem + env(safe-area-inset-top));
    z-index: 16;
    border-color: rgba(141, 221, 255, 0.42);
    box-shadow: 0 16px 32px rgba(4, 14, 24, 0.45);
    background: rgba(8, 24, 42, 0.95);
  }

  body.running-ecg .hud {
    gap: 0.36rem;
  }

  body.running-ecg .hud-item {
    padding: 0.36rem 0.42rem;
  }

  body.running-ecg .hud-item .label {
    font-size: 0.65rem;
  }

  body.running-ecg .hud-item strong {
    font-size: 1rem;
  }

  body.running-ecg .status-line {
    display: none;
  }

  body.running-ecg .monitor-frame {
    border-radius: 14px;
  }

  body.running-ecg .strip-stage {
    top: 11.2%;
    bottom: 17.4%;
  }

  .mobile-strip-dock {
    display: none !important;
  }

  .control-panel .block:last-child {
    margin-bottom: 0.25rem;
  }

  .leaderboard-list {
    max-height: 180px;
  }
}

@media (max-width: 620px) {
  .hero-art {
    display: none;
  }

  .option-btn {
    font-size: 0.92rem;
    padding: 0.6rem 0.62rem;
  }

  .explanation {
    min-height: 54px;
    font-size: 0.8rem;
  }

  body.running-ecg .strip-stage {
    top: 11.8%;
    bottom: 19.2%;
  }
}
