/* === CSS Variables & Reset === */
:root {
  --primary: #3182F6;
  --primary-hover: #1B64DA;
  --primary-light: #E8F3FF;
  --primary-glow: rgba(49, 130, 246, 0.15);
  --accent: #FF8800;
  --accent-hover: #E67A00;
  --accent-light: #FFF4E6;
  --danger: #F04452;
  --danger-hover: #D63341;
  --danger-light: #FFF0F1;
  --success: #00C950;
  --success-light: #E8FAF0;
  --warning: #FF8800;
  --warning-light: #FFF4E6;
  --bg: #F2F4F6;
  --surface: #FFFFFF;
  --text: #191F28;
  --text-secondary: #4E5968;
  --text-light: #8B95A1;
  --text-muted: #B0B8C1;
  --border: #E5E8EB;
  --border-hover: #D1D6DB;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.02);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 16px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --font: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;

  /* seat colors - Toss palette */
  --seat-empty: #F2F4F6;
  --seat-empty-border: #E5E8EB;
  --seat-assigned: #E8FAF0;
  --seat-assigned-border: #00C950;
  --seat-fixed: #FFF4E6;
  --seat-fixed-border: #FF8800;
  --seat-highlight: #E8F3FF;
  --seat-highlight-border: #3182F6;
  --seat-hover: #E5E8EB;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* === Typography === */
h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 12px;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, border-color 0.2s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover {
  box-shadow: var(--shadow);
}
.btn:active {
  box-shadow: none;
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-accent {
  background: var(--accent);
  color: white;
}
.btn-accent:hover {
  background: var(--accent-hover);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--border);
}
.btn-outline:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

.btn-danger {
  color: var(--danger);
  border: 1.5px solid var(--danger);
  background: transparent;
}
.btn-danger:hover {
  background: var(--danger-light);
  border-color: var(--danger);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.btn-ghost:hover {
  background: var(--bg);
  color: var(--text);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 8px;
}

/* === Card === */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  border: none;
  transition: box-shadow 0.2s;
}

/* === Form Elements === */
textarea, input[type="number"], select {
  font-family: var(--font);
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}
textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
textarea {
  width: 100%;
  resize: vertical;
  line-height: 1.8;
}

/* === Badges === */
.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 99px;
  vertical-align: middle;
}
.count-badge {
  font-size: 0.85rem;
  color: var(--primary);
  font-weight: 600;
  margin-left: auto;
}

/* Step Badge */
.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  flex-shrink: 0;
}

/* === Rule List === */
.rule-list {
  list-style: none;
  margin-top: 0.5rem;
}
.rule-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  border: none;
  transition: background 0.15s;
}
.rule-list li:hover {
  background: var(--primary-light);
}
.rule-list .btn-remove {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.rule-list .btn-remove:hover {
  color: var(--danger);
  background: var(--danger-light);
}

/* === Hint text === */
.hint {
  font-size: 0.8rem;
  color: var(--text-light);
}

/* === Warning Banner === */
.warning-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  background: var(--warning-light);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: #92400E;
  margin-bottom: 0.75rem;
}
.warning-banner::before {
  content: '!';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  flex-shrink: 0;
}

/* === Seat Grid (shared) === */
.seat-grid-container {
  position: relative;
}

.seat-grid {
  display: grid;
  gap: 6px;
  justify-content: center;
}

.seat {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
  user-select: none;
  position: relative;
  border: 2px solid transparent;
}
.seat:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.seat.empty {
  background: var(--seat-empty);
  border-color: var(--seat-empty-border);
  color: var(--text-light);
}
.seat.assigned {
  background: var(--seat-assigned);
  border-color: var(--seat-assigned-border);
  color: var(--text);
}
.seat.assigned::after {
  content: '';
  position: absolute;
  bottom: 3px;
  right: 4px;
  width: 10px;
  height: 6px;
  border-left: 2px solid var(--success);
  border-bottom: 2px solid var(--success);
  transform: rotate(-45deg);
  opacity: 0.6;
}
.seat.fixed {
  background: var(--seat-fixed);
  border-color: var(--seat-fixed-border);
}
.seat.fixed::after {
  content: '';
  position: absolute;
  bottom: 3px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  opacity: 0.5;
}
.seat.highlight {
  background: var(--seat-highlight);
  border-color: var(--seat-highlight-border);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.seat:hover {
  box-shadow: var(--shadow-md);
  z-index: 1;
}
.seat .seat-number {
  position: absolute;
  top: 2px;
  left: 5px;
  font-size: 0.6rem;
  color: var(--text-light);
  font-weight: 400;
}
.seat .seat-name {
  font-size: 0.8rem;
  word-break: keep-all;
}

/* === Blackboard === */
.blackboard {
  background: #333D4B;
  color: #D1D6DB;
  text-align: center;
  padding: 0.6rem;
  border-radius: 12px;
  font-size: 0.85rem;
  margin-bottom: 12px;
  letter-spacing: 3px;
  font-weight: 500;
  border: none;
  box-shadow: var(--shadow-md);
  position: relative;
}

/* === Teacher Perspective === */
.blackboard.podium {
  background: #4A3728;
}

/* View Toggle Button */
.view-toggle-wrap {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}
.view-toggle-btn {
  gap: 6px;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
}
.view-toggle-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Print: dual view (hidden on screen, shown in print) */
.print-dual-wrapper {
  display: none;
}

/* === Screen === */
.screen {
  min-height: 100vh;
  animation: screenFadeIn 0.3s ease;
}
@keyframes screenFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* === Toast === */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
@media (max-width: 640px) {
  #toast-container {
    top: auto;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
  }
  .toast {
    max-width: 100%;
  }
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  transform: translateX(120%);
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 360px;
  background: var(--surface);
  color: var(--text);
}
.toast.show {
  transform: translateX(0);
  opacity: 1;
}
.toast-icon {
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}
.toast-success {
  background: var(--surface);
  color: var(--text);
  border-left: 4px solid var(--success);
}
.toast-error {
  background: var(--surface);
  color: var(--text);
  border-left: 4px solid var(--danger);
}
.toast-warning {
  background: var(--surface);
  color: var(--text);
  border-left: 4px solid var(--accent);
}
.toast-info {
  background: var(--surface);
  color: var(--text);
  border-left: 4px solid var(--primary);
}

/* === Confirm Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(25, 31, 40, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s;
}
.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  max-width: 400px;
  width: 90%;
  text-align: center;
  transform: scale(0.9);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-overlay.active .modal-box {
  transform: scale(1);
}
.confirm-message {
  font-size: 1rem;
  font-weight: 500;
  margin-bottom: 1.5rem;
  color: var(--text);
  line-height: 1.6;
}
.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}
.modal-actions .btn {
  min-width: 100px;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
}
.empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  animation: float 3s ease-in-out infinite;
}
.empty-icon-svg {
  display: block;
  margin: 0 auto 1rem;
  color: var(--text-light);
  animation: float 3s ease-in-out infinite;
}
.empty-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

/* === Animations === */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slotSpin {
  0% { transform: translateY(-100%); opacity: 0; }
  50% { transform: translateY(5%); opacity: 1; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes pop {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.5); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes slideDown {
  from { opacity: 0; max-height: 0; transform: translateY(-8px); }
  to { opacity: 1; max-height: 200px; transform: translateY(0); }
}

.animate-fade-in {
  animation: fadeIn 0.3s ease forwards;
}
.animate-slot {
  animation: slotSpin 0.4s ease forwards;
}
.animate-pop {
  animation: pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .btn:hover {
    transform: none;
  }
  .seat:hover {
    transform: none;
  }
}

/* === Accessibility === */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--primary-glow);
}
a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
textarea:focus-visible, input:focus-visible, select:focus-visible {
  outline: none; /* already has border-color + box-shadow via :focus */
}

.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;
}

/* === Print Styles === */
@media print {
  #toast-container,
  .student-actions,
  .student-toolbar,
  .teacher-link-btn,
  .teacher-header,
  .settings-panel,
  .preview-actions,
  .view-toggle-wrap {
    display: none !important;
  }
  .print-dual-wrapper {
    display: block !important;
  }
  /* 인쇄 시 원본 배치도는 JS에서 print-hidden 클래스로 숨김 */
  .print-hidden {
    display: none !important;
  }
  .print-dual-wrapper .print-view-label {
    font-size: 14pt;
    font-weight: 700;
    margin: 20px 0 8px;
    text-align: center;
    page-break-after: avoid;
  }
  .print-dual-wrapper .seat-grid-container {
    margin-bottom: 24px;
    transition: none !important;
  }
  .print-dual-wrapper .blackboard.podium {
    background: #4A3728 !important;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
  body {
    background: white;
  }
  .student-container {
    min-height: auto;
    padding: 1rem;
  }
  .seat {
    border: 1px solid #333 !important;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
  .blackboard {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}

/* === Group Layout (모둠대형) === */
.group-cluster {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 6px;
  background: var(--bg);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.group-cluster:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
}
.group-label {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-light);
  margin-bottom: 4px;
  pointer-events: none;
  user-select: none;
}
