/* ── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0d0d0d;
  --bg2:         #141414;
  --bg3:         #1c1c1c;
  --bg4:         #242424;
  --border:      #2a2a2a;
  --border2:     #333333;
  --text:        #e8e8e8;
  --text2:       #999999;
  --text3:       #555555;
  --accent:      #4a9eff;
  --accent2:     #1a6fd4;
  --accent-dim:  #1a3a5c;
  --danger:      #ff4444;
  --mono:        'SF Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
  --sans:        -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --ctrl-h:      56px;
  --titlebar-h:  44px;
  --sidebar-w:   300px;
  --note-h:      240px;
  --radius:      6px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Title Bar ───────────────────────────────────────────────────────────── */
#titlebar {
  height: var(--titlebar-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0px);
  gap: 12px;
  position: relative;
  flex-shrink: 0;
  z-index: 100;
}

#app-title {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--text2);
}

#file-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  position: absolute;
  right: 150px;
}

#close-file-btn {
  position: absolute;
  right: 12px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 5px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--sans);
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 32px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.12s, border-color 0.12s;
}
#close-file-btn:active { color: var(--danger); border-color: var(--danger); }
#close-file-btn.hidden { display: none; }

/* Sidebar hidden state */
#sidebar {
  transition: width 0.25s ease, opacity 0.25s ease;
}
#sidebar.collapsed {
  width: 0;
  opacity: 0;
  overflow: hidden;
  border-left: none;
}
#sidebar-toggle-btn.active { color: var(--accent); }

/* ── Layout ──────────────────────────────────────────────────────────────── */
#layout {
  display: flex;
  height: calc(100dvh - var(--titlebar-h));
  overflow: hidden;
}

/* ── Player Column ───────────────────────────────────────────────────────── */
#player-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  background: #000;
}

/* ── Drop Zone ───────────────────────────────────────────────────────────── */
#drop-zone {
  flex: 1;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  min-height: 0;
}
#drop-zone.active { display: flex; }

#drop-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text3);
}
#drop-content svg { color: var(--text3); }
#drop-content p { font-size: 16px; color: var(--text2); }
#drop-content p.sub { font-size: 12px; color: var(--text3); margin-top: -6px; }
#drop-content .formats {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text3);
  letter-spacing: 0.05em;
}

#file-input { display: none; }

#open-btn {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 12px 28px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 15px;
  font-family: var(--sans);
  display: inline-block;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  display: flex;
  align-items: center;
}

/* ── Video ───────────────────────────────────────────────────────────────── */
#video {
  flex: 1;
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  min-height: 0;
}
#video.active { display: block; }

/* ── Controls Bar ────────────────────────────────────────────────────────── */
#controls {
  height: var(--ctrl-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  padding-bottom: max(0px, calc(var(--safe-bottom) - 8px));
  gap: 10px;
  flex-shrink: 0;
  z-index: 10;
}

.ctrl-btn {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.ctrl-btn:active { background: var(--bg3); color: var(--text); }
.ctrl-btn.note-trigger:active { color: var(--accent); }

.ctrl-label {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text3);
  letter-spacing: 0.1em;
  flex-shrink: 0;
}

.time-mono {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text2);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Progress Bar ────────────────────────────────────────────────────────── */
#progress-wrap {
  flex: 1;
  height: var(--ctrl-h);
  display: flex;
  align-items: center;
  cursor: pointer;
  min-width: 0;
  -webkit-tap-highlight-color: transparent;
}

#progress-bg {
  width: 100%;
  height: 5px;
  background: var(--bg4);
  border-radius: 3px;
  position: relative;
}

#progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  pointer-events: none;
}

#progress-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  pointer-events: none;
  left: 0%;
}

/* ── Speed Control ───────────────────────────────────────────────────────── */
#speed-wrap {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
#speed-display {
  font-size: 12px;
  min-width: 30px;
  text-align: center;
  color: var(--text);
}
.speed-btn {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 14px;
  padding: 6px 5px;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  border-radius: 4px;
}
.speed-btn:active { color: var(--accent); background: var(--bg3); }

/* ── Note Panel ──────────────────────────────────────────────────────────── */
#note-panel {
  position: absolute;
  bottom: var(--ctrl-h);
  left: 0;
  right: 0;
  height: var(--note-h);
  background: var(--bg2);
  border-top: 2px solid var(--accent);
  display: flex;
  flex-direction: column;
  z-index: 50;
  animation: slide-up 0.2s ease-out;
}
#note-panel.hidden { display: none; }

@keyframes slide-up {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

#note-panel-header {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-shrink: 0;
}
#note-meta { display: flex; align-items: center; gap: 8px; flex: 1; flex-wrap: wrap; }

.meta-label {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--text3);
}
.note-ts-display {
  color: var(--accent);
  font-size: 13px;
  background: var(--accent-dim);
  padding: 3px 9px;
  border-radius: 3px;
}
.meta-sep { color: var(--border2); }
.note-datetime-display {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text2);
}

#note-close-btn {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 16px;
  padding: 6px 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  -webkit-tap-highlight-color: transparent;
}
#note-close-btn:active { color: var(--danger); background: #2a1a1a; }

#note-text {
  flex: 1;
  background: var(--bg2);
  border: none;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  padding: 10px 14px;
  resize: none;
  outline: none;
  min-height: 0;
  -webkit-user-select: text;
  user-select: text;
}
#note-text::placeholder { color: var(--text3); }

#note-panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#note-save-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 10px 22px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-family: var(--sans);
  font-weight: 600;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
#note-save-btn:active { background: var(--accent2); }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#sidebar-title {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--text2);
}
#note-count {
  background: var(--bg4);
  border: 1px solid var(--border2);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  color: var(--text2);
}

/* ── Notes List ──────────────────────────────────────────────────────────── */
#notes-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0;
}
#notes-list::-webkit-scrollbar { width: 3px; }
#notes-list::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

#notes-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text3);
  line-height: 1.7;
}
#notes-empty .sub { font-size: 12px; margin-top: 6px; }

.note-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.note-item:last-child { border-bottom: none; }

.note-item-header {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}
.note-item-ts {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 7px;
  border-radius: 2px;
  cursor: pointer;
  flex-shrink: 0;
  min-height: 28px;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}
.note-item-ts:active { background: var(--accent); color: #fff; }

.note-item-dt {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text3);
}
.note-item-delete {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 13px;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.note-item-delete:active { color: var(--danger); }

.note-item-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Sidebar Footer ──────────────────────────────────────────────────────── */
#sidebar-footer {
  padding: 12px 14px;
  padding-bottom: calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#export-btn {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 11px 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--sans);
  font-weight: 500;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
#export-btn:not(:disabled):active {
  background: var(--bg4);
  color: var(--accent);
}
#export-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Flash overlay ───────────────────────────────────────────────────────── */
.seek-flash {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--mono);
  font-size: 22px;
  color: rgba(255,255,255,0.9);
  background: rgba(0,0,0,0.6);
  padding: 8px 18px;
  border-radius: 6px;
  pointer-events: none;
  animation: flash-out 0.65s ease-out forwards;
}
@keyframes flash-out {
  0%   { opacity: 1; }
  65%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── iPad landscape tweak ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 260px; }
  #file-label { display: none; }
}
@media (max-width: 600px) {
  :root { --sidebar-w: 220px; }
}
