:root {
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --text: #232220;
  --text-muted: #6B6860;
  --accent-down: #B5651D;
  --accent-up: #2F6F62;
  --border: #E4E0D6;
  --danger: #B23A3A;
}

:root[data-theme="dark"] {
  --bg: #14181A;
  --surface: #1B2124;
  --text: #E7E9E4;
  --text-muted: #8A928F;
  --accent-down: #E0A458;
  --accent-up: #6FBFA0;
  --border: #2A3234;
  --danger: #D9736A;
}

* { box-sizing: border-box; }

/* Guarantees the `hidden` attribute always wins over any element's own
   display rule (flex, grid, etc.) — without this, any hidden-toggled
   element that also sets its own `display` stays visible. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  min-height: 100vh;
}

.screen { min-height: 100vh; }

/* ---------- Login ---------- */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card h1 { font-size: 22px; margin: 0 0 2px; font-weight: 600; }
.login-card .hint { margin: 0 0 8px; color: var(--text-muted); font-size: 14px; }

.login-card input {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
}

.login-card button {
  padding: 12px 14px;
  border-radius: 8px;
  border: none;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.error { color: var(--danger); font-size: 13px; margin: 0; }

/* ---------- Dashboard shell ---------- */

#dashboard-screen {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 20px 80px;
  transition: max-width 0.15s ease;
}

/* Give side-by-side mode more breathing room on wide screens */
#dashboard-screen:has(#sections[data-layout="side-by-side"]) {
  max-width: 920px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.topbar h1 { font-size: 20px; font-weight: 600; margin: 0; }
.topbar-actions { display: flex; gap: 6px; }

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

/* ---------- Sections (Up / Down) ---------- */

.sections {
  display: grid;
  grid-template-columns: 1fr;
  gap: 36px;
}

.sections[data-layout="side-by-side"] {
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}

/* Regardless of the chosen layout, collapse to one column once it's too
   tight to be useful — side-by-side is a desktop convenience, not a
   guarantee, so small screens always stay legible. */
@media (max-width: 640px) {
  .sections[data-layout="side-by-side"] {
    grid-template-columns: 1fr;
  }
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.section-up .section-title { color: var(--accent-up); }
.section-down .section-title { color: var(--accent-down); }

.timer-list { list-style: none; margin: 0; padding: 0; }

.timer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 4px;
  border-bottom: 1px solid var(--border);
  cursor: grab;
}

.timer-row.dragging { opacity: 0.4; }

.timer-row .handle {
  color: var(--text-muted);
  font-size: 14px;
  user-select: none;
  padding: 0 2px;
}

.timer-row .thumb {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
}

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

.timer-row .label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timer-row .readout {
  font-family: 'JetBrains Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 20px;
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
}

.timer-row.countdown .readout { color: var(--accent-down); }
.timer-row.countup .readout { color: var(--accent-up); }

.timer-row .readout .unit {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  margin-left: 3px;
  margin-right: 7px;
}

.timer-row .delete-btn {
  opacity: 0;
  transition: opacity 0.15s;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
}

.timer-row:hover .delete-btn { opacity: 1; }
.timer-row .delete-btn:hover { color: var(--danger); }

.empty-state {
  color: var(--text-muted);
  font-size: 13px;
  padding: 10px 4px;
}

/* ---------- Add form ---------- */

.add-toggle {
  margin-top: 16px;
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
}

.add-toggle:hover { color: var(--text); border-color: var(--text-muted); }

.add-form {
  margin-top: 16px;
  padding: 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.add-form input[type="text"],
.add-form input[type="datetime-local"] {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.add-form-row { display: flex; gap: 16px; }

.date-time-row { display: flex; gap: 10px; }
.date-time-row input { flex: 1; min-width: 0; }

.type-choice {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

.thumbnail-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
}

.thumbnail-preview {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px dashed var(--border);
  background: var(--bg) center/cover no-repeat;
  flex-shrink: 0;
}

.file-label {
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

.file-label input[type="file"] { display: none; }

.link-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}

.add-form-actions { display: flex; justify-content: flex-end; gap: 8px; }

.add-form-actions button {
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.add-form-actions button.secondary { background: transparent; color: var(--text-muted); }

/* ---------- Delete confirmation modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  max-width: 340px;
  width: 100%;
}

.modal h3 { margin: 0 0 8px; font-size: 16px; }
.modal-body { margin: 0 0 18px; font-size: 14px; color: var(--text-muted); }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.modal-actions button {
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.modal-actions button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }

@media (max-width: 480px) {
  .timer-row .readout { font-size: 16px; }
  .timer-row .readout .unit { margin-right: 4px; }
}
