:root,
html[data-theme="dark"] {
  --bg: #0e0e0e;
  --bg-deep: #080808;
  --bg-glow-1: #1a1a1a;
  --bg-glow-2: #141414;
  --ink: #ececec;
  --ink-soft: #bdbdbd;
  --muted: #8a8a8a;
  --heading: #f5f5f5;
  --panel: rgba(22, 22, 22, 0.92);
  --panel-solid: #161616;
  --line: rgba(255, 255, 255, 0.1);
  --grid-line: rgba(255, 255, 255, 0.035);
  --accent: #f2f2f2;
  --accent-2: #cfcfcf;
  --accent-soft: #242424;
  --danger: #d6d6d6;
  --ok: #f0f0f0;
  --warn: #c8c8c8;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --font: "Manrope", sans-serif;
  --display: "Fraunces", Georgia, serif;
  --theme-icon: #cfcfcf;
}

html[data-theme="light"] {
  --bg: #f3f1ee;
  --bg-deep: #e8e4de;
  --bg-glow-1: #ffffff;
  --bg-glow-2: #efeae3;
  --ink: #1c1c1c;
  --ink-soft: #3a3a3a;
  --muted: #6b6b6b;
  --heading: #141414;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --line: rgba(0, 0, 0, 0.1);
  --grid-line: rgba(0, 0, 0, 0.045);
  --accent: #1a1a1a;
  --accent-2: #333333;
  --accent-soft: #eceae6;
  --danger: #3a3a3a;
  --ok: #1a1a1a;
  --warn: #555555;
  --shadow: 0 18px 50px rgba(40, 30, 20, 0.1);
  --theme-icon: #3a3a3a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, var(--bg-glow-1) 0%, transparent 34%),
    radial-gradient(circle at 90% 0%, var(--bg-glow-2) 0%, transparent 30%),
    linear-gradient(160deg, var(--bg), var(--bg-deep));
}

body {
  position: relative;
  min-height: 100vh;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 85%);
  z-index: 0;
}

.topbar, .layout, .site-footer, .modal { position: relative; z-index: 1; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem 0.75rem;
  max-width: 1440px;
  margin: 0 auto;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: block;
  object-fit: cover;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  user-select: none;
}

.brand-name {
  margin: 0;
  font-family: var(--display);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--heading);
}

.brand-tag {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.sync-status {
  margin: 0.35rem 0 0;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: default;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.sync-status::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: #777;
}

.sync-status[data-status="ok"] {
  color: #d9f5d9;
  border-color: rgba(120, 200, 120, 0.35);
}

.sync-status[data-status="ok"]::before { background: #6dcf6d; }

.sync-status[data-status="syncing"] {
  color: #e8e8e8;
}

.sync-status[data-status="syncing"]::before {
  background: #cfcfcf;
  box-shadow: 0 0 0 0 rgba(207, 207, 207, 0.6);
  animation: sync-pulse 1.2s ease infinite;
}

.sync-status[data-status="offline"],
.sync-status[data-status="error"] {
  color: #f0d0d0;
  border-color: rgba(220, 120, 120, 0.35);
}

.sync-status[data-status="offline"]::before,
.sync-status[data-status="error"]::before { background: #d88; }

@keyframes sync-pulse {
  50% { box-shadow: 0 0 0 6px rgba(207, 207, 207, 0); }
}

.layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 280px;
  gap: 1rem;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem 2rem;
}

.sidebar, .panel, .agenda {
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}

.sidebar {
  padding: 1.1rem;
  min-height: 520px;
}

.sidebar-title {
  margin: 0 0 0.85rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.subject-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.subject-list button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 12px;
  padding: 0.75rem 0.8rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.subject-list button:hover {
  background: rgba(255, 255, 255, 0.04);
  transform: translateX(2px);
}

.subject-list button.active {
  background: #242424;
  border-color: rgba(255, 255, 255, 0.12);
}

.subject-list .item-name {
  display: block;
  font-weight: 600;
  margin-bottom: 0.15rem;
  color: #f0f0f0;
}

.subject-list .item-sub {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
}

.sidebar-hint {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.agenda {
  padding: 1.1rem;
  min-height: 520px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.agenda-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.agenda-header .sidebar-title {
  margin: 0;
}

.btn-compact {
  padding: 0.45rem 0.7rem;
  font-size: 0.82rem;
}

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
}

.calendar-month {
  margin: 0;
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 700;
  color: #f0f0f0;
  letter-spacing: -0.02em;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.15rem;
  margin-bottom: 0.25rem;
  text-align: center;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.2rem;
}

.cal-day {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.cal-day.empty {
  cursor: default;
  pointer-events: none;
}

.cal-day:not(.empty):hover {
  background: rgba(255, 255, 255, 0.05);
}

.cal-day.academic-classes {
  background: rgba(110, 145, 138, 0.22);
  color: #e8efed;
}

.cal-day.academic-classes:hover {
  background: rgba(110, 145, 138, 0.32);
}

.cal-day.academic-exams {
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(190, 165, 110, 0.28),
      rgba(190, 165, 110, 0.28) 3px,
      rgba(190, 165, 110, 0.12) 3px,
      rgba(190, 165, 110, 0.12) 6px
    );
  color: #f3efe6;
  border-color: rgba(210, 185, 130, 0.28);
}

.cal-day.academic-exams:hover {
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(190, 165, 110, 0.38),
      rgba(190, 165, 110, 0.38) 3px,
      rgba(190, 165, 110, 0.18) 3px,
      rgba(190, 165, 110, 0.18) 6px
    );
}

.cal-day.today {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.cal-day.selected {
  background: #efefef;
  color: #111;
  border-color: #efefef;
  box-shadow: none;
}

.cal-day.selected.academic-classes,
.cal-day.selected.academic-exams {
  background: #efefef;
  color: #111;
}

.cal-num {
  display: grid;
  place-items: center;
  height: 100%;
}

.cal-marks {
  position: absolute;
  left: 50%;
  bottom: 3px;
  display: flex;
  align-items: center;
  gap: 3px;
  transform: translateX(-50%);
  height: 5px;
}

.cal-dot,
.cal-activity {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: transparent;
}

.cal-day.has-event .cal-dot {
  background: #d8d8d8;
}

.cal-day.academic-exams .cal-activity {
  width: 7px;
  height: 3px;
  border-radius: 2px;
  background: rgba(230, 205, 145, 0.95);
}

.cal-day.selected .cal-dot {
  background: #111;
}

.cal-day.selected.academic-exams .cal-activity {
  background: #111;
}

.cal-day.selected.has-event .cal-dot {
  background: #111;
}

.cal-legend {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.cal-legend li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.legend-swatch.classes {
  background: rgba(110, 145, 138, 0.45);
}

.legend-swatch.exams {
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(190, 165, 110, 0.7),
      rgba(190, 165, 110, 0.7) 2px,
      rgba(190, 165, 110, 0.25) 2px,
      rgba(190, 165, 110, 0.25) 4px
    );
}

.legend-swatch.event {
  background: #2a2a2a;
  position: relative;
}

.legend-swatch.event::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #d8d8d8;
  transform: translate(-50%, -50%);
}

.academic-chip {
  margin: 0 0 0.65rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  font-size: 0.8rem;
  line-height: 1.35;
  color: #e8eeec;
  border: 1px solid transparent;
}

.academic-chip.classes {
  background: rgba(110, 145, 138, 0.18);
  border-color: rgba(110, 145, 138, 0.35);
}

.academic-chip.exams {
  background: rgba(190, 165, 110, 0.16);
  border-color: rgba(190, 165, 110, 0.35);
  color: #f3efe6;
}

.agenda-day-label {
  margin: 0 0 0.55rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.event-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.event-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
  align-items: start;
}

.event-main {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #121212;
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.event-main:hover {
  background: #181818;
  border-color: rgba(255, 255, 255, 0.18);
}

.event-title {
  display: block;
  font-weight: 600;
  color: #f0f0f0;
}

.event-sub {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.upcoming-block {
  margin-top: 0.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.upcoming-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.upcoming-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 12px;
  padding: 0.7rem 0.75rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.upcoming-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
}

.upcoming-when {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.upcoming-item.today .upcoming-when,
.upcoming-item.overdue .upcoming-when {
  color: #f0f0f0;
}

.upcoming-item.soon .upcoming-when {
  color: #d6d6d6;
}

.upcoming-title {
  display: block;
  font-weight: 600;
  color: #f0f0f0;
}

.upcoming-sub {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.upcoming-item.overdue {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.03);
}

.panel {
  padding: 1.35rem 1.4rem 1.5rem;
  min-height: 520px;
}

.empty-state {
  display: grid;
  place-content: center;
  text-align: center;
  min-height: 420px;
  gap: 0.75rem;
  animation: rise 0.45s ease both;
}

.empty-state h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  letter-spacing: -0.03em;
  max-width: 14ch;
  justify-self: center;
  color: #f5f5f5;
}

.empty-state p {
  margin: 0 auto 0.5rem;
  max-width: 42ch;
  color: var(--ink-soft);
  line-height: 1.55;
}

.hidden { display: none !important; }

.subject-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.1rem;
}

.subject-header-side {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  flex-shrink: 0;
}

.target-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.target-field input {
  width: 4.5rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: #f5f5f5;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.45rem 0.55rem;
  outline: none;
}

.target-field input:focus {
  border-color: rgba(255, 255, 255, 0.28);
}

.subject-name-input {
  width: min(100%, 420px);
  border: none;
  background: transparent;
  font-family: var(--display);
  font-size: clamp(1.5rem, 2.5vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #f5f5f5;
  padding: 0;
  outline: none;
  border-bottom: 2px solid transparent;
  transition: border-color 0.2s ease;
}

.subject-name-input:focus {
  border-bottom-color: #cfcfcf;
}

.subject-meta {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
  margin-bottom: 1.35rem;
}

.stat {
  background: #121212;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 1.05rem;
  animation: rise 0.5s ease both;
}

.stat:nth-child(2) { animation-delay: 0.05s; }
.stat:nth-child(3) { animation-delay: 0.1s; }

.stat.highlight {
  background: linear-gradient(160deg, #2a2a2a, #141414);
  color: #f2f2f2;
  border-color: rgba(255, 255, 255, 0.12);
}

.stat.highlight .stat-label,
.stat.highlight .stat-sub { color: rgba(230, 230, 230, 0.65); }

.stat-label {
  margin: 0;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat-value {
  margin: 0.45rem 0 0.2rem;
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  color: #f3f3f3;
}

.stat-sub {
  margin: 0;
  font-size: 0.84rem;
  color: var(--ink-soft);
  line-height: 1.35;
}

.progress {
  margin-top: 0.7rem;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f0f0f0, #777777);
  transition: width 0.35s ease;
}

.grades-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.grades-header h2 {
  margin: 0;
  font-size: 1.05rem;
  color: #f0f0f0;
}

.grades-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #121212;
}

.grades-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.grades-table th,
.grades-table td {
  padding: 0.85rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  color: var(--ink-soft);
}

.grades-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}

.grades-table tr:last-child td { border-bottom: none; }

.grades-table tbody tr {
  transition: background 0.2s ease;
}

.grades-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.type-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #242424;
  color: #eaeaea;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.date-cell {
  display: inline-block;
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.35;
}

.score-cell {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
  color: #f2f2f2;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.done {
  background: #2a2a2a;
  color: #e8e8e8;
}

.badge.pending {
  background: #efefef;
  color: #111;
}

.row-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
}

.icon-btn {
  border: 1px solid var(--line);
  background: #1a1a1a;
  border-radius: 10px;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  color: var(--ink-soft);
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.icon-btn:hover {
  background: #efefef;
  color: #111;
  border-color: #efefef;
}

.icon-btn.delete:hover {
  background: #cfcfcf;
  color: #111;
  border-color: #cfcfcf;
}

.table-empty {
  margin: 0;
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 0.7rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(145deg, #efefef, #d4d4d4);
  color: #111;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
}

.btn-secondary {
  background: #1a1a1a;
  color: #ececec;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
}

.btn-ghost.danger {
  color: #cfcfcf;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.modal {
  border: none;
  border-radius: 20px;
  padding: 0;
  background: transparent;
  max-width: 460px;
  width: calc(100% - 2rem);
  color: var(--ink);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(3px);
}

.modal-card {
  background: #151515;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1.25rem 1.3rem 1.2rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.85rem;
}

.modal-card h3 {
  margin: 0 0 0.2rem;
  font-family: var(--display);
  font-size: 1.35rem;
  color: #f3f3f3;
}

.modal-card label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.modal-card input,
.modal-card select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  font: inherit;
  color: #f0f0f0;
  background: #101010;
  outline: none;
}

.modal-card input::placeholder {
  color: #777;
}

.modal-card input:focus,
.modal-card select:focus {
  border-color: rgba(255, 255, 255, 0.28);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
}

.modal-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.modal-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
  font-weight: 400;
}

.modal-error {
  margin: 0;
  color: #ececec;
  font-size: 0.85rem;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.tone-ok { color: #ffffff !important; }
.tone-warn { color: #cfcfcf !important; }
.tone-bad { color: #9a9a9a !important; }

/* Theme toggle — icon only */
.theme-toggle {
  width: 2.15rem;
  height: 2.15rem;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--theme-icon);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.72;
  transition: opacity 0.2s ease, background 0.2s ease, color 0.2s ease;
  flex: 0 0 auto;
}

.theme-toggle:hover {
  opacity: 1;
  background: rgba(127, 127, 127, 0.12);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--line);
  outline-offset: 2px;
}

.theme-toggle svg {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
}

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }

html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

html[data-theme="light"] .theme-toggle .icon-sun { display: none; }
html[data-theme="light"] .theme-toggle .icon-moon { display: block; }

/* Light theme overrides for hardcoded dark surfaces */
html[data-theme="light"] .empty-state h1,
html[data-theme="light"] .subject-name-input,
html[data-theme="light"] .stat-value,
html[data-theme="light"] .panel h1,
html[data-theme="light"] .agenda-day-label,
html[data-theme="light"] .cal-month,
html[data-theme="light"] .modal-card h3,
html[data-theme="light"] .subject-list .name,
html[data-theme="light"] .event-item-title {
  color: var(--heading);
}

html[data-theme="light"] .subject-list button {
  background: transparent;
  color: var(--ink);
}

html[data-theme="light"] .subject-list button:hover {
  background: rgba(0, 0, 0, 0.04);
}

html[data-theme="light"] .subject-list button.active {
  background: var(--accent-soft);
  border-color: rgba(0, 0, 0, 0.1);
}

html[data-theme="light"] .btn-ghost {
  color: var(--ink-soft);
}

html[data-theme="light"] .btn-ghost:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--ink);
}

html[data-theme="light"] .btn-primary {
  background: #1a1a1a;
  color: #f5f5f5;
  border-color: #1a1a1a;
}

html[data-theme="light"] .btn-primary:hover {
  background: #000;
  color: #fff;
}

html[data-theme="light"] .btn-secondary {
  background: rgba(0, 0, 0, 0.05);
  color: var(--ink);
  border-color: rgba(0, 0, 0, 0.1);
}

html[data-theme="light"] .modal-card {
  background: var(--panel-solid);
  color: var(--ink);
}

html[data-theme="light"] .modal::backdrop {
  background: rgba(30, 28, 24, 0.45);
}

html[data-theme="light"] .modal-card input,
html[data-theme="light"] .modal-card select,
html[data-theme="light"] .subject-name-input,
html[data-theme="light"] .subject-target-input,
html[data-theme="light"] input[type="number"],
html[data-theme="light"] input[type="text"],
html[data-theme="light"] input[type="date"],
html[data-theme="light"] select {
  background: #faf9f7;
  color: var(--ink);
  border-color: rgba(0, 0, 0, 0.12);
}

html[data-theme="light"] .modal-card input:focus,
html[data-theme="light"] .modal-card select:focus {
  border-color: rgba(0, 0, 0, 0.28);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}

html[data-theme="light"] .grades-table th,
html[data-theme="light"] .grades-table td {
  border-color: rgba(0, 0, 0, 0.08);
  color: var(--ink);
}

html[data-theme="light"] .stat-card,
html[data-theme="light"] .cal-day,
html[data-theme="light"] .event-item {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.08);
}

html[data-theme="light"] .tone-ok { color: #1a1a1a !important; }
html[data-theme="light"] .tone-warn { color: #5a5a5a !important; }
html[data-theme="light"] .tone-bad { color: #8a8a8a !important; }

html[data-theme="light"] .sync-status {
  background: rgba(0, 0, 0, 0.04);
}

html[data-theme="light"] .weight-bar {
  background: rgba(0, 0, 0, 0.08);
}

html[data-theme="light"] .weight-bar > span {
  background: linear-gradient(90deg, #2a2a2a, #8a8a8a);
}

.site-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.75rem 1.5rem 2.25rem;
  max-width: 1440px;
  margin: 0 auto;
}

.social-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  text-decoration: none;
  color: var(--muted);
  opacity: 0.78;
  transition: opacity 0.2s ease, color 0.2s ease;
}

.social-link:hover {
  opacity: 1;
  color: var(--ink-soft);
}

.social-icon {
  width: 0.95rem;
  height: 0.95rem;
  flex-shrink: 0;
}

.social-handle {
  font-family: Papyrus, "Segoe Print", "Bradley Hand", fantasy, cursive;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  line-height: 1;
  font-weight: 400;
}

html[data-theme="dark"] .social-link {
  color: #9a9a9a;
}

html[data-theme="dark"] .social-link:hover {
  color: #d4d4d4;
}

html[data-theme="light"] .social-link {
  color: #6a6a6a;
}

html[data-theme="light"] .social-link:hover {
  color: #2a2a2a;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.btn .label-short { display: none; }

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 0.75rem 1rem 1.5rem;
  }

  .layout > * {
    min-width: 0;
    max-width: 100%;
  }

  .sidebar,
  .agenda { min-height: auto; }

  .stats { grid-template-columns: 1fr; }

  .topbar { padding: 1rem 1rem 0.5rem; }
}

@media (max-width: 700px) {
  .hide-on-mobile { display: none !important; }

  .btn .label-full { display: none; }
  .btn .label-short { display: inline; }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    gap: 0.45rem;
  }

  .topbar-actions .btn {
    flex: 1 1 auto;
  }

  .topbar-actions .theme-toggle {
    flex: 0 0 auto;
  }

  .topbar-actions #btn-session {
    flex: 0 0 auto;
  }

  .topbar-actions #btn-new-subject {
    flex: 1 1 auto;
  }

  .panel {
    padding: 1.1rem 1rem 1.25rem;
    overflow: hidden;
  }

  .grades-table-wrap {
    overflow: visible;
    border: none;
    background: transparent;
    max-width: 100%;
  }

  .grades-table {
    min-width: 0;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
  }

  .grades-table thead {
    display: none;
  }

  .grades-table,
  .grades-table tbody {
    display: block;
    width: 100%;
  }

  .grades-table tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem 0.75rem;
    padding: 0.9rem;
    margin-bottom: 0.65rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #121212;
  }

  .grades-table tbody tr:hover {
    background: #121212;
  }

  .grades-table td {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    padding: 0;
    border: none;
    min-width: 0;
  }

  .grades-table td::before {
    content: attr(data-label);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
  }

  .grades-table td:first-child,
  .grades-table td:last-child {
    grid-column: 1 / -1;
  }

  .grades-table td:last-child::before {
    display: none;
  }

  .grades-table .row-actions {
    display: flex;
    gap: 0.45rem;
    width: 100%;
  }

  .grades-table .row-actions .icon-btn {
    flex: 1;
    min-height: 2.4rem;
  }

  .calendar-grid,
  .calendar-weekdays {
    width: 100%;
  }

  .cal-day {
    min-width: 0;
    font-size: 0.75rem;
    border-radius: 8px;
  }

  .modal-card {
    width: min(100vw - 1.25rem, 440px);
    max-height: min(90vh, 720px);
    overflow-y: auto;
  }

  .modal-card input,
  .modal-card select,
  .target-field input,
  .subject-name-input {
    font-size: 16px;
  }

  html[data-theme="light"] .grades-table tbody tr {
    background: #fff;
  }

  html[data-theme="light"] .grades-table tbody tr:hover {
    background: #fff;
  }
}

@media (max-width: 600px) {
  .subject-header { flex-direction: column; }
  .subject-header-side { width: 100%; justify-content: space-between; }
  .modal-row { grid-template-columns: 1fr; }
  .grades-header { flex-wrap: wrap; }
}
