:root {
  --bg: #0F0F0F;
  --surface: #1C1C1E;
  --raised: #2C2C2E;
  --text: #F5F5F7;
  --muted: #8E8E93;
  --accent: #007AFF;
  --green: #34C759;
  --red: #FF3B30;
  --orange: #FF9F0A;
  --border: #38383A;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans Khmer', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  touch-action: pan-y;
}

/* ============================================================ */
/* Header */
/* ============================================================ */
.header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(15,15,15,.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  flex-shrink: 0;
}

.hamburger {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo {
  font-size: 17px;
  font-weight: 700;
  flex: 1;
  margin-left: 8px;
  letter-spacing: -.3px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transition: background .3s, box-shadow .3s;
}

.status-dot[data-state="ready"] {
  background: var(--muted);
}

.status-dot[data-state="recording"] {
  background: var(--green);
  box-shadow: 0 0 8px rgba(52,199,89,.5);
  animation: pulse-dot 1.5s infinite;
}

.status-dot[data-state="processing"] {
  background: var(--orange);
  animation: spin-dot 1s linear infinite;
}

.status-dot[data-state="playing"] {
  background: var(--accent);
}

.status-dot[data-state="error"] {
  background: var(--red);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

@keyframes spin-dot {
  0% { opacity: 1; }
  50% { opacity: .3; }
  100% { opacity: 1; }
}

/* ============================================================ */
/* Language Bar */
/* ============================================================ */
.lang-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  flex-shrink: 0;
}

.lang-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 16px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: border-color .2s;
  min-width: 0;
}

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

.lang-code {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
}

.lang-name {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.swap-btn {
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color .2s;
}

.swap-btn:active {
  color: var(--accent);
}

/* ============================================================ */
/* Display Area */
/* ============================================================ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.display-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px 20px;
  min-height: 0;
  overflow-y: auto;
}

.transcript-box, .translation-box {
  min-height: 48px;
}

.text-content {
  font-size: 24px;
  line-height: 1.4;
  word-break: break-word;
  font-family: 'Noto Sans Khmer', -apple-system, sans-serif;
}

.translation-text {
  font-size: 28px;
  font-weight: 600;
  color: var(--accent);
}

.placeholder {
  text-align: center;
  padding: 40px 0;
}

.placeholder-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: .6;
}

.placeholder-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.placeholder-sub {
  font-size: 14px;
  color: var(--muted);
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
  opacity: .3;
}

/* Waveform */
.waveform {
  width: 100%;
  height: 48px;
  display: none;
  margin-top: auto;
}

.waveform.active {
  display: block;
}

/* Info bar */
.info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  flex-shrink: 0;
}

.info-text {
  font-size: 12px;
  color: var(--muted);
}

.latency {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ============================================================ */
/* Record Button */
/* ============================================================ */
.record-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 0;
  padding-bottom: max(12px, var(--safe-bottom));
  flex-shrink: 0;
}

.record-btn {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: none;
  background: var(--raised);
  color: var(--text);
  font-size: 38px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s, background .2s, box-shadow .2s;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  position: relative;
}

.record-btn:active {
  transform: scale(.92);
}

.record-btn.recording {
  background: var(--red);
  animation: pulse-rec 1.5s infinite;
}

.record-btn.playing {
  background: var(--accent);
}

.record-btn.error {
  background: var(--orange);
}

@keyframes pulse-rec {
  0% { box-shadow: 0 0 0 0 rgba(255,59,48,.4); }
  100% { box-shadow: 0 0 0 16px rgba(255,59,48,0); }
}

.record-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  margin-top: 4px;
}

/* ============================================================ */
/* Bottom Sheet */
/* ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  z-index: 101;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.32,.72,0,1);
  padding: 16px;
  padding-bottom: max(16px, var(--safe-bottom));
}

.bottom-sheet.active {
  transform: translateY(0);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.sheet-title {
  font-size: 16px;
  font-weight: 700;
}

.sheet-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

.sheet-role {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}

.sheet-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sheet-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  transition: border-color .2s;
  width: 100%;
  text-align: left;
}

.sheet-item:active {
  border-color: var(--accent);
}

.sheet-item .sheet-code {
  font-weight: 700;
  color: var(--accent);
  min-width: 28px;
}

.sheet-item .check {
  margin-left: auto;
  color: var(--accent);
  font-weight: 700;
  display: none;
}

.sheet-item.active .check {
  display: block;
}

/* ============================================================ */
/* Animations */
/* ============================================================ */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.text-content.new-text {
  animation: fade-in .2s ease-out;
}

/* ============================================================ */
/* Responsive */
/* ============================================================ */
@media (min-width: 500px) {
  body {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
