:root {
  --ink: #08236f;
  --muted: #58677f;
  --line: #dfe7f2;
  --blue: #0879e8;
  --blue-dark: #0561ba;
  --orange: #ff9c16;
  --cyan: #08b8d8;
  --coral: #ec1350;
  --surface: #ffffff;
  --background: #f5f8fc;
  --shadow: 0 20px 60px rgba(8, 35, 111, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  min-height: 100%;
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--background);
}
button, input, textarea, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  color: white;
  background: var(--ink);
  border-radius: 8px;
  transform: translateY(-150%);
}
.skip-link:focus { transform: none; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.app-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 8px clamp(16px, 3vw, 40px);
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand img { width: 48px; height: 48px; border-radius: 12px; object-fit: cover; }
.brand span { display: grid; line-height: 1.1; }
.brand b { font-size: 1.15rem; }
.brand small { margin-top: 5px; color: var(--muted); }
.header-meta { display: flex; align-items: center; gap: 14px; }

.auth-layout {
  width: min(1100px, calc(100% - 32px));
  min-height: calc(100vh - 73px);
  margin: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 460px);
  align-items: center;
  gap: clamp(40px, 8vw, 100px);
  padding: 48px 0;
}
.auth-copy h1, .dashboard h1 { margin: 12px 0 18px; font-size: clamp(2.4rem, 5vw, 4.6rem); line-height: 0.98; letter-spacing: -0.055em; }
.auth-copy > p { max-width: 620px; color: var(--muted); font-size: 1.17rem; line-height: 1.7; }
.eyebrow, .step-label { color: var(--blue); font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.78rem; }
.trust-list { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.trust-list li { display: grid; grid-template-columns: 24px minmax(0, 1fr); align-items: start; gap: 10px; line-height: 1.45; }
.trust-list li::before { content: "✓"; display: inline-grid; place-items: center; width: 24px; height: 24px; color: white; background: var(--cyan); border-radius: 50%; font-weight: 900; }
.auth-card { padding: clamp(24px, 4vw, 42px); background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.auth-card h2 { margin: 9px 0 8px; font-size: 1.75rem; letter-spacing: -0.03em; }
.help, .privacy-note { color: var(--muted); line-height: 1.55; }
.privacy-note { margin: 18px 0 0; font-size: 0.78rem; }
label { display: grid; gap: 7px; margin: 22px 0 10px; font-weight: 700; }
input, textarea, select {
  width: 100%;
  color: var(--ink);
  background: white;
  border: 1px solid #c7d4e6;
  border-radius: 11px;
  padding: 12px 14px;
  outline: 0;
}
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(8, 121, 232, 0.16); }
.button, .icon-button, .tool, .small-action, .tab, .panel-tab, .page-chip, .page-add, .back-button, .link-button {
  border: 0;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease;
}
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid rgba(8, 184, 216, 0.5);
  outline-offset: 2px;
}
button:disabled { cursor: not-allowed; opacity: 0.55; }
.button { min-height: 44px; padding: 10px 18px; border-radius: 11px; font-weight: 800; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.primary { color: white; background: var(--blue); }
.primary:hover:not(:disabled) { background: var(--blue-dark); }
.secondary { color: var(--blue); background: #edf6ff; border: 1px solid #b8dcff; }
.ghost { background: transparent; border: 1px solid var(--line); }
.danger { color: white; background: var(--coral); }
.wide { width: 100%; margin-top: 12px; }
.compact { min-height: 38px; padding: 7px 13px; }
.back-button, .link-button { padding: 0; color: var(--blue); background: transparent; font-weight: 700; }
.otp { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 24px 0 12px; }
.otp input { padding: 10px 2px; text-align: center; font-size: 1.65rem; font-weight: 800; }
.code-actions { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.9rem; }
.form-status { min-height: 24px; margin: 14px 0 0; color: var(--coral); font-weight: 700; }
.form-status.success { color: #087b4d; }

.dashboard { width: min(1100px, calc(100% - 32px)); margin: auto; padding: clamp(32px, 6vw, 72px) 0; }
.dashboard-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; }
.dashboard h1 { margin-bottom: 10px; }
.dashboard-heading p { margin: 0; color: var(--muted); }
.lesson-tabs { display: flex; gap: 8px; margin: 34px 0 20px; border-bottom: 1px solid var(--line); }
.tab { padding: 12px 16px; background: transparent; border-bottom: 3px solid transparent; font-weight: 800; }
.tab.active { color: var(--blue); border-color: var(--blue); }
.lesson-list { display: grid; gap: 12px; }
.lesson-card { display: grid; grid-template-columns: 84px minmax(0, 1fr) auto; align-items: center; gap: 18px; padding: 18px; background: white; border: 1px solid var(--line); border-radius: 16px; }
.lesson-date { display: grid; place-items: center; min-height: 66px; background: #edf6ff; border-radius: 12px; font-size: 1.25rem; font-weight: 900; text-align: center; }
.lesson-date small { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; }
.lesson-card h2 { margin: 0 0 5px; font-size: 1.15rem; }
.lesson-card p { margin: 0; color: var(--muted); }
.empty-state { padding: 60px 20px; text-align: center; color: var(--muted); background: white; border: 1px dashed #b9c9df; border-radius: 18px; }

.classroom { height: calc(100vh - 73px); min-height: 620px; background: #eaf0f8; overflow: hidden; }
.classroom-topbar { height: 66px; display: flex; align-items: center; gap: 12px; padding: 9px 14px; background: white; border-bottom: 1px solid var(--line); }
.lesson-identity { min-width: 0; margin-right: auto; }
.lesson-identity h1 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.05rem; }
.lesson-identity span { color: var(--muted); font-size: 0.78rem; }
.room-status { padding: 6px 10px; color: #76500b; background: #fff3d6; border-radius: 999px; font-size: 0.78rem; font-weight: 800; white-space: nowrap; }
.room-status.active { color: #087b4d; background: #e1f8ed; }
.media-actions { display: flex; align-items: center; gap: 7px; }
.icon-button { min-width: 40px; height: 40px; display: inline-grid; place-items: center; background: #f1f5fa; border-radius: 10px; font-weight: 700; }
.icon-button.labeled { display: inline-flex; gap: 7px; padding: 0 11px; }
.icon-button[aria-pressed="true"] { color: white; background: var(--blue); }
.classroom-grid { height: calc(100% - 66px); display: grid; grid-template-columns: 96px minmax(0, 1fr) 320px; }
.tool-rail { display: flex; flex-direction: column; align-items: stretch; gap: 5px; padding: 10px 7px; overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; background: white; border-right: 1px solid var(--line); }
.tool-rail::-webkit-scrollbar { width: 6px; }
.tool { width: 100%; min-width: 0; min-height: 54px; padding: 4px 2px; display: grid; place-items: center; align-content: center; gap: 2px; background: transparent; border-radius: 9px; font-size: 1.25rem; line-height: 1; text-align: center; }
.tool span { width: 100%; font-size: 0.62rem; font-weight: 700; line-height: 1.12; white-space: nowrap; }
.tool:hover, .tool.active { color: var(--blue); background: #eaf4ff; }
.board-shell { min-width: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; padding: 10px; gap: 8px; }
.board-toolbar, .page-strip { display: flex; align-items: center; gap: 10px; padding: 7px 10px; background: white; border: 1px solid var(--line); border-radius: 11px; }
.board-toolbar label { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 0.75rem; }
.board-toolbar input[type="color"] { width: 32px; height: 28px; padding: 2px; border-radius: 7px; }
.board-toolbar input[type="range"] { width: 90px; padding: 0; }
.small-action { min-height: 30px; padding: 5px 9px; background: #f1f5fa; border-radius: 7px; font-weight: 700; }
.small-action[aria-pressed="true"] { color: white; background: var(--blue); }
.material-upload { position: relative; display: inline-flex; align-items: center; overflow: hidden; cursor: pointer; }
.material-upload:hover { background: #e2ebf7; }
.material-upload:focus-within { outline: 3px solid rgba(8, 121, 232, 0.28); outline-offset: 2px; }
.material-upload:has(input:disabled) { cursor: wait; opacity: 0.68; }
.material-upload input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; opacity: 0; cursor: pointer; }
.material-upload input[type="file"]:disabled { cursor: wait; }
.sync-state { margin-left: auto; color: var(--muted); font-size: 0.74rem; }
.sync-state.online { color: #087b4d; }
.canvas-stage { position: relative; min-height: 0; overflow: hidden; background: white; border: 1px solid #cbd8e9; border-radius: 12px; box-shadow: 0 8px 30px rgba(8, 35, 111, 0.08); touch-action: none; }
.canvas-stage.grid { background-image: linear-gradient(#d9e4f2 1px, transparent 1px), linear-gradient(90deg, #d9e4f2 1px, transparent 1px); background-size: 24px 24px; }
.canvas-stage.image-drop-target::after { content: "Отпустите изображение, чтобы вставить его на доску"; position: absolute; z-index: 5; inset: 18px; display: grid; place-items: center; padding: 24px; color: var(--blue); background: rgba(237, 246, 255, 0.92); border: 3px dashed var(--blue); border-radius: 12px; font-weight: 800; text-align: center; pointer-events: none; }
#backgroundCanvas, #boardCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#backgroundCanvas { z-index: 0; background: transparent; }
#boardCanvas { z-index: 1; cursor: crosshair; }
.danger-text { color: #b42318; }
.board-lock { position: absolute; z-index: 3; left: 50%; bottom: 14px; transform: translateX(-50%); max-width: calc(100% - 28px); padding: 8px 12px; color: #5f4a11; background: rgba(255, 242, 203, 0.95); border-radius: 9px; font-size: 0.75rem; font-weight: 700; text-align: center; pointer-events: none; }
.remote-cursor { position: absolute; z-index: 2; pointer-events: none; font-size: 0.7rem; font-weight: 700; color: var(--blue); transform: translate(7px, 7px); }
.page-strip { justify-content: center; }
.page-chip, .page-add { width: 32px; height: 30px; border-radius: 7px; background: #f1f5fa; font-weight: 800; }
.page-chip.active { color: white; background: var(--blue); }
.side-panel { min-width: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); background: white; border-left: 1px solid var(--line); }
.panel-tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
.panel-tab { padding: 14px 5px 11px; background: transparent; border-bottom: 3px solid transparent; font-size: 0.76rem; font-weight: 800; }
.panel-tab.active { color: var(--blue); border-color: var(--blue); }
.panel-content { min-height: 0; overflow: auto; padding: 14px; }
.panel-heading { display: flex; justify-content: space-between; margin-bottom: 10px; }
.panel-heading span { min-width: 26px; padding: 3px 7px; text-align: center; background: #edf3fa; border-radius: 999px; font-size: 0.75rem; }
.participant-list, .task-list { display: grid; gap: 8px; margin-top: 12px; }
.panel-content > label { display: grid; gap: 6px; margin-bottom: 12px; color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.panel-content > label select { padding: 8px 10px; background: white; }
.material-list { display: grid; gap: 7px; margin: 12px 0; }
.material-link { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; color: var(--blue); background: #eef6ff; border-radius: 8px; font-size: 0.82rem; font-weight: 700; overflow-wrap: anywhere; }
.participant { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 9px; border: 1px solid var(--line); border-radius: 10px; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; color: white; background: var(--blue); border-radius: 50%; font-size: 0.75rem; font-weight: 900; }
.participant-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.82rem; font-weight: 750; }
.permission-button { padding: 5px 7px; color: var(--blue); background: #edf6ff; border: 0; border-radius: 6px; cursor: pointer; font-size: 0.69rem; font-weight: 800; }
.message-list { height: calc(100% - 104px); min-height: 180px; overflow-y: auto; display: grid; align-content: start; gap: 9px; }
.message { padding: 9px 10px; background: #f1f5fa; border-radius: 10px; }
.message b { display: block; margin-bottom: 3px; font-size: 0.75rem; }
.message p { margin: 0; color: #213457; font-size: 0.82rem; line-height: 1.45; }
.chat-form { display: grid; gap: 7px; padding-top: 10px; border-top: 1px solid var(--line); }
.chat-form textarea { margin: 0; resize: none; }
.task-card { padding: 11px; border: 1px solid var(--line); border-radius: 10px; }
.task-card b { display: block; margin-bottom: 4px; }
.task-card p { margin: 0; color: var(--muted); font-size: 0.8rem; }
.task-answer, .task-grade { width: 100%; margin-top: 9px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.task-answer { min-height: 68px; resize: vertical; }
.task-status { display: block; margin-top: 7px; color: var(--muted); }
.task-actions { display: flex; gap: 6px; margin-top: 8px; }
.task-actions .button { padding: 7px 10px; font-size: 0.76rem; }
.task-feedback { margin-top: 8px !important; color: var(--ink) !important; }
.submission-card { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.submission-card strong { display: block; font-size: 0.84rem; }

dialog { width: min(540px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 18px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(5, 19, 56, 0.52); backdrop-filter: blur(4px); }
.dialog-form { padding: 24px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
.dialog-heading h2 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }

@media (max-width: 980px) {
  .auth-layout { grid-template-columns: 1fr; max-width: 660px; }
  .auth-copy { text-align: center; }
  .trust-list { justify-content: center; text-align: left; }
  .classroom-grid { grid-template-columns: 96px minmax(0, 1fr); }
  .side-panel { position: fixed; z-index: 20; right: 0; bottom: 0; width: min(360px, 92vw); height: calc(100vh - 139px); box-shadow: -12px 0 36px rgba(8, 35, 111, 0.18); }
  .classroom.side-collapsed .side-panel { display: none; }
  .icon-button.labeled span { display: none; }
}

@media (max-width: 680px) {
  .app-header { min-height: 64px; }
  .brand img { width: 42px; height: 42px; }
  #currentUser { display: none; }
  .auth-layout { min-height: auto; padding: 30px 0; }
  .auth-copy h1 { font-size: 2.7rem; }
  .lesson-card { grid-template-columns: 68px minmax(0, 1fr); }
  .lesson-card .button { grid-column: 1 / -1; }
  .dashboard-heading { align-items: flex-start; }
  .dashboard-heading .button { padding-inline: 11px; }
  .classroom { height: calc(100vh - 64px); min-height: 540px; }
  .classroom-topbar { height: 58px; padding: 7px; }
  .classroom-grid { height: calc(100% - 58px); grid-template-columns: 52px minmax(0, 1fr); }
  .tool-rail { padding-inline: 4px; }
  .tool { min-height: 48px; }
  .tool span, .room-status, .board-toolbar label, #fullscreenButton { display: none; }
  .board-shell { padding: 5px; gap: 5px; }
  .board-toolbar { gap: 5px; padding: 5px; }
  .sync-state { max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .media-actions .button { font-size: 0; min-width: 40px; }
  .media-actions .button::first-letter { font-size: 1rem; }
  .side-panel { height: calc(100vh - 122px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
