/* Material Design 3 (https://m3.material.io/) + Telegram-style Dynamic Accent System */
:root {
  --md-sys-typescale-brand: 'Plus Jakarta Sans', 'Roboto', system-ui, -apple-system, sans-serif;
  --md-sys-typescale-plain: 'Roboto', system-ui, -apple-system, sans-serif;
  --md-sys-typescale-code: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --md-sys-shape-corner-small: 8px;
  --md-sys-shape-corner-medium: 12px;
  --md-sys-shape-corner-large: 16px;
  --md-sys-shape-corner-extra-large: 28px;
  --md-sys-shape-corner-full: 9999px;

  --md-sys-motion-easing: cubic-bezier(0.2, 0.0, 0.0, 1.0);
  --md-sys-elevation-1: 0 1px 3px rgba(0, 0, 0, 0.22);
  --md-sys-elevation-2: 0 4px 12px rgba(0, 0, 0, 0.28);
  --md-sys-elevation-3: 0 8px 24px rgba(0, 0, 0, 0.36);

  --tg-accent: #2AABEE;
  --md-sys-color-primary: #58C4FF;
  --md-sys-color-on-primary: #00344F;
  --md-sys-color-primary-container: #004C70;
  --md-sys-color-on-primary-container: #CBE6FF;
  --md-code-line-active: rgba(42, 171, 238, 0.20);
}

[data-theme="dark"] {
  --md-sys-color-background: #0F1117;
  --md-sys-color-on-background: #E4E2EA;
  --md-sys-color-surface: #0F1117;
  --md-sys-color-on-surface: #E4E2EA;
  --md-sys-color-on-surface-variant: #C4C6D0;

  --md-sys-color-surface-container-lowest: #0A0C10;
  --md-sys-color-surface-container-low: #161821;
  --md-sys-color-surface-container: #1C1F2A;
  --md-sys-color-surface-container-high: #252836;
  --md-sys-color-surface-container-highest: #303444;

  --md-sys-color-secondary-container: #2B3244;
  --md-sys-color-on-secondary-container: #DCE2F9;

  --md-sys-color-tertiary-container: #493954;
  --md-sys-color-on-tertiary-container: #F2DAFF;

  --md-sys-color-success: #4ADE80;
  --md-sys-color-success-container: #113822;
  --md-sys-color-on-success-container: #BBF7D0;

  --md-sys-color-error: #F87171;
  --md-sys-color-error-container: #451215;
  --md-sys-color-on-error-container: #FECACA;

  --md-sys-color-outline: #8E9099;
  --md-sys-color-outline-variant: #343846;

  --md-code-bg: #11131A;
  --md-code-line-hover: rgba(255, 255, 255, 0.05);
}

[data-theme="light"] {
  --md-sys-color-background: #F6F8FC;
  --md-sys-color-on-background: #181C22;
  --md-sys-color-surface: #F6F8FC;
  --md-sys-color-on-surface: #181C22;
  --md-sys-color-on-surface-variant: #434750;

  --md-sys-color-surface-container-lowest: #FFFFFF;
  --md-sys-color-surface-container-low: #EFF2F8;
  --md-sys-color-surface-container: #E8ECF4;
  --md-sys-color-surface-container-high: #E0E5EF;
  --md-sys-color-surface-container-highest: #D8DEE9;

  --md-sys-color-secondary-container: #DCE4F5;
  --md-sys-color-on-secondary-container: #131C2B;

  --md-sys-color-tertiary-container: #F3DAFF;
  --md-sys-color-on-tertiary-container: #271430;

  --md-sys-color-success: #15803D;
  --md-sys-color-success-container: #DCFCE7;
  --md-sys-color-on-success-container: #14532D;

  --md-sys-color-error: #B91C1C;
  --md-sys-color-error-container: #FEE2E2;
  --md-sys-color-on-error-container: #7F1D1D;

  --md-sys-color-outline: #737782;
  --md-sys-color-outline-variant: #C4C7D2;

  --md-code-bg: #F1F4FA;
  --md-code-line-hover: rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--md-sys-typescale-plain);
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-surface);
  min-height: 100vh;
  display: flex;
  transition: background-color 220ms var(--md-sys-motion-easing), color 220ms var(--md-sys-motion-easing);
}

.m3-rail {
  width: 88px;
  background-color: var(--md-sys-color-surface-container-low);
  border-right: 1px solid var(--md-sys-color-outline-variant);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 8px;
  gap: 10px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
  z-index: 25;
}

.m3-logo {
  width: 48px;
  height: 48px;
  border-radius: var(--md-sys-shape-corner-large);
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  display: grid;
  place-items: center;
  font-family: var(--md-sys-typescale-brand);
  font-weight: 800;
  font-size: 17px;
  margin-bottom: 10px;
  cursor: pointer;
}

.m3-rail-btn {
  width: 74px;
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 5px 0;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.m3-rail-pill {
  width: 56px;
  height: 32px;
  border-radius: var(--md-sys-shape-corner-full);
  display: grid;
  place-items: center;
  transition: background-color 160ms var(--md-sys-motion-easing);
}

.m3-rail-btn:hover .m3-rail-pill { background-color: var(--md-code-line-hover); }
.m3-rail-btn.active { color: var(--md-sys-color-on-surface); }
.m3-rail-btn.active .m3-rail-pill {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.m3-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.m3-topbar {
  min-height: 68px;
  padding: 10px 24px;
  background-color: var(--md-sys-color-surface);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}

.m3-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 14px;
}

.m3-crumb {
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--md-sys-shape-corner-full);
  transition: background-color 140ms;
}

.m3-crumb:hover { background-color: var(--md-code-line-hover); }
.m3-crumb.current {
  color: var(--md-sys-color-on-primary-container);
  background-color: var(--md-sys-color-primary-container);
}

.m3-topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.tg-palette-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--md-sys-shape-corner-full);
  background-color: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.tg-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease;
}

.tg-swatch:hover { transform: scale(1.15); }
.tg-swatch.active {
  border-color: var(--md-sys-color-on-surface);
  transform: scale(1.18);
}

.tg-color-picker-wrap {
  position: relative;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--md-sys-color-outline);
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 11px;
}

.tg-color-picker-wrap input[type="color"] {
  position: absolute;
  inset: -6px;
  width: 36px;
  height: 36px;
  opacity: 0;
  cursor: pointer;
}

.m3-seg {
  display: inline-flex;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-full);
  overflow: hidden;
  background-color: var(--md-sys-color-surface-container);
}

.m3-seg-btn {
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.m3-seg-btn.active {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.m3-btn {
  height: 38px;
  padding: 0 18px;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  transition: filter 150ms, transform 120ms;
}

.m3-btn:hover { filter: brightness(1.08); }
.m3-btn-filled { background-color: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.m3-btn-tonal { background-color: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
.m3-btn-outlined {
  background: transparent;
  border: 1px solid var(--md-sys-color-outline);
  color: var(--md-sys-color-primary);
}

.m3-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--md-sys-color-outline-variant);
  background-color: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.m3-container {
  padding: 24px 28px 96px;
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.m3-card {
  background-color: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-extra-large);
  padding: 22px;
  box-shadow: var(--md-sys-elevation-1);
}

.m3-hero {
  background: linear-gradient(135deg, var(--md-sys-color-primary-container) 0%, var(--md-sys-color-surface-container) 100%);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-extra-large);
  padding: 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.m3-h1 { font-family: var(--md-sys-typescale-brand); font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.m3-h2 { font-family: var(--md-sys-typescale-brand); font-size: 19px; font-weight: 700; }

.m3-grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 16px;
}

.m3-course-card {
  background-color: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
  transition: transform 160ms var(--md-sys-motion-easing), border-color 160ms;
}

.m3-course-card:hover {
  transform: translateY(-2px);
  border-color: var(--md-sys-color-primary);
}

.m3-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 12px;
  font-weight: 700;
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.m3-pill-success {
  background-color: var(--md-sys-color-success-container);
  color: var(--md-sys-color-on-success-container);
}

.m3-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.m3-chip {
  height: 36px;
  padding: 0 16px;
  border-radius: var(--md-sys-shape-corner-full);
  border: 1px solid var(--md-sys-color-outline-variant);
  background-color: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.m3-chip.selected {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-color: transparent;
}

.m3-split {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

@media (max-width: 1060px) { .m3-split { grid-template-columns: 1fr; } }

.m3-code-stage {
  background-color: var(--md-code-bg);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-large);
  overflow: hidden;
  font-family: var(--md-sys-typescale-code);
  font-size: 13.5px;
  line-height: 1.65;
}

.m3-code-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  padding: 4px 12px 4px 0;
  cursor: pointer;
  border-left: 3px solid transparent;
}

.m3-code-row:hover { background-color: var(--md-code-line-hover); }
.m3-code-row.active {
  background-color: var(--md-code-line-active);
  border-left-color: var(--md-sys-color-primary);
}

.m3-line-num {
  text-align: right;
  padding-right: 12px;
  color: var(--md-sys-color-outline);
  font-size: 12px;
  user-select: none;
}

.m3-code-row.active .m3-line-num { color: var(--md-sys-color-primary); font-weight: 700; }
.m3-line-text { white-space: pre-wrap; word-break: break-word; }

.m3-exp-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 68vh;
  overflow-y: auto;
  padding-right: 4px;
}

.m3-exp-card {
  background-color: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 14px 16px;
  cursor: pointer;
}

.m3-exp-card.active {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

.m3-editor {
  width: 100%;
  min-height: 260px;
  padding: 16px;
  border-radius: var(--md-sys-shape-corner-large);
  border: 1px solid var(--md-sys-color-outline);
  background-color: var(--md-code-bg);
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-sys-typescale-code);
  font-size: 13.5px;
  line-height: 1.6;
  resize: vertical;
}

.m3-console {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: var(--md-sys-shape-corner-large);
  background-color: var(--md-sys-color-surface-container-highest);
  font-family: var(--md-sys-typescale-code);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.m3-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: none;
  place-items: center;
  padding: 20px;
  z-index: 60;
}

.m3-backdrop.open { display: grid; }

.m3-dialog {
  width: 100%;
  max-width: 480px;
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-extra-large);
  padding: 24px;
  box-shadow: var(--md-sys-elevation-3);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.m3-input, .m3-select, .m3-textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--md-sys-shape-corner-medium);
  border: 1px solid var(--md-sys-color-outline);
  background-color: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  font-size: 14px;
}

.hidden { display: none !important; }
