:root {
  color-scheme: light;
  --bg: #f7f7fb;
  --bg-elevated: #ffffff;
  --bg-muted: #eef0f6;
  --fg: #1f2937;
  --fg-muted: #4b5563;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.08);
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.12);
  --shadow: 0 20px 60px -30px rgba(71, 85, 105, 0.45);
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --bg-elevated: #111b2f;
  --bg-muted: #14203a;
  --fg: #f8fafc;
  --fg-muted: #cbd5f5;
  --accent: #818cf8;
  --accent-strong: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, 0.16);
  --border: rgba(148, 163, 184, 0.12);
  --border-strong: rgba(148, 163, 184, 0.2);
  --shadow: 0 30px 80px -40px rgba(15, 23, 42, 0.8);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  display: flex;
}

button,
input,
textarea,
select {
  font-family: inherit;
}

.app {
  display: flex;
  width: 100%;
}

.sidebar {
  width: 260px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 32px 20px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  gap: 16px;
  align-items: center;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--accent-strong);
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 1px;
}

.brand-copy h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
}

.brand-copy p {
  margin: 4px 0 0;
  color: var(--fg-muted);
  font-size: 0.85rem;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.nav-item {
  border: none;
  background: transparent;
  padding: 12px 14px;
  font-weight: 500;
  color: var(--fg-muted);
  border-radius: var(--radius-md);
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}

.nav-item:hover {
  background: var(--bg-muted);
  color: var(--fg);
  transform: translateX(4px);
}

.nav-item.active {
  background: var(--accent);
  color: #ffffff;
  transform: translateX(0);
}

.sidebar-footer {
  margin-top: auto;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  color: var(--fg-muted);
  font-size: 0.9rem;
}

.toggle input {
  display: none;
}

.toggle-track {
  width: 46px;
  height: 24px;
  border-radius: 999px;
  background: var(--bg-muted);
  position: relative;
  transition: background var(--transition);
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 4px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--accent);
  transition: transform var(--transition);
}

.toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(20px);
}

.toggle-label {
  user-select: none;
}

.main {
  flex: 1;
  padding: 36px 44px 56px;
  overflow-y: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}

.topbar h2 {
  margin: 0;
  font-size: 1.6rem;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--fg-muted);
}

.topbar-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: right;
  color: var(--fg-muted);
  font-size: 0.9rem;
}

.section {
  display: none;
}

.section.active {
  display: block;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 24px;
}

.grid.wide {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  margin-top: 32px;
}

.grid .card.half {
  min-height: 320px;
}

.card {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 24px 80px -40px rgba(15, 23, 42, 0.45);
}

.card.full {
  grid-column: 1 / -1;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

h3 {
  margin: 0;
}

.badge {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.badge-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-muted);
}

.metric {
  text-align: left;
}

.metric-value {
  font-size: 2.5rem;
  font-weight: 700;
  margin: 0;
}

.metric-hint {
  color: var(--fg-muted);
  margin: 6px 0 0;
}

.highlight {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.1), rgba(129, 140, 248, 0.18));
  border: 1px solid rgba(79, 70, 229, 0.18);
}

.actions,
.timer-controls,
.flashcard-controls {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.actions {
  justify-content: flex-end;
}

.timer-controls,
.flashcard-controls {
  justify-content: center;
}

button {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-muted);
  color: var(--fg);
  transition: background var(--transition), transform var(--transition), border var(--transition);
}

button:hover {
  transform: translateY(-1px);
}

.button-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: transparent;
}

.primary:hover {
  background: var(--accent-strong);
}

.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--fg);
}

.secondary:hover {
  border-color: var(--border-strong);
}

.danger {
  background: rgba(248, 113, 113, 0.16);
  color: #ef4444;
  border-color: rgba(248, 113, 113, 0.2);
}

.danger:hover {
  background: rgba(248, 113, 113, 0.24);
}

.full {
  width: 100%;
}

textarea,
input,
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: inherit;
  transition: border var(--transition), box-shadow var(--transition);
}

textarea:focus,
input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  resize: vertical;
}

.weekly-plan {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.weekly-plan li {
  padding: 12px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: rgba(15, 23, 42, 0.02);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.notes-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 24px;
}

.notes-sidebar {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(100vh - 140px);
}

.search input {
  border-radius: var(--radius-md);
}

.filters select {
  border-radius: var(--radius-md);
}

.notes-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.notes-list li {
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border var(--transition), transform var(--transition);
}

.notes-list li:hover {
  border-color: var(--border);
  transform: translateX(4px);
}

.notes-list li.active {
  background: var(--accent);
  color: #ffffff;
}

.notes-list .note-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: inherit;
  opacity: 0.8;
  margin-top: 8px;
}

.note-editor {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 24px;
  border: 1px solid var(--border);
  min-height: 600px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.note-empty {
  text-align: center;
  margin: auto;
  color: var(--fg-muted);
}

.hidden {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  font-weight: 500;
}

.note-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  gap: 12px;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.task-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.task-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  gap: 12px;
}

.task-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.task-actions {
  display: flex;
  gap: 8px;
}

.task-item.completed {
  opacity: 0.6;
  text-decoration: line-through;
}

.task-badge {
  font-size: 0.75rem;
  padding: 4px 8px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
}

.timer-display {
  font-size: 4rem;
  font-weight: 700;
  text-align: center;
  margin: 36px 0 16px;
}

.timer-modes {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
}

.mode-button {
  flex: 1;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--fg-muted);
}

.mode-button.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-style: solid;
}

.timer-history {
  list-style: none;
  padding: 0;
  margin: 24px 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--fg-muted);
  font-size: 0.9rem;
}

.stacked {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.flashcard {
  perspective: 1200px;
  height: 220px;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s ease;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 1.1rem;
}

.flashcard-face.back {
  transform: rotateY(180deg);
  background: var(--accent);
  color: #ffffff;
}

.flashcard-controls button {
  min-width: 120px;
}

#flashcardDrafts,
.flashcard-drafts {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.flashcard-drafts li {
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(15, 23, 42, 0.02);
}

.flashcard-drafts .draft-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--fg-muted);
}

.flashcard-drafts .draft-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#flashcardSetSelect {
  width: auto;
  min-width: 180px;
}

.shared-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 24px;
}

.shared-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.shared-panel textarea {
  height: 260px;
}

.shared-status {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.04);
  color: var(--fg-muted);
}

.activity-feed {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  max-height: 260px;
}

.activity-feed li {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.03);
  font-size: 0.9rem;
}

.hint {
  margin-top: 20px;
  color: var(--fg-muted);
  font-size: 0.85rem;
}

textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.datetime {
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1100px) {
  .sidebar {
    display: none;
  }

  .main {
    padding: 28px 24px 48px;
  }

  .topbar {
    flex-direction: column;
    gap: 16px;
    text-align: center;
  }

  .notes-layout {
    grid-template-columns: 1fr;
  }

  .notes-sidebar {
    max-height: unset;
  }
}

@media (max-width: 768px) {
  body {
    background: var(--bg);
  }

  .main {
    padding: 24px 16px 40px;
  }

  .grid,
  .grid.wide {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 20px;
  }

  .timer-display {
    font-size: 3.2rem;
  }

  .timer-modes {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
