:root {
  color-scheme: dark;
  --bg: #080b12;
  --bg-soft: #0d121c;
  --panel: rgba(17, 23, 34, .88);
  --panel-solid: #111722;
  --panel-2: #182131;
  --panel-3: #202c40;
  --line: #2d3b52;
  --line-soft: rgba(145, 171, 211, .16);
  --text: #f3f6fc;
  --muted: #a5b1c5;
  --subtle: #728199;
  --accent: #a8ccff;
  --accent-strong: #619cff;
  --good: #b9e4d1;
  --warning: #f2c58a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #edf2f8;
  --bg-soft: #e5ebf4;
  --panel: rgba(255, 255, 255, .9);
  --panel-solid: #ffffff;
  --panel-2: #f3f6fa;
  --panel-3: #e9eff7;
  --line: #cbd5e4;
  --line-soft: rgba(56, 79, 112, .14);
  --text: #192131;
  --muted: #536176;
  --subtle: #718097;
  --accent: #2d65b3;
  --accent-strong: #1f55a0;
  --good: #24715d;
  --warning: #97641d;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 90% -8%, rgba(93, 140, 215, .2), transparent 28rem),
    radial-gradient(circle at -10% 76%, rgba(90, 116, 169, .1), transparent 25rem),
    var(--bg);
}

button {
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 3px solid rgba(168, 204, 255, .6);
  outline-offset: 3px;
}

.app-shell {
  width: min(100% - 32px, 780px);
  margin: 0 auto;
  padding: 30px 0 38px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.brand-lockup {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.brand-mark {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, 9px);
  gap: 4px;
  width: 38px;
  height: 38px;
  padding: 7px 8px;
  margin-top: 3px;
  border: 1px solid rgba(168, 204, 255, .35);
  border-radius: 13px;
  background: linear-gradient(145deg, #1a2c48, #101a2b);
  box-shadow: 0 8px 22px rgba(31, 78, 139, .2);
  transform: rotate(-4deg);
}

.brand-mark span,
.brand-mark b {
  display: block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #a8ccff;
}

.brand-mark span:nth-child(2),
.brand-mark span:nth-child(3) {
  opacity: .78;
}

.brand-mark span:nth-child(4) {
  opacity: .58;
}

.brand-mark b {
  position: absolute;
  left: 12px;
  bottom: 5px;
  width: 14px;
  height: 10px;
  border-radius: 45% 45% 50% 50%;
  background: #769ed7;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .18em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 7px;
  font-size: clamp(27px, 7vw, 40px);
  letter-spacing: -.055em;
  line-height: .98;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: .01em;
}

.icon-button,
.secondary-button,
.trim-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  background: var(--panel-2);
  font-weight: 750;
  transition: border-color .2s ease, background .2s ease, transform .2s ease, box-shadow .2s ease;
}

.icon-button {
  min-width: 92px;
  padding: 0 15px;
  font-size: 12px;
  box-shadow: 0 5px 18px rgba(0, 0, 0, .12);
}

.icon-button:hover,
.secondary-button:hover {
  border-color: var(--accent);
  background: var(--panel-3);
  box-shadow: 0 7px 22px rgba(50, 100, 165, .15);
}

.notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
  padding: 14px 16px 15px;
  border: 1px solid var(--line-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 15px 15px 0;
  background: linear-gradient(110deg, rgba(35, 54, 82, .62), rgba(18, 25, 38, .72));
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .08);
}

.notice-icon {
  display: grid;
  flex: 0 0 22px;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  border: 1px solid rgba(168, 204, 255, .5);
  border-radius: 50%;
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
}

.notice strong {
  display: block;
  margin-bottom: 2px;
  color: var(--text);
  font-weight: 800;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin-bottom: 16px;
}

.stat-card {
  min-width: 0;
  padding: 13px 13px 14px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(24, 33, 49, .94), rgba(14, 19, 29, .9));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .035);
}

.stat-card span,
.section-label,
.micro-label {
  display: block;
  color: var(--subtle);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .13em;
}

.stat-card span {
  margin-bottom: 6px;
}

.stat-card strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  letter-spacing: -.01em;
}

.game-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 21px;
  background: linear-gradient(150deg, rgba(21, 28, 41, .96), rgba(13, 18, 27, .97));
  box-shadow: 0 24px 70px rgba(0, 0, 0, .22), inset 0 1px 0 rgba(255, 255, 255, .035);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 4px 14px;
}

.section-label {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 9px;
}

.card-header h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -.02em;
}

.live-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  border: 1px solid rgba(185, 228, 209, .2);
  border-radius: 999px;
  color: var(--good);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
}

.live-pill i {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 4px rgba(185, 228, 209, .1);
  animation: breathe 2.5s ease-in-out infinite;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(123, 158, 211, .17);
  border-radius: 15px;
  background: #090c13;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04);
}

canvas {
  display: block;
  width: 100%;
  height: min(72vw, 470px);
  min-height: 350px;
  touch-action: none;
}

.canvas-hint {
  position: absolute;
  left: 50%;
  bottom: 13px;
  transform: translateX(-50%);
  padding: 7px 12px;
  border: 1px solid rgba(157, 198, 255, .25);
  border-radius: 999px;
  background: rgba(8, 12, 20, .76);
  color: #d9e7ff;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(8px);
}

.instruction-row {
  display: flex;
  gap: 13px;
  align-items: flex-start;
  padding: 19px 4px 15px;
}

.step-number {
  display: grid;
  flex: 0 0 32px;
  place-items: center;
  height: 32px;
  border: 3px solid rgba(168, 204, 255, .2);
  border-radius: 50%;
  background: var(--accent);
  color: #08101c;
  font-size: 14px;
  font-weight: 900;
  box-shadow: 0 0 0 5px rgba(168, 204, 255, .06);
}

.instruction-copy {
  min-width: 0;
}

.micro-label {
  margin-bottom: 4px;
  color: var(--subtle);
  font-size: 9px;
}

.instruction-row h2 {
  margin-bottom: 4px;
  font-size: 18px;
  letter-spacing: -.025em;
}

.instruction-row p {
  max-width: 560px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1.18fr;
  gap: 9px;
}

.trim-button {
  display: flex;
  min-height: 53px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 9px;
  font-size: 12px;
  line-height: 1.05;
}

.trim-button small {
  color: inherit;
  opacity: .64;
  font-size: 9px;
  font-weight: 700;
}

.button-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, .06);
}

.trim-button.small {
  border-color: #3d778d;
  color: #c5eff2;
  background: linear-gradient(145deg, #1d4050, #162d3b);
}

.trim-button.medium {
  border-color: #6e6386;
  color: #e4d6ff;
  background: linear-gradient(145deg, #3a374d, #29283b);
}

.trim-button.stop {
  color: var(--muted);
  background: rgba(255, 255, 255, .025);
}

.stop-symbol {
  width: 9px;
  height: 9px;
  border: 2px solid currentColor;
  border-radius: 3px;
}

.trim-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 9px 24px rgba(0, 0, 0, .16);
}

.trim-button:active,
.secondary-button:active,
.icon-button:active {
  transform: translateY(1px);
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 2px 7px;
  color: var(--subtle);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .02em;
}

.progress-track {
  height: 6px;
  margin: 0 2px 13px;
  overflow: hidden;
  border-radius: 10px;
  background: #202a3a;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .25);
}

.progress-track div {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #76b6d0, #b9e4d1);
  box-shadow: 0 0 12px rgba(185, 228, 209, .35);
  transition: width .4s cubic-bezier(.2, .8, .2, 1);
}

.message {
  min-height: 42px;
  padding: 12px 13px;
  border: 1px solid var(--line-soft);
  border-radius: 11px;
  background: rgba(24, 33, 49, .72);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.bottom-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.secondary-button {
  font-size: 12px;
  background: rgba(18, 25, 37, .74);
}

.save-status {
  margin: 15px 0 0;
  text-align: center;
  color: var(--subtle);
  font-size: 11px;
}

@keyframes breathe {
  0%, 100% {
    opacity: .65;
    transform: scale(.9);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
  }
}

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

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 780px);
    padding-top: 20px;
  }

  .topbar {
    gap: 10px;
  }

  .brand-lockup {
    gap: 10px;
  }

  .brand-mark {
    display: none;
  }

  .icon-button {
    min-width: 80px;
    padding: 0 9px;
  }

  .game-card {
    padding: 9px;
    border-radius: 18px;
  }

  .card-header {
    padding: 4px 3px 12px;
  }

  canvas {
    min-height: 330px;
  }

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

  .trim-button.stop {
    grid-column: 1 / -1;
  }
}

@media (max-width: 380px) {
  .app-shell {
    width: min(100% - 16px, 780px);
  }

  h1 {
    font-size: 26px;
  }

  .subtitle {
    font-size: 12px;
  }

  .notice {
    font-size: 12px;
  }

  .stats {
    gap: 6px;
  }

  .stat-card {
    padding-inline: 9px;
  }

  .stat-card strong {
    font-size: 12px;
  }

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