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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --accent: #e94560;
  --accent-dim: #c73a52;
  --text-primary: #eee;
  --text-secondary: #aab;
  --text-muted: #667;
  --danger: #e94560;
  --success: #2ecc71;
  --border: #2a2a4a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* Header */
#header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

#header h1 {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
  text-align: center;
}

.header-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 20px;
  padding: 8px;
  cursor: pointer;
  width: 40px;
}

.header-spacer {
  width: 40px;
}

.hidden {
  display: none !important;
}

/* Screens */
.screen {
  display: none;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* Recording List Screen */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  padding: 40px;
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.empty-state .sub {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 8px;
}

.recording-list {
  list-style: none;
  padding: 8px;
  flex: 1;
}

.recording-item {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 12px;
}

.recording-item:active {
  background: var(--bg-card);
}

.recording-item-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 20px;
}

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

.recording-item-title {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recording-item-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  display: flex;
  gap: 12px;
}

.recording-item-duration {
  font-size: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* FAB */
.fab {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(233, 69, 96, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
  z-index: 5;
}

.fab:active {
  transform: scale(0.92);
}

.fab-icon {
  display: block;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
}

/* Record Screen */
.record-container {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.spectrogram-wrapper {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
}

#spectrogram-canvas,
#playback-spectrogram {
  display: block;
  width: 100%;
  height: 200px;
}

.freq-labels {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 20px; /* leave room for time axis */
  width: 50px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4px 4px;
  pointer-events: none;
}

.freq-label {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.5);
  text-align: right;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
}

/* Spectrum Display */
.spectrum-section {
  flex-shrink: 0;
}

.spectrum-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 4px 2px;
}

.spectrum-title {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.peak-freq {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.spectrum-wrapper {
  background: var(--bg-secondary);
  border-radius: 10px;
  overflow: hidden;
}

.spectrum-wrapper canvas {
  display: block;
  width: 100%;
  height: 120px;
}

/* Vibration Display */
.vibration-section {
  flex-shrink: 0;
}

.vibration-wrapper {
  background: var(--bg-secondary);
  border-radius: 10px;
  overflow: hidden;
}

.vibration-wrapper canvas {
  display: block;
  width: 100%;
  height: 100px;
}

.playback-cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: white;
  pointer-events: none;
  left: 0;
}

#screen-playback .spectrogram-wrapper {
  cursor: pointer;
}

.range-selection {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(233, 69, 96, 0.2);
  border-left: 2px solid var(--accent);
  border-right: 2px solid var(--accent);
  pointer-events: none;
}

.range-info {
  font-size: 12px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.btn-loop {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.btn-clear-range {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.record-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
}

.record-time {
  font-size: 32px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
}

.record-status {
  font-size: 14px;
  color: var(--text-secondary);
}

.record-status.recording {
  color: var(--accent);
}

.record-controls {
  display: flex;
  justify-content: center;
  padding: 8px 0;
}

.btn-record {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid var(--text-primary);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-record .record-dot {
  display: block;
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 50%;
  transition: all 0.2s;
}

.btn-record.recording .record-dot {
  width: 24px;
  height: 24px;
  border-radius: 4px;
}

/* Memo Section */
.memo-section {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 16px;
}

.memo-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.memo-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.memo-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.memo-field.full-width {
  grid-column: 1 / -1;
}

.memo-field label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.memo-field select,
.memo-field input,
.memo-field textarea {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
}

.memo-field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23aab' fill='none' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.memo-field textarea {
  resize: vertical;
  min-height: 60px;
}

.memo-field input:focus,
.memo-field select:focus,
.memo-field textarea:focus {
  border-color: var(--accent);
}

/* Playback Screen */
.playback-container {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.playback-info {
  text-align: center;
  font-size: 24px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
}

.playback-controls {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.btn-play {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-play:active {
  background: var(--accent-dim);
}

.playback-memo {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 16px;
}

.playback-memo-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.playback-memo-row:last-child {
  border-bottom: none;
}

.playback-memo-label {
  color: var(--text-secondary);
  flex-shrink: 0;
}

.playback-memo-value {
  text-align: right;
  word-break: break-all;
}

.playback-actions {
  display: flex;
  gap: 12px;
}

.btn-action {
  flex: 1;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.btn-action:active {
  background: var(--bg-card);
}

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

.btn-danger:active {
  background: rgba(233, 69, 96, 0.15);
}

/* List Toolbar */
.list-toolbar {
  display: flex;
  gap: 8px;
  padding: 8px 8px 0;
  flex-shrink: 0;
}

.btn-toolbar {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.btn-toolbar:active {
  background: var(--bg-card);
}

.btn-toolbar:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Selection mode for recording list */
.recording-item.selectable {
  padding-left: 12px;
}

.recording-item .select-check {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid var(--text-muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: transparent;
  transition: all 0.15s;
}

.recording-item.selected .select-check {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Compare Screen */
.compare-container {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.compare-track {
  background: var(--bg-secondary);
  border-radius: 10px;
  padding: 10px;
  flex-shrink: 0;
}

.compare-track-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.compare-track-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.compare-track-db {
  font-size: 18px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.compare-spectrogram-wrapper {
  position: relative;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
}

.compare-spectrogram-wrapper canvas {
  display: block;
  width: 100%;
  height: 120px;
}

.compare-cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(255,255,255,0.8);
  pointer-events: none;
  display: none;
}

.compare-cursor-time {
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  padding: 8px 0 0;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
