/* Field Diary — self-contained mobile-first styles (no external deps) */
:root {
  color-scheme: light;
  --paper: #fbfaf7;
  --paper-deep: #f1ece4;
  --ink: #24211d;
  --muted: #706a61;
  --faint: #9b9286;
  --line: rgba(36, 33, 29, 0.14);
  --card: #fffdf8;
  --accent: #b7472a;
  --accent-dark: #7f2e1c;
  --green: #2f6f4e;
  --danger: #9f2d2d;
  --shadow: 0 18px 45px rgba(64, 44, 24, 0.09), 0 2px 8px rgba(64, 44, 24, 0.06);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* App shell */
.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 14px 28px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.app-title {
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.app-title .dot { color: var(--accent); }

.header-actions button {
  font-size: 0.9rem;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}

.view { display: none; }
.view.active { display: block; }

/* Buttons — thumb friendly */
.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-weight: 700;
  padding: 14px 20px;
  min-height: 56px;
  min-width: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.04s ease, box-shadow 0.1s ease;
  touch-action: manipulation;
  user-select: none;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(183, 71, 42, 0.28);
}
.btn-primary:disabled {
  background: #d2b8a8;
  color: #f5f0e9;
  box-shadow: none;
  cursor: not-allowed;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-ghost:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-large {
  font-size: 1.15rem;
  padding: 18px 24px;
  min-height: 64px;
  border-radius: 18px;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.btn-row > .btn { flex: 1 1 120px; }
/* Pause button is compact icon+text to leave room for large snapshot/stop */
#btn-pause {
  flex: 0 0 auto;
  min-width: 62px;
  padding: 12px 8px;
  font-size: 0.95rem;
  min-height: 56px;
}

/* Start view */
.privacy {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 12px 0 20px;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--muted);
}
.privacy strong { color: var(--ink); }

.start-panel {
  text-align: center;
  margin-top: 8px;
}

.start-panel h2 {
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  font-size: 1.6rem;
  margin: 8px 0 6px;
  letter-spacing: -0.025em;
}

.start-panel p.lead {
  color: var(--muted);
  margin: 0 0 20px;
  font-size: 1.02rem;
}

.form-row { margin: 16px 0; text-align: left; }
.form-row label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9rem; color: var(--muted); }
.form-row input[type="text"] {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
}

.option-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 10px 0 16px;
  cursor: pointer;
}
.option-card input { margin-top: 3px; transform: scale(1.15); }
.option-card strong { display: block; font-size: 0.95rem; }
.option-card small { display: block; color: var(--muted); line-height: 1.35; margin-top: 2px; }

/* Recording view */
.recording-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.recording-header .status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--danger);
  font-size: 0.95rem;
}
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger);
  animation: pulse 1.4s infinite ease-in-out;
}
@keyframes pulse {
  0%,100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.video-wrap {
  position: relative;
  background: #111;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  aspect-ratio: 4 / 3; /* reasonable phone preview */
  max-height: 58vh;
  touch-action: none; /* let the app handle two-finger camera zoom instead of page zoom */
  overscroll-behavior: contain;
}
.video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Zoom controls (badge + hint inside video-wrap) */
.zoom-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.78rem;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  pointer-events: none;
  user-select: none;
}
.zoom-hint {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  background: rgba(0,0,0,0.45);
  color: rgba(255,255,255,0.85);
  font-size: 0.60rem;
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  font-family: ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.01em;
}
.zoom-buttons {
  position: absolute;
  right: 10px;
  bottom: 22px;
  z-index: 3;
  display: flex;
  gap: 6px;
}
.zoom-buttons button {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.62);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
  font-weight: 800;
  touch-action: manipulation;
}
.zoom-buttons button:active { transform: translateY(1px); }

.rec-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.timer {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: clamp(2.1rem, 9vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  padding: 4px 0;
  min-width: 120px;
}

.level {
  flex: 1 1 180px;
  min-width: 140px;
}
.level-label { font-size: 0.75rem; color: var(--muted); margin-bottom: 4px; }
.level-track {
  height: 10px;
  background: var(--paper-deep);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.level-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), #4a8f6a);
  transition: width 80ms linear;
}
.level-fill.warning { background: linear-gradient(90deg, #d1972f, #e1b24f); }
.level-fill.danger { background: linear-gradient(90deg, var(--danger), #c95757); }

.audio-health {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  margin: -2px 0 12px;
}
.audio-health-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 2px;
}
.audio-health-text {
  font-weight: 700;
  font-size: 0.92rem;
}
.audio-health-detail {
  color: var(--muted);
  font-size: 0.74rem;
  margin-top: 2px;
  line-height: 1.25;
}
.audio-settings-text {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.72rem;
  text-align: right;
  max-width: 45%;
  line-height: 1.25;
}

.snap-status {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  margin-bottom: 12px;
}
.snap-count { font-weight: 700; }
.last-thumb {
  width: 72px; height: 54px;
  background: #111;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  flex-shrink: 0;
}
.last-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.last-thumb.empty { display: grid; place-items: center; color: var(--faint); font-size: 0.7rem; }

.quick-note {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.quick-note label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.quick-note-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.quick-note textarea {
  flex: 1 1 auto;
  min-height: 64px;
  max-height: 28vh;
  font: inherit;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  resize: vertical;
}
.quick-note .btn {
  flex: 0 0 104px;
  min-height: 64px;
  padding: 10px 12px;
}
.quick-note-meta {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 6px;
}
.recent-notes {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
}
.recent-note {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 6px 8px;
  background: var(--paper-deep);
  border-radius: 10px;
  font-size: 0.86rem;
}
.recent-note-time {
  flex: 0 0 auto;
  color: var(--accent-dark);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 800;
}
.recent-note-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Review view */
.review-header h2 { margin: 4px 0 2px; font-size: 1.35rem; }
.meta-line { color: var(--muted); font-size: 0.9rem; margin-bottom: 10px; }

.playback {
  display: none;
}

.field-player {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  margin: 12px 0 4px;
}
.field-player.disabled {
  opacity: 0.62;
}
.field-player #btn-player-toggle {
  flex: 0 0 auto;
  min-width: 92px;
}
.field-player-main {
  flex: 1 1 auto;
  min-width: 0;
}
.field-player-progress {
  width: 100%;
  accent-color: var(--accent);
}
.field-player-time {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  margin-top: 2px;
}
.notes {
  width: 100%;
  min-height: 110px;
  font: inherit;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  resize: vertical;
  margin-bottom: 12px;
}

.gallery-title { font-weight: 700; margin: 8px 0 6px; font-size: 0.95rem; }
.field-notes-review { margin: 4px 0 14px; }
.field-notes-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.field-note-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.field-note-time {
  color: var(--accent-dark);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 800;
  margin-bottom: 4px;
}
.field-note-text {
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.snap-item {
  position: relative;
  background: #111;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.snap-item img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}
.snap-item .snap-time {
  position: absolute;
  left: 6px; bottom: 6px;
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  background: rgba(0,0,0,0.65);
  color: #fff;
  padding: 1px 6px;
  border-radius: 4px;
  pointer-events: none;
}
.snap-item .dl-btn {
  position: absolute;
  top: 6px; right: 6px;
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255,255,255,0.9);
  color: var(--ink);
  border: 0;
  cursor: pointer;
}

.empty-gallery {
  padding: 18px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 12px;
}

/* History */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.session-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.session-card .title { font-weight: 700; margin: 0 0 4px; }
.session-card .meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 8px; }
.session-card .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.session-card .actions .btn { flex: 1 1 auto; min-height: 42px; padding: 8px 14px; font-size: 0.9rem; }

/* Diagnostics */
.diag {
  margin-top: 24px;
  font-size: 0.8rem;
  color: var(--muted);
}
.diag summary { cursor: pointer; color: var(--faint); }
.diag ul { margin: 6px 0 0; padding-left: 18px; }
.diag li { margin: 2px 0; }

/* Messages */
.message {
  padding: 10px 12px;
  border-radius: 10px;
  margin: 10px 0;
  font-size: 0.95rem;
}
.message.error { background: #fde8e8; color: #7f2e2e; border: 1px solid #f0b3b3; }
.message.success { background: #e8f5e9; color: #2f6f4e; border: 1px solid #a8d5b0; }
.message.info { background: #f1f0eb; color: var(--muted); border: 1px solid var(--line); }

/* Small utils */
.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.muted { color: var(--muted); }

/* Mobile tweaks */
@media (max-width: 480px) {
  .app { padding: 10px 10px 24px; }
  .timer { font-size: 2.4rem; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .btn-row { gap: 6px; }
  .btn-large { font-size: 1.0rem; padding: 14px 12px; min-height: 56px; }
  #btn-pause { min-width: 56px; padding: 10px 6px; font-size: 0.9rem; }
  .audio-health { flex-direction: column; gap: 4px; }
  .audio-settings-text { max-width: none; text-align: left; }
  .field-player { align-items: stretch; }
  .field-player #btn-player-toggle { min-width: 78px; }
  .quick-note-row { flex-direction: column; }
  .quick-note .btn { flex-basis: auto; width: 100%; }
}

/* Landscape / larger phones */
@media (min-width: 640px) and (orientation: landscape) {
  .video-wrap { aspect-ratio: 16 / 9; max-height: 48vh; }
}