/* ============================================================
   Dawtastic — app.css
   Tokens, layout, shell, landing, generic components only.
   Module styles live in steps.css / sampler.css / recorder.css / admin.css.
   ============================================================ */

/* ---- design tokens ---- */
:root {
  --bg: #111318;
  --surface: #1b1e26;
  --surface2: #242833;
  --text: #eef0f4;
  --muted: #9aa1af;
  --accent: #ffb02e;
  --accent2: #4cc9f0;
  --danger: #ef476f;
  --ok: #06d6a0;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---- base ---- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100vh; }

a { color: var(--accent2); }

h1, h2, h3 { margin: 0 0 0.5em; line-height: 1.2; }

input, button, select, textarea { font: inherit; color: inherit; }

/* ---- generic: buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  min-height: 44px;
  min-width: 44px;
  padding: 0.55em 1.1em;
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: filter 0.12s ease, transform 0.05s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn--primary { background: var(--accent); border-color: var(--accent); color: #1a1204; }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--ghost { background: transparent; border-color: var(--surface2); }
.btn--big { width: 100%; padding: 0.8em 1.2em; font-size: 1.05rem; }
.btn--round { border-radius: 50%; width: 48px; height: 48px; padding: 0; font-size: 1.2rem; }

/* ---- generic: cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 20px;
}
.card h2 { color: var(--accent); font-size: 1.15rem; }
.card p { color: var(--muted); margin: 0.4em 0 1em; }

/* ---- generic: form fields ---- */
.field { display: block; margin-bottom: 14px; }
.field span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 0.9rem; }
.field input,
input[type="text"], input[type="number"], input[type="password"] {
  width: 100%;
  min-height: 44px;
  padding: 0.5em 0.8em;
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: calc(var(--radius) - 4px);
  color: var(--text);
  outline: none;
}
.field input:focus,
input[type="text"]:focus, input[type="number"]:focus, input[type="password"]:focus {
  border-color: var(--accent2);
}
.form-error { color: var(--danger); font-size: 0.9rem; }

/* ---- generic: slider ---- */
.slider { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; background: transparent; }
.slider::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--surface2); }
.slider::-moz-range-track { height: 6px; border-radius: 3px; background: var(--surface2); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 24px; height: 24px; margin-top: -9px;
  border-radius: 50%; background: var(--accent); border: none;
}
.slider::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%; background: var(--accent); border: none;
}

/* ---- generic: toast ---- */
#toast-root {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}
.toast {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 10px 18px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.2s ease;
  max-width: min(90vw, 420px);
}
.toast--out { opacity: 0; transition: opacity 0.4s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- generic: dialog ---- */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 900;
}
.dialog {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.dialog h2 { color: var(--accent); }
.dialog p { color: var(--muted); }
.dialog-url {
  background: var(--bg);
  border: 1px dashed var(--accent2);
  border-radius: calc(var(--radius) - 4px);
  padding: 10px 12px;
  margin: 12px 0 16px;
  overflow-x: auto;
}
.dialog-url code { color: var(--accent2); font-size: 0.9rem; word-break: break-all; }
.dialog-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

/* ---- generic: bottom sheet ---- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 800;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 850;
  background: var(--surface);
  border-top: 1px solid var(--surface2);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  animation: sheet-in 0.22s ease;
}
@keyframes sheet-in { from { transform: translateY(30%); opacity: 0; } }
.sheet h2, .sheet h3 { color: var(--accent); }

/* ---- app shell ---- */
body.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
}
.app-logo {
  font-weight: 800;
  color: var(--accent);
  text-decoration: none;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.project-name {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 6px);
  color: var(--text);
  font-weight: 600;
  font-size: 1rem;
  padding: 6px 10px;
  min-height: 40px;
}
.project-name:hover { border-color: var(--surface2); }
.project-name:focus { border-color: var(--accent2); outline: none; background: var(--bg); }
.save-status { color: var(--ok); font-size: 0.85rem; white-space: nowrap; }
.save-status.is-saving { color: var(--muted); }
.save-status.is-offline { color: var(--danger); font-weight: 700; }

/* ---- transport bar ---- */
.transport {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
  flex-wrap: wrap;
}
.transport-play { background: var(--accent); border-color: var(--accent); color: #1a1204; font-size: 1.3rem; }
.transport-play.is-playing { background: var(--danger); border-color: var(--danger); color: #fff; }
.bpm-group { display: flex; align-items: center; gap: 6px; }
.bpm-field {
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--surface2);
  border-radius: calc(var(--radius) - 4px);
  padding: 4px 10px;
}
.bpm-field input {
  width: 58px;
  min-height: 36px;
  background: transparent;
  border: none;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
  -moz-appearance: textfield;
  appearance: textfield;
}
.bpm-field input::-webkit-outer-spin-button,
.bpm-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.bpm-field input:focus { outline: none; }
.bpm-field span { color: var(--muted); font-size: 0.8rem; }

/* metronome toggle */
.transport-metro {
  background: transparent;
  border-color: var(--surface2);
  color: var(--muted);
  white-space: nowrap;
}
.transport-metro.is-on {
  background: var(--surface2);
  color: var(--accent);
  border-color: var(--accent);
}

/* master volume */
.master-vol {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 0 1 160px;
}
.master-vol > span { color: var(--muted); font-size: 1.05rem; }
.master-vol .slider { width: 120px; min-width: 70px; }

/* ---- module tabs ---- */
.module-tabs { display: flex; gap: 6px; margin-left: auto; }
.module-tabs button {
  min-height: 44px;
  padding: 0.4em 1em;
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.module-tabs button.is-active {
  background: var(--surface2);
  color: var(--accent);
  border-color: var(--accent);
}

/* narrow / portrait: tabs get their own row, everything wraps cleanly */
@media (max-width: 940px) {
  .transport { row-gap: 8px; }
  .master-vol { flex: 1 1 110px; }
  .module-tabs {
    margin-left: 0;
    flex: 1 0 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
}

/* ---- module container ---- */
#module-root {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px calc(20px + env(safe-area-inset-bottom));
}

.notice { max-width: 480px; margin: 40px auto; }
.notice--center { text-align: center; }
.notice h1, .notice h2 { color: var(--accent); }

/* ---- landing ---- */
body.landing { display: flex; align-items: center; justify-content: center; padding: 20px; }
.landing-wrap { width: 100%; max-width: 880px; }
.landing-hero { text-align: center; margin-bottom: 32px; }
.landing-hero h1 {
  font-size: clamp(2.6rem, 8vw, 4rem);
  font-weight: 800;
  background: linear-gradient(100deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  margin-bottom: 0.2em;
}
.landing-hero p { color: var(--muted); font-size: 1.05rem; margin: 0; }
.landing-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}
.landing-footer { text-align: center; color: var(--muted); font-size: 0.85rem; margin-top: 28px; }
