:root {
  color-scheme: light;
  font-family: 'Segoe UI', 'Hiragino Sans', 'Yu Gothic', system-ui, -apple-system,
    BlinkMacSystemFont, sans-serif;
  --bg: #f5f6fb;
  --surface: #ffffff;
  --border: #e0e3eb;
  --text: #1f2940;
  --muted: #6f7795;
  --primary: #3d7eff;
  --primary-dark: #2853c5;
  --accent: #f44336;
  --success: #4caf50;
  --warn: #ffc107;
  --shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #fdf3ff, var(--bg));
  color: var(--text);
}

.app-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 24px 64px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.eyebrow {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin: 0 0 8px;
}

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 4vw, 3rem);
}

.tagline {
  margin-top: 8px;
  font-size: 1.1rem;
  color: var(--muted);
}

.stat-pill {
  background: rgba(61, 126, 255, 0.1);
  color: var(--primary);
  font-size: 1rem;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(61, 126, 255, 0.25);
}

main {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
}

.card {
  background: var(--surface);
  border-radius: 24px;
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.control-panel {
  grid-column: 1 / -1;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
}

.primary-btn {
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: 1rem;
  padding: 14px 28px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(61, 126, 255, 0.4);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.primary-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  box-shadow: none;
}

.primary-btn:not(:disabled):hover {
  transform: translateY(-2px);
}

.state-text {
  font-weight: 600;
}

.error-text {
  min-height: 1em;
  color: var(--accent);
  margin: 8px 0 0;
}

.privacy-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.settings-panel h2,
.meter-panel h2 {
  margin: 0 0 8px;
}

.settings-panel p {
  margin: 4px 0 12px;
  color: var(--muted);
}

.range-label {
  font-weight: 600;
  margin-bottom: 8px;
  display: inline-block;
}

input[type='range'] {
  width: 100%;
  accent-color: var(--primary);
}

.range-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
}

.character-panel {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.speech-bubble {
  background: #fffbe6;
  border: 2px solid #ffe58f;
  border-radius: 18px;
  padding: 12px 18px;
  font-weight: 600;
  max-width: 320px;
  position: relative;
}

.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 40px;
  border-width: 12px 12px 0 12px;
  border-style: solid;
  border-color: #ffe58f transparent transparent transparent;
}

.character-figure {
  font-size: clamp(4rem, 15vw, 7rem);
  line-height: 1;
  filter: drop-shadow(0 10px 22px rgba(0, 0, 0, 0.1));
}

.character-state {
  margin: 0;
  font-weight: 600;
  color: var(--muted);
}

.meter {
  width: 100%;
  height: 32px;
  border-radius: 16px;
  background: #eceff5;
  overflow: hidden;
  border: 1px solid #d5d9e5;
}

.meter-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--success), var(--warn), var(--accent));
  transition: width 0.1s linear;
}

.volume-text {
  font-weight: 600;
  margin-top: 12px;
}

#historyCanvas {
  width: 100%;
  height: auto;
  margin-top: 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #0f172a;
}

.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  .app-shell {
    padding: 32px 16px 48px;
  }

  main {
    grid-template-columns: 1fr;
  }

  .control-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .stat-pill {
    width: 100%;
    text-align: center;
  }
}
