:root {
  --bg: #1a1a2e;
  --card: #16213e;
  --accent: #e94560;
  --text: #eaeaea;
  --muted: #8a8a9a;
  --blue-model: #4a9eff;
  --success: #42b983;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  overflow-x: hidden;
}

body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding: 0.75rem 1rem 1.25rem;
  max-width: 720px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 0.75rem;
}

h1 {
  font-size: 1.25rem;
  line-height: 1.25;
  letter-spacing: 0.02em;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.tab {
  padding: 0.55rem;
  border: 1px solid #2b3856;
  border-radius: 8px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.88rem;
}

.tab.active {
  background: #23355c;
  color: var(--text);
  border-color: var(--blue-model);
}

.tone-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  margin-bottom: 0.65rem;
}

.tone-btn {
  padding: 0.58rem 0.3rem;
  border: 1px solid var(--muted);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 0.86rem;
  cursor: pointer;
  transition: all 0.16s ease;
}

.tone-btn:hover {
  border-color: var(--blue-model);
}

.tone-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}

.tone-btn.combo {
  font-size: 0.8rem;
  position: relative;
}

.tone-btn.combo.locked {
  opacity: 0.55;
}

.tone-btn.combo.locked::after {
  content: "🔒";
  font-size: 0.68rem;
  position: absolute;
  top: 2px;
  right: 4px;
}

.info-card {
  background: var(--card);
  border-left: 3px solid var(--blue-model);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.65rem;
  font-size: 0.86rem;
}

.audio-mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.65rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.switch {
  width: 42px;
  height: 22px;
  border-radius: 11px;
  border: none;
  background: #3a3f58;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.switch::after {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}

.switch.on {
  background: var(--success);
}

.switch.on::after {
  transform: translateX(20px);
}

.canvas-wrap {
  background: var(--card);
  border-radius: 12px;
  padding: 0.5rem;
  margin-bottom: 0.65rem;
}

#pitchCanvas,
#historyCanvas {
  width: 100%;
  height: 165px;
  display: block;
}

.volume-track {
  height: 6px;
  background: #0f1526;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 0.4rem;
}

.volume-fill {
  height: 100%;
  width: 0%;
  background: var(--success);
  transition: width 0.08s linear;
}

.controls {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}

.controls button,
.secondary-btn {
  padding: 0.62rem 0.35rem;
  border: none;
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 0.84rem;
  cursor: pointer;
  transition: background 0.16s;
}

.controls button:hover:not(:disabled),
.secondary-btn:hover {
  background: #203159;
}

.controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#recordBtn.recording {
  background: var(--accent);
}

.feedback {
  min-height: 2.3rem;
  font-size: 0.86rem;
  color: var(--text);
  background: rgba(22, 33, 62, 0.72);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  text-align: center;
  margin-bottom: 0.65rem;
  line-height: 1.4;
}

.t3-guide {
  background: var(--card);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
  margin-top: 0.4rem;
}

.t3-guide.hidden {
  display: none;
}

.t3-step {
  margin-bottom: 0.6rem;
}

.step-label {
  font-size: 0.82rem;
  display: block;
  margin-bottom: 0.25rem;
}

.step-bar {
  height: 7px;
  background: #0f0f1a;
  border-radius: 4px;
  overflow: hidden;
}

.step-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s;
}

.t3-note {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.38;
}

.level-list {
  display: grid;
  gap: 0.55rem;
}

.level-item {
  padding: 0.8rem 0.95rem;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid #2a3b61;
  font-size: 0.9rem;
}

.level-item.unlocked {
  cursor: pointer;
}

.level-item.unlocked:hover {
  border-color: var(--success);
}

.level-item.locked {
  opacity: 0.55;
}

.stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.65rem;
  font-size: 0.9rem;
}

.paywall-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.paywall-overlay.hidden {
  display: none;
}

.paywall-card {
  background: var(--card);
  padding: 1.6rem;
  border-radius: 16px;
  max-width: 400px;
  width: 92%;
  text-align: center;
  border: 1px solid var(--accent);
}

.paywall-card h2 {
  color: var(--accent);
  margin-bottom: 0.7rem;
  font-size: 1.2rem;
}

.paywall-card p {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 1rem;
  line-height: 1.4;
}

.paywall-card ul {
  text-align: left;
  margin-bottom: 1.15rem;
  font-size: 0.84rem;
  list-style: none;
  padding: 0 0.4rem;
}

.paywall-card li {
  margin-bottom: 0.45rem;
}

.buy-btn {
  width: 100%;
  padding: 0.85rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 0.7rem;
}

.close-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.84rem;
  text-decoration: underline;
  cursor: pointer;
}

@media (max-width: 540px) {
  .tone-selector {
    grid-template-columns: repeat(2, 1fr);
  }
  .controls {
    grid-template-columns: repeat(3, 1fr);
  }
  #pitchCanvas,
  #historyCanvas {
    height: 145px;
  }
}