:root {
  color-scheme: dark;
  --bg: #111214;
  --glow: rgba(88, 101, 242, 0.10);
  --card: #1b1d21;
  --surface: #24262b;
  --surface-hover: #2a2d33;
  --input: #202227;
  --panel: #202226;
  --border: rgba(255, 255, 255, 0.075);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f2f3f5;
  --secondary: #b5bac1;
  --muted: #7d828c;
  --disabled: #5d626b;
  --blue: #5865f2;
  --blue-hover: #6875ff;
  --green: #35d07f;
  --green-soft: rgba(53, 208, 127, 0.18);
  --yellow: #f2c94c;
  --yellow-soft: rgba(242, 201, 76, 0.18);
  --not-free: #30333a;
  --red: #ff5c5c;
  --red-soft: rgba(255, 92, 92, 0.16);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px;
  background: radial-gradient(circle at 50% 0%, var(--glow), transparent 420px), var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

.card {
  width: min(980px, calc(100vw - 32px));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  padding: 30px;
  overflow: hidden;
  animation: cardIn 260ms cubic-bezier(.2,.8,.2,1) both;
}

.site-footer {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.site-footer a {
  color: var(--secondary);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--text);
  text-decoration: underline;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 20px;
  position: relative;
  text-align: center;
}

.topbar > div:first-child {
  max-width: 620px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0;
}

.topbar p,
.panel-head p,
.helper {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.user-area {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  position: absolute;
  top: 0;
  right: 0;
  max-width: min(360px, 45%);
}

.user-chip,
.status-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--secondary);
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.user-chip:hover {
  transform: translateY(-1px);
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.is-hidden {
  display: none !important;
}

.loading-view,
.login-view,
.scheduler-view {
  margin-top: 28px;
}

.login-box {
  max-width: 460px;
  margin: 28px auto 0;
  text-align: center;
}

.form-stack {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

label,
.control-field span {
  color: var(--secondary);
  font-size: 13px;
  font-weight: 600;
}

.inline-form {
  display: flex;
  gap: 10px;
  justify-content: center;
}

input,
select {
  width: 100%;
  height: 46px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0 14px;
  color: var(--text);
  outline: none;
  transition: border-color 150ms ease, background-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

select {
  height: 42px;
}

input:hover:not(:focus),
select:hover:not(:focus) {
  border-color: var(--border-strong);
}

input:focus,
select:focus,
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(88, 101, 242, 0.22);
}

input:focus,
select:focus {
  border-color: rgba(88, 101, 242, 0.70);
  background: var(--surface);
}

.primary-button,
.secondary-button,
.quiet-button,
.paint-button,
.toggle,
.weekday-cube,
.slot-button {
  cursor: pointer;
}

.primary-button,
.secondary-button,
.quiet-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border-radius: 14px;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  transition: background-color 150ms ease, transform 150ms ease, box-shadow 150ms ease, filter 150ms ease, color 150ms ease, border-color 150ms ease;
}

.primary-button {
  background: var(--blue);
  color: white;
  min-width: 88px;
}

.primary-button:hover:not(:disabled) {
  background: var(--blue-hover);
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(88, 101, 242, 0.28);
}

.primary-button:active:not(:disabled),
.secondary-button:active:not(:disabled),
.quiet-button:active:not(:disabled) {
  transform: translateY(0) scale(0.985);
  box-shadow: none;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.secondary-button,
.quiet-button {
  background: var(--surface);
  color: var(--secondary);
  border: 1px solid var(--border);
}

.secondary-button:hover,
.quiet-button:hover {
  background: var(--surface-hover);
  color: var(--text);
  transform: translateY(-1px);
}

.danger-hover:hover {
  border-color: rgba(255, 92, 92, 0.45);
  color: #ffb3b3;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
}

.control-field {
  display: grid;
  gap: 8px;
  flex: 1;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  background: transparent;
  color: var(--secondary);
  padding: 0 4px;
}

.format-toggle {
  flex-shrink: 0;
}

.toggle-track {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--not-free);
  transition: background-color 180ms ease;
}

.toggle-knob {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--text);
  transition: transform 180ms cubic-bezier(.2,.8,.2,1);
}

.toggle[aria-pressed="true"] .toggle-track {
  background: rgba(53, 208, 127, 0.35);
}

.toggle[aria-pressed="true"] .toggle-knob {
  transform: translateX(20px);
}

.weekday-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 12px;
  margin-top: 18px;
}

.weekday-cube {
  min-height: 104px;
  position: relative;
  overflow: hidden;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
  color: var(--text);
  transition: transform 180ms cubic-bezier(.2,.8,.2,1), background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.weekday-cube::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.045), transparent 55%);
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
}

.weekday-cube:hover {
  transform: translateY(-5px) scale(1.018);
  background: var(--surface-hover);
  border-color: var(--border-strong);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.30);
}

.weekday-cube:hover::before {
  opacity: 1;
}

.weekday-cube:active {
  transform: translateY(-2px) scale(0.995);
}

.weekday-cube.is-selected {
  border-color: rgba(88, 101, 242, 0.85);
  box-shadow: 0 0 0 4px rgba(88, 101, 242, 0.16), 0 16px 36px rgba(0, 0, 0, 0.30);
}

.cube-title {
  font-size: 15px;
  font-weight: 700;
}

.cube-summary {
  margin-top: 8px;
  font-size: 13px;
  color: var(--secondary);
}

.cube-dots {
  position: absolute;
  left: 14px;
  bottom: 12px;
  display: flex;
  gap: 6px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  opacity: 0.9;
  background: var(--muted);
}

.dot.active {
  background: var(--green);
}

.dot.semi {
  background: var(--yellow);
}

.day-panel {
  margin-top: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 20px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.035);
  animation: panelIn 200ms cubic-bezier(.2,.8,.2,1) both;
}

.day-panel.is-switching {
  animation: panelSwitch 140ms ease both;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.save-state {
  font-size: 13px;
  font-weight: 700;
}

.save-state.saved {
  color: var(--green);
}

.save-state.unsaved {
  color: var(--yellow);
}

.paint-modes {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
  margin-bottom: 16px;
}

.paint-button {
  height: 38px;
  border-radius: 999px;
  padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--secondary);
  font-size: 14px;
  font-weight: 600;
  transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease, color 150ms ease;
}

.paint-button:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.paint-button.is-selected {
  transform: none;
  color: var(--text);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.06);
}

.paint-button.mode-none.is-selected {
  background: var(--not-free);
  border-color: rgba(255,255,255,0.16);
}

.paint-button.mode-semi.is-selected {
  background: var(--yellow-soft);
  border-color: rgba(242,201,76,0.55);
  color: #ffe08a;
}

.paint-button.mode-active.is-selected {
  background: var(--green-soft);
  border-color: rgba(53,208,127,0.55);
  color: #8cffbd;
}

.slot-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}

.slot-button {
  min-height: 38px;
  border-radius: 11px;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.slot-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(0,0,0,0.22);
}

.slot-button:active,
.slot-button.is-painting {
  transform: scale(0.975);
}

.slot-button.state-0 {
  background: var(--not-free);
  color: var(--muted);
  border-color: rgba(255,255,255,0.055);
}

.slot-button.state-1 {
  background: var(--yellow-soft);
  color: #ffe08a;
  border-color: rgba(242,201,76,0.42);
}

.slot-button.state-2 {
  background: var(--green-soft);
  color: #8cffbd;
  border-color: rgba(53,208,127,0.42);
}

.override-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
  background: var(--card);
  border: 1px dashed rgba(255,255,255,0.10);
  border-radius: 16px;
  padding: 12px;
}

.override-row .quiet-button {
  min-height: 38px;
}

.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 10px;
  z-index: 10;
}

.toast {
  min-width: 240px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.10);
  border-left: 4px solid var(--green);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.35);
  animation: toastIn 180ms ease both;
}

.toast.error {
  border-left-color: var(--red);
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: white;
  animation: spin 700ms linear infinite;
}

.skeleton {
  background: linear-gradient(90deg, var(--surface), var(--surface-hover), var(--surface));
  background-size: 200% 100%;
  animation: skeleton 1.2s ease-in-out infinite;
  border-radius: 14px;
}

.skeleton-title {
  width: 230px;
  height: 28px;
}

.skeleton-line {
  width: min(420px, 100%);
  height: 16px;
  margin-top: 14px;
}

.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 24px;
}

.skeleton-cube {
  height: 104px;
}

.is-dragging,
.is-dragging * {
  user-select: none;
  cursor: crosshair;
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

@keyframes panelSwitch {
  from {
    opacity: 0.6;
  }
  to {
    opacity: 1;
  }
}

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

@keyframes skeleton {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 900px) {
  .weekday-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .slot-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (max-width: 650px) {
  body {
    padding: 16px;
  }

  .card {
    padding: 20px;
  }

  .topbar,
  .control-row,
  .panel-head,
  .inline-form {
    flex-direction: column;
  }

  .topbar {
    align-items: center;
  }

  .user-area {
    position: static;
    max-width: none;
    justify-content: center;
  }

  .user-area,
  .inline-form,
  .primary-button,
  .secondary-button,
  .quiet-button {
    width: 100%;
  }

  h1 {
    font-size: 24px;
  }

  .weekday-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .slot-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .toast-container {
    left: 16px;
    right: 16px;
    bottom: 16px;
  }
}

@media (max-width: 420px) {
  .weekday-grid {
    grid-template-columns: 1fr;
  }

  .slot-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
    transform: none !important;
  }
}
