:root {
  --bg: #1B2420;
  --surface: #22302A;
  --surface-raised: #2A3B33;
  --border: rgba(237, 239, 232, 0.12);
  --text: #EDEFE8;
  --text-muted: #8FA396;
  --accent: #E8B44A;
  --accent-ink: #2A2110;
  --danger: #E4785C;
  --done: #7FB985;
  --font-display: "Fraunces", serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 0.95rem;
}

input, select, textarea {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  width: 100%;
}

input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.7rem;
  margin-bottom: 0.3rem;
  display: block;
}

.wordmark {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 500;
  margin: 0;
  letter-spacing: -0.01em;
}

/* ---------- Lock screen ---------- */
.lock {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lock-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.lock-card button {
  margin-top: 1rem;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 8px;
  padding: 0.6rem;
  font-weight: 600;
}
.error { color: var(--danger); font-size: 0.85rem; }

/* ---------- Layout ---------- */
.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem;
}
.tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.45rem 1rem;
  border-radius: 999px;
  font-weight: 500;
  font-size: 0.9rem;
}
.tab.active {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ---------- Week view ---------- */
.week-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}
.week-label { text-align: center; }
.week-range {
  font-family: var(--font-display);
  font-size: 1.3rem;
  display: block;
}
.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-decoration: underline;
  padding: 0;
}
.ghost-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.6rem;
}
@media (max-width: 900px) {
  .week-grid { grid-template-columns: repeat(2, 1fr); }
}

.day-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.day-col.is-today { border-color: var(--accent); }
.day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.day-head .day-name { color: var(--text); font-weight: 600; }

.session-card {
  background: var(--surface-raised);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  border-left: 3px solid var(--accent);
  cursor: pointer;
}
.session-card.is-done { border-left-color: var(--done); }
.session-subject { font-weight: 600; font-size: 0.88rem; }
.session-meta { color: var(--text-muted); font-size: 0.75rem; font-family: var(--font-mono); }

.add-session-btn {
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 0.5rem;
  font-size: 0.85rem;
  margin-top: auto;
}
.add-session-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Dashboard ---------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
}
.stat-label { color: var(--text-muted); font-size: 0.8rem; margin: 0 0 0.3rem; }
.stat-number {
  font-family: var(--font-mono);
  font-size: 2.1rem;
  font-weight: 600;
  margin: 0;
  color: var(--accent);
}
.stat-unit { font-size: 1.1rem; color: var(--text-muted); margin-left: 0.15rem; }

.chart-row {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 1rem;
}
@media (max-width: 800px) {
  .stat-row, .chart-row { grid-template-columns: 1fr; }
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
}
.chart-title {
  font-family: var(--font-display);
  margin: 0 0 0.8rem;
  font-size: 1.05rem;
}

/* ---------- Fields / settings ---------- */
.settings-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.3rem;
  margin-bottom: 1.2rem;
}
.settings-block h2 {
  font-family: var(--font-display);
  font-weight: 500;
  margin: 0 0 0.2rem;
}
.hint { color: var(--text-muted); font-size: 0.85rem; margin: 0 0 1rem; }

.fields-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.field-row-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-raised);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}
.field-row-item .name { font-weight: 500; }
.field-row-item .type-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
}
.field-row-item .remove {
  background: none;
  border: none;
  color: var(--text-muted);
}
.field-row-item .remove:hover { color: var(--danger); }

.inline-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.inline-form input, .inline-form select { width: auto; flex: 1 1 140px; }
.inline-form button {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-weight: 600;
}

.subjects-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.subject-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-raised);
  border-radius: 999px;
  padding: 0.35rem 0.7rem 0.35rem 0.5rem;
  font-size: 0.85rem;
}
.subject-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.subject-chip button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1;
}
.subject-chip button:hover { color: var(--danger); }

.color-picker { display: flex; gap: 0.35rem; }
.color-swatch {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}
.color-swatch.selected { border-color: var(--text); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 12, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 10;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 420px;
  max-width: 100%;
  max-height: 88vh;
  overflow-y: auto;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-day-label {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin: 0;
}
.status-toggle {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.9rem;
}
.status-btn {
  flex: 1;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.5rem;
  border-radius: 8px;
  font-weight: 500;
}
.status-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.custom-fields {
  margin-top: 0.3rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
}
.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.2rem;
}
.primary-btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.4rem;
  font-weight: 600;
}
.text-danger {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.85rem;
}
label:has(+ input[type="checkbox"]) { display: inline; margin-right: 0.5rem; }
input[type="checkbox"] { width: auto; }
