:root {
  --bg: #0a0a12;
  --panel-bg: rgba(12, 12, 20, 0.82);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e8eaf0;
  --text-muted: rgba(232, 234, 240, 0.55);
  --accent: #a8c8ff;
  --accent-dim: rgba(168, 200, 255, 0.25);
  --radius: 12px;
  --panel-w: min(380px, calc(100vw - 24px));
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

/* ── Ambient light layer ── */
.ambient-light {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: radial-gradient(ellipse 80% 70% at 50% 45%, hsl(220 60% 55% / 0.5), hsl(220 40% 8% / 0.95));
  transition: background 0.15s ease;
  will-change: opacity, filter;
}

.grain-canvas {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.04;
  mix-blend-mode: overlay;
}

/* ── Start screen ── */
.start-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 6, 14, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

.start-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-screen__inner {
  text-align: center;
  padding: 2rem;
  position: relative;
}

.start-screen__glow {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 200px;
  height: 200px;
  transform: translate(-50%, -60%);
  background: radial-gradient(circle, rgba(168, 200, 255, 0.3), transparent 70%);
  border-radius: 50%;
  animation: glow-pulse 3s ease-in-out infinite;
}

@keyframes glow-pulse {
  0%, 100% { transform: translate(-50%, -60%) scale(1); opacity: 0.6; }
  50% { transform: translate(-50%, -60%) scale(1.2); opacity: 1; }
}

.start-screen__title {
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  font-weight: 300;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
  position: relative;
}

.start-screen__sub {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 2rem;
  position: relative;
}

.start-screen__note {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 1rem;
  position: relative;
}

.btn-start {
  position: relative;
  padding: 0.9rem 2.8rem;
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--bg);
  background: var(--accent);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-start:hover { transform: scale(1.04); box-shadow: 0 0 30px rgba(168, 200, 255, 0.4); }
.btn-start:active { transform: scale(0.97); }

/* ── Panel ── */
.panel {
  position: fixed;
  top: calc(12px + var(--safe-top));
  right: 12px;
  z-index: 50;
  width: var(--panel-w);
  max-height: calc(100vh - 24px - var(--safe-top) - var(--safe-bottom));
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.panel.is-hidden {
  transform: translateX(calc(100% + 20px));
  opacity: 0;
  pointer-events: none;
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.panel__title {
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel__actions { display: flex; gap: 4px; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }

.panel__body {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0 16px;
}

.section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--panel-border);
}

.section:last-child { border-bottom: none; }

.section__title {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.section__hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ── Sliders ── */
.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  margin-bottom: 6px;
  margin-top: 10px;
}

.slider-label:first-child { margin-top: 0; }

.slider-val {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
}

.slider {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(168, 200, 255, 0.5);
  cursor: pointer;
}

.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

/* ── Transport ── */
.transport {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.transport__btn {
  flex: 1;
  padding: 8px;
  font-size: 0.85rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.transport__btn:hover { background: rgba(255,255,255,0.1); color: var(--text); }
.transport__btn--play.is-playing { background: var(--accent-dim); color: var(--accent); }

.audio-status {
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
  min-height: 1.2em;
}

.audio-status.is-playing { color: var(--accent); }
.audio-status.is-muted { color: #f0a060; }

.noise-item { cursor: pointer; }

.noise-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.noise-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.03);
  border: 1px solid transparent;
  border-radius: 8px;
  transition: border-color 0.15s, background 0.15s;
}

.noise-item.is-active {
  border-color: var(--accent-dim);
  background: rgba(168, 200, 255, 0.06);
}

#ios-audio-bridge {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.start-screen__ios-hint {
  color: #f0a060;
  font-size: 0.8rem;
  margin-top: 0.75rem;
  position: relative;
}

.audio-help {
  margin-top: 6px;
  font-size: 0.68rem;
  line-height: 1.4;
  color: #f0a060;
}

.noise-group__label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 10px 0 4px;
  padding-left: 2px;
}

.noise-group__label:first-child { margin-top: 0; }

.noise-item__toggle {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.noise-item__info { min-width: 0; }

.noise-item__name {
  font-size: 0.85rem;
  font-weight: 500;
  display: block;
}

.noise-item__desc {
  font-size: 0.68rem;
  color: var(--text-muted);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.noise-item__vol {
  width: 72px;
  height: 3px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.noise-item__vol::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
}

.noise-item__vol::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
}

/* ── Controls ── */
.control-grid { display: flex; flex-direction: column; }

.color-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.color-field input[type="color"] {
  width: 40px;
  height: 28px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  padding: 2px;
}

.select-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  margin-top: 10px;
}

.select-field select {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 8px;
  font-size: 0.78rem;
  cursor: pointer;
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  margin-top: 10px;
  cursor: pointer;
}

.toggle-field input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ── Presets ── */
.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.preset-btn {
  padding: 10px 8px;
  font-size: 0.78rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-align: center;
}

.preset-btn:hover {
  background: var(--accent-dim);
  border-color: rgba(168, 200, 255, 0.3);
}

/* ── Show panel button ── */
.show-panel-btn {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  right: 20px;
  z-index: 40;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  color: var(--accent);
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  transition: transform 0.2s;
}

.show-panel-btn:hover { transform: scale(1.08); }

/* ── Mobile adjustments ── */
@media (max-width: 480px) {
  .panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 70vh;
    border-radius: var(--radius) var(--radius) 0 0;
    padding-bottom: var(--safe-bottom);
  }

  .panel.is-hidden {
    transform: translateY(calc(100% + 20px));
  }
}
