:root {
  color-scheme: light;
  --font-main: 'Heebo', 'Rubik', 'Segoe UI', sans-serif;
  --font-accent: 'Rubik', 'Segoe UI', sans-serif;
  --bg-body: #f5f6fb;
  --bg-surface: #ffffff;
  --bg-surface-alt: rgba(255, 255, 255, 0.8);
  --border-soft: rgba(110, 123, 154, 0.18);
  --shadow-soft: 0 12px 30px rgba(31, 42, 68, 0.12);
  --text-primary: #1f2a44;
  --text-secondary: #52607a;
  --accent: #2f6fed;
  --accent-hover: #1f53c5;
  --accent-soft: rgba(47, 111, 237, 0.12);
  --table-header-bg: rgba(47, 111, 237, 0.08);
  --table-time-bg: rgba(47, 111, 237, 0.06);
  --edit-highlight: rgba(255, 215, 115, 0.5);
  --focus-ring: 0 0 0 3px rgba(47, 111, 237, 0.35);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg-body: #0f1322;
  --bg-surface: #161a2d;
  --bg-surface-alt: rgba(22, 26, 45, 0.86);
  --border-soft: rgba(119, 131, 189, 0.28);
  --shadow-soft: 0 12px 28px rgba(6, 9, 20, 0.55);
  --text-primary: #f1f3ff;
  --text-secondary: rgba(226, 230, 255, 0.75);
  --accent: #7c9dff;
  --accent-hover: #92affe;
  --accent-soft: rgba(124, 157, 255, 0.18);
  --table-header-bg: rgba(124, 157, 255, 0.2);
  --table-time-bg: rgba(124, 157, 255, 0.16);
  --edit-highlight: rgba(255, 207, 123, 0.26);
}

* {
  box-sizing: border-box;
}

::selection {
  background: var(--accent);
  color: #ffffff;
}

body {
  margin: 0;
  font-family: var(--font-main);
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 32px 16px 48px;
  transition: background 0.3s ease, color 0.3s ease;
}

.page {
  width: min(1040px, 100%);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
  background: var(--bg-surface-alt);
  border-radius: 20px;
  border: 1px solid var(--border-soft);
  padding: 16px 20px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
}

.controls-group {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.control-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-status {
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
}

.auth-status.authenticated {
  color: var(--accent);
  font-weight: 600;
  border-color: rgba(47, 111, 237, 0.4);
}

.controls-title {
  font-family: var(--font-accent);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text-primary);
}

.grade-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  border-radius: 999px;
  padding: 6px;
  border: 1px solid var(--border-soft);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

[data-theme="dark"] .grade-switch {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.grade-switch button {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 8px 20px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.grade-switch button.active {
  background: var(--accent);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(47, 111, 237, 0.22);
}

.action-button {
  border: 1px solid var(--border-soft);
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 9px 22px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.action-button--accent {
  background: var(--accent);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 10px 18px rgba(47, 111, 237, 0.22);
}

.action-button--accent:hover:not(:disabled) {
  background: var(--accent-hover);
  color: #ffffff;
}

.action-button--ghost {
  background: transparent;
  color: var(--text-secondary);
}

.action-button--ghost:hover:not(:disabled) {
  background: rgba(47, 111, 237, 0.08);
  color: var(--text-primary);
}

.action-button:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.action-button:disabled {
  opacity: 0.65;
  cursor: wait;
}

.action-button[aria-pressed="true"] {
  background: var(--accent);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 10px 18px rgba(47, 111, 237, 0.22);
}

.icon-button {
  border: 1px solid var(--border-soft);
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: 999px;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.icon-button:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.icon-button .icon-moon {
  display: none;
}

[data-theme="dark"] .icon-button .icon-sun {
  display: none;
}

[data-theme="dark"] .icon-button .icon-moon {
  display: inline-flex;
}

.auth-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 19, 34, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
}

.auth-modal[hidden] {
  display: none;
}

.auth-modal__dialog {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: 18px;
  padding: 28px 32px;
  box-shadow: var(--shadow-soft);
  width: min(360px, 100%);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-form h2 {
  margin: 0;
  font-size: 1.3rem;
}

.auth-form__description {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.auth-form__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

.auth-form__field input {
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  padding: 10px 12px;
  font-size: 1rem;
  background: var(--bg-surface-alt);
  color: inherit;
}

.auth-form__field input:focus {
  outline: none;
  box-shadow: var(--focus-ring);
  border-color: transparent;
}

.auth-form__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-start;
}

.auth-form__submit {
  background: var(--accent);
  color: #ffffff;
  border-color: transparent;
}

.auth-form__submit:hover {
  background: var(--accent-hover);
}

.auth-form__cancel {
  background: transparent;
}

.auth-form__error {
  margin: 0;
  color: #d14343;
  font-size: 0.85rem;
}

[data-theme="dark"] .icon-button {
  color: #e5e9ff;
}

.grade {
  display: none;
  background: var(--bg-surface);
  border-radius: 20px;
  box-shadow: var(--shadow-soft);
  padding: 24px;
  border: 1px solid var(--border-soft);
  transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
}

.grade.active {
  display: block;
  animation: fadeIn 0.3s ease forwards;
}

.grade.editing {
  box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-soft);
}

.grade h2 {
  margin: 0 0 18px;
  font-size: clamp(1.4rem, 3vw, 1.8rem);
  font-family: var(--font-accent);
  font-weight: 600;
}

.table-wrapper {
  width: 100%;
  overflow-x: auto;
  border-radius: 16px;
  border: 1px solid var(--border-soft);
  background: var(--bg-surface);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 760px;
  text-align: center;
}

thead th {
  background: var(--table-header-bg);
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 0.8rem;
  padding: 14px 16px;
}

thead th:first-child {
  border-top-right-radius: 16px;
}

thead th:last-child {
  border-top-left-radius: 16px;
}

tbody td {
  border-top: 1px solid rgba(82, 96, 122, 0.12);
  padding: 16px 18px;
  font-size: 0.96rem;
  color: var(--text-secondary);
  background: transparent;
  transition: background 0.2s ease, color 0.2s ease;
}

tbody tr:hover td {
  background: rgba(47, 111, 237, 0.04);
}

td.time {
  font-weight: 600;
  color: var(--text-primary);
  background: var(--table-time-bg);
  border-inline-end: 1px solid rgba(82, 96, 122, 0.12);
}

tbody td[contenteditable="true"] {
  background: var(--edit-highlight);
  color: var(--text-primary);
  box-shadow: inset 0 0 0 1px rgba(31, 42, 68, 0.04);
}

tbody td:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.28);
  background: var(--edit-highlight);
}

.tips {
  margin: 20px 0 0;
  font-size: 0.88rem;
  color: var(--text-secondary);
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 10px 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.tips::before {
  content: "ℹ";
  font-weight: 600;
  color: var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 768px) {
  body {
    padding: 24px 12px 32px;
  }

  .controls {
    border-radius: 16px;
    padding: 14px;
  }

  .controls-group {
    width: 100%;
    justify-content: space-between;
  }

  .control-actions {
    justify-content: flex-end;
  }

  .grade {
    padding: 20px 18px;
    border-radius: 16px;
  }

  table {
    min-width: 560px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

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