:root {
  color-scheme: dark;
  --ink: #e9f0e8;
  --muted: #849187;
  --panel: #151a17;
  --panel-2: #1b211d;
  --line: #303a33;
  --lime: #c8ff4d;
  --coral: #ff745c;
  --blue: #6fc6ff;
  --bg: #0c100e;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; min-height: 100vh; }
button { font: inherit; }
button:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.shell { width: min(1100px, calc(100% - 36px)); margin: 0 auto; padding-bottom: 80px; }
.topbar { height: 78px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.brand { font-size: 18px; display: flex; gap: 10px; align-items: center; letter-spacing: -.04em; }
.brand b { color: var(--lime); font-weight: 600; }
.brand-cursor { width: 10px; height: 20px; background: var(--lime); animation: blink 1.1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.history-toggle, .text-button { color: var(--ink); background: none; border: 0; cursor: pointer; padding: 10px 0; }
.history-toggle { border-bottom: 1px solid var(--muted); }
.history-toggle span { color: var(--lime); margin-left: 6px; }
.hero { padding: 84px 0 54px; display: grid; grid-template-columns: 1fr 340px; align-items: end; gap: 40px; }
.hero h1 { margin: 10px 0 0; font-family: Arial, "PingFang SC", sans-serif; font-size: clamp(43px, 7vw, 82px); line-height: .98; letter-spacing: -.065em; font-weight: 800; grid-row: span 2; }
.hero h1 em { color: var(--lime); font-style: normal; }
.hero > p:last-child { color: var(--muted); font-size: 14px; line-height: 1.8; margin: 0 0 8px; }
.eyebrow, .step-kicker { color: var(--lime); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; }
.hero .eyebrow { grid-column: 1 / -1; margin: 0; }
.studio { border: 1px solid var(--line); background: var(--panel); min-height: 520px; }
.studio-head { padding: 25px 28px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.studio-head h2 { font-family: Arial, "PingFang SC", sans-serif; margin: 7px 0 0; font-size: 25px; letter-spacing: -.03em; }
.text-button { color: var(--muted); font-size: 12px; }
.text-button:hover { color: var(--ink); }
#setupView { padding: 28px; }
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.preset-card { min-height: 166px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); padding: 20px; text-align: left; cursor: pointer; transition: .2s ease; }
.preset-card:hover { border-color: var(--lime); transform: translateY(-2px); }
.preset-card .preset-top { display: flex; justify-content: space-between; align-items: start; }
.preset-card .preset-index { color: var(--muted); font-size: 11px; }
.preset-card strong { font-family: Arial, "PingFang SC", sans-serif; font-size: 20px; }
.preset-card small { display: block; color: var(--muted); margin-top: 7px; line-height: 1.5; }
.mini-beats { display: flex; align-items: center; gap: 6px; height: 50px; margin-top: 16px; }
.mini-beats i { display: block; width: 8px; border-radius: 8px; background: var(--lime); }
.custom-card { width: 100%; border: 1px dashed #4b584e; color: var(--ink); background: transparent; min-height: 96px; padding: 20px 24px; margin-top: 14px; display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 16px; text-align: left; cursor: pointer; }
.custom-card:hover { border-color: var(--coral); }
.custom-plus { width: 46px; height: 46px; border: 1px solid var(--coral); color: var(--coral); display: grid; place-items: center; font-size: 24px; }
.custom-card strong, .custom-card small { display: block; }
.custom-card small { color: var(--muted); margin-top: 6px; }
.play-view { padding: 28px; }
.turn-banner { display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 14px; }
.turn-number { width: 48px; height: 48px; border: 1px solid var(--lime); color: var(--lime); display: grid; place-items: center; font-size: 20px; }
.turn-banner strong, .turn-banner span { display: block; }
.turn-banner > div:nth-child(2) span { color: var(--muted); font-size: 12px; margin-top: 5px; }
.tap-counter { color: var(--lime); }
#rhythmCanvas { width: 100%; height: 130px; display: block; margin: 24px 0 0; background: repeating-linear-gradient(90deg, transparent 0, transparent calc(12.5% - 1px), #222a25 calc(12.5% - 1px), #222a25 12.5%); border: 1px solid var(--line); }
.tap-pad { width: 100%; height: 180px; background: #121714; border: 1px solid var(--line); border-top: 0; color: var(--ink); cursor: pointer; position: relative; overflow: hidden; }
.tap-pad:hover, .tap-pad.is-tapping { background: #171f19; }
.tap-pad strong { position: relative; display: block; font-family: Arial, sans-serif; font-size: 56px; line-height: 1; letter-spacing: -.05em; }
.tap-pad small { position: relative; color: var(--muted); display: block; margin-top: 10px; }
.tap-rings, .tap-rings::before, .tap-rings::after { position: absolute; inset: 50% auto auto 50%; width: 90px; height: 90px; border: 1px solid #344037; transform: translate(-50%, -50%); border-radius: 50%; }
.tap-rings::before, .tap-rings::after { content: ""; width: 150px; height: 150px; }
.tap-rings::after { width: 230px; height: 230px; }
.play-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 18px; }
.primary, .secondary { min-height: 48px; border: 1px solid var(--lime); padding: 0 20px; cursor: pointer; }
.primary { background: var(--lime); color: #11150f; font-weight: 700; }
.primary span { margin-left: 18px; }
.primary:hover { background: #d8ff7e; }
.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
.secondary:hover { border-color: var(--muted); }
button:disabled { opacity: .35; cursor: not-allowed; }
.privacy-note { color: #69766d; font-size: 10px; margin: 22px 0 0; }
.handoff { text-align: center; padding: 72px 22px; }
.handoff-icon { width: 76px; height: 76px; display: grid; place-items: center; border: 1px solid var(--lime); color: var(--lime); font-size: 34px; margin: 0 auto 26px; }
.handoff h2 { font: 700 38px/1.1 Arial, "PingFang SC", sans-serif; letter-spacing: -.04em; margin: 11px 0; }
.handoff > p:not(.eyebrow) { color: var(--muted); line-height: 1.7; }
.handoff b { color: var(--ink); }
.large { margin-top: 22px; min-width: 240px; }
.result-view { padding: 32px 28px; }
.score-wrap { display: grid; grid-template-columns: 160px 1fr; gap: 30px; align-items: center; }
.score-ring { width: 150px; height: 150px; border-radius: 50%; display: grid; place-content: center; text-align: center; background: conic-gradient(var(--lime) var(--score), #283129 0); position: relative; }
.score-ring::before { content: ""; position: absolute; inset: 8px; background: var(--panel); border-radius: 50%; }
.score-ring strong, .score-ring span { position: relative; }
.score-ring strong { font: 800 55px/1 Arial, sans-serif; }
.score-ring span { font-size: 11px; color: var(--muted); margin-top: 4px; }
.score-wrap h2 { font: 700 34px/1.1 Arial, "PingFang SC", sans-serif; margin: 8px 0; }
.score-wrap p:last-child { color: var(--muted); line-height: 1.6; margin: 0; }
.legend { display: flex; gap: 20px; color: var(--muted); font-size: 11px; margin: 30px 0 10px; }
.legend span { display: flex; align-items: center; gap: 7px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); }
.dot.reply { background: var(--coral); }
.legend .line { width: 15px; border-top: 1px dashed #647067; }
#resultCanvas { width: 100%; height: 230px; display: block; border: 1px solid var(--line); background: #101512; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-top: 0; }
.metric { padding: 17px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric small, .metric strong { display: block; }
.metric small { color: var(--muted); font-size: 10px; margin-bottom: 6px; }
.metric strong { font-size: 18px; }
.history-panel { position: fixed; z-index: 20; top: 0; right: 0; width: min(450px, 100%); height: 100dvh; background: #141916; border-left: 1px solid var(--line); padding: 28px; transform: translateX(101%); transition: transform .25s ease; overflow-y: auto; }
.history-panel.open { transform: translateX(0); }
.history-head { display: flex; align-items: start; justify-content: space-between; border-bottom: 1px solid var(--line); padding-bottom: 20px; }
.history-head h2 { font: 700 30px/1 Arial, sans-serif; margin: 7px 0 0; }
.history-head button { color: var(--ink); background: none; border: 1px solid var(--line); width: 38px; height: 38px; font-size: 24px; cursor: pointer; }
.history-intro { color: var(--muted); font-size: 12px; line-height: 1.7; }
.history-list { display: grid; gap: 10px; margin: 24px 0; }
.history-item { border: 1px solid var(--line); padding: 16px; display: grid; grid-template-columns: 1fr auto; gap: 9px; }
.history-item strong { font: 700 17px Arial, sans-serif; }
.history-item .history-score { color: var(--lime); font-size: 20px; grid-row: span 2; }
.history-item small { color: var(--muted); }
.empty-history { color: var(--muted); border: 1px dashed var(--line); padding: 34px 20px; text-align: center; line-height: 1.6; }
.danger-text { background: none; color: var(--coral); border: 0; padding: 10px 0; cursor: pointer; }
.scrim { position: fixed; z-index: 10; inset: 0; background: #000a; }

@media (max-width: 720px) {
  .shell { width: min(100% - 24px, 1100px); padding-bottom: 32px; }
  .topbar { height: 62px; }
  .hero { padding: 52px 0 34px; display: block; }
  .hero .eyebrow { margin-bottom: 12px; }
  .hero h1 { font-size: clamp(42px, 13vw, 64px); }
  .hero > p:last-child { margin-top: 25px; }
  .studio-head, #setupView, .play-view, .result-view { padding: 20px 16px; }
  .studio-head h2 { font-size: 20px; }
  .presets { grid-template-columns: 1fr; }
  .preset-card { min-height: 125px; }
  .custom-card { grid-template-columns: 44px 1fr; }
  .custom-card > span:last-child { display: none; }
  .turn-banner { grid-template-columns: 42px 1fr; }
  .turn-number { width: 42px; height: 42px; }
  .tap-counter { grid-column: 2; }
  .tap-pad { height: 160px; }
  .play-actions { display: grid; grid-template-columns: 1fr 1.35fr; }
  .score-wrap { grid-template-columns: 110px 1fr; gap: 18px; }
  .score-ring { width: 108px; height: 108px; }
  .score-ring strong { font-size: 40px; }
  .score-wrap h2 { font-size: 25px; }
  .legend { flex-wrap: wrap; }
  #resultCanvas { height: 190px; }
  .metrics { grid-template-columns: 1fr; }
  .metric { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric:last-child { border-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
