:root {
  --bg: #0D1416;
  --surface: #141E21;
  --surface-2: #1B282C;
  --border: #28393F;
  --ink: #EFF4F3;
  --ink-2: #C2D0CE;
  --mute: #8AA09D;
  --accent: #399AA3;
  --accent-bright: #5BC0C9;
  --warm: #D9A86C;
  --danger: #D96B6B;
  --radius: 14px;
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0 0 calc(76px + env(safe-area-inset-bottom)) 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(13, 20, 22, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: radial-gradient(circle at center, rgba(239, 244, 243, 0.95) 0%, rgba(57, 154, 163, 0.45) 36%, rgba(13, 20, 22, 1) 76%);
  border: 1px solid rgba(217, 168, 108, 0.45);
  flex-shrink: 0;
}

.app-header h1 {
  margin: 0;
  font-family: 'Cormorant Garamond', 'Shippori Mincho', serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.15;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--mute);
}

.preset-pills {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.pill {
  border: none;
  background: transparent;
  color: var(--mute);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.pill.active {
  background: var(--accent);
  color: #071214;
}

/* Main */
.app-main {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  scroll-margin-top: 76px;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.step-badge {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  color: var(--warm);
  background: rgba(217, 168, 108, 0.14);
  border: 1px solid rgba(217, 168, 108, 0.35);
  padding: 3px 8px;
  border-radius: 6px;
}

.panel h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.hint {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--ink-2);
}

.micro-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--mute);
  line-height: 1.5;
}

/* Upload Drop */
.upload-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 22px 16px;
  border: 1.5px dashed var(--accent);
  border-radius: 12px;
  background: rgba(57, 154, 163, 0.08);
  cursor: pointer;
  text-align: center;
}

.upload-drop.compact {
  padding: 16px;
}

.upload-drop input {
  display: none;
}

.upload-icon {
  font-size: 24px;
  line-height: 1;
  color: var(--accent-bright);
}

.upload-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
}

.upload-sub {
  font-size: 12px;
  color: var(--mute);
}

/* Track List */
.track-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.track-stats {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--warm);
}

.track-actions {
  display: flex;
  gap: 6px;
}

.track-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.track-empty {
  text-align: center;
  padding: 18px 8px;
  color: var(--mute);
  font-size: 13px;
}

.track-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.track-num {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--accent-bright);
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.track-info {
  flex: 1;
  min-width: 0;
}

.track-title-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 2px 0;
}

.track-title-input:focus {
  outline: none;
  border-bottom-color: var(--accent-bright);
}

.track-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--mute);
  margin-top: 2px;
}

.track-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn.danger {
  color: var(--danger);
}

/* Controls */
.control-grid {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 16px;
}

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 700;
}

.val-badge {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--accent-bright);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent-bright);
  height: 28px;
}

.inline-toggle-range {
  display: flex;
  align-items: center;
  gap: 12px;
}

.loop-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: #2C3D42;
  border-radius: 999px;
  transition: 0.2s;
  cursor: pointer;
}

.slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: var(--ink);
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

/* Preview Canvas */
.canvas-preview-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #080E10;
  margin-bottom: 14px;
}

#bg-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Tabs & Chips */
.tab-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.tab-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 10px 6px;
  border-radius: 10px;
  cursor: pointer;
}

.tab-btn.active {
  border-color: var(--accent-bright);
  background: rgba(57, 154, 163, 0.2);
  color: var(--ink);
}

.bg-tab-pane {
  display: none;
}

.bg-tab-pane.active {
  display: block;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 12px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.chip.active, .chip:active {
  border-color: var(--warm);
  color: var(--warm);
  background: rgba(217, 168, 108, 0.14);
}

/* Fields */
.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--ink-2);
  margin-bottom: 5px;
}

.field input[type="text"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
}

.field textarea {
  font-family: 'IBM Plex Mono', 'Noto Sans JP', monospace;
  font-size: 12.5px;
  line-height: 1.55;
  resize: vertical;
}

.key-row {
  display: flex;
  gap: 8px;
}

.field-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sub-divider {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-bottom: 14px;
}

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

/* Buttons */
.btn-primary, .btn-secondary, .btn-ghost {
  font-family: inherit;
  font-weight: 700;
  border-radius: 11px;
  cursor: pointer;
  min-height: 44px;
  padding: 10px 16px;
  font-size: 14px;
  border: 1px solid transparent;
  transition: opacity 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #061214;
}

.btn-primary:disabled, .btn-secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  border-color: var(--border);
}

.btn-sm {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-lg {
  min-height: 52px;
  font-size: 16px;
}

.btn-full {
  width: 100%;
}

.export-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.status-msg {
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--warm);
  min-height: 18px;
}

/* Progress */
.progress-area {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin: 12px 0;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 8px;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 10px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--warm));
  transition: width 0.2s;
}

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(13, 20, 22, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}

.bottom-nav a {
  text-align: center;
  text-decoration: none;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
  padding: 8px 4px;
  border-radius: 8px;
}

.bottom-nav a:active {
  background: var(--surface-2);
  color: var(--accent-bright);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(74px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #1F3136;
  color: var(--ink);
  border: 1px solid var(--accent-bright);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s;
  z-index: 50;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
