/* === Student Screen === */
#student-screen {
  background: #F2F4F6;
  position: relative;
}

.student-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  gap: 1.5rem;
  position: relative;
  z-index: 1;
}

.student-title {
  font-family: var(--font);
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.02em;
}

/* Student seat grid: fluid sizing */
.student-grid .seat {
  width: clamp(56px, 10vw, 110px);
  height: clamp(44px, 7vw, 72px);
  font-size: clamp(0.72rem, 1.2vw, 1rem);
  font-weight: 600;
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.student-grid .seat .seat-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
/* 모둠대형: 그리드 셀에 맞게 좌석 크기 조정 */
.student-grid .group-cluster-seats .seat {
  width: auto;
  height: auto;
  min-height: clamp(44px, 7vw, 72px);
}
.student-grid .seat.empty {
  background: var(--surface);
}
.student-grid .seat.assigned {
  box-shadow: var(--shadow-md);
}
.student-grid .seat .seat-number {
  font-size: 0.65rem;
}
.student-grid .blackboard {
  font-size: 1rem;
  padding: 0.65rem;
  letter-spacing: 4px;
}

/* Draw button - hero CTA */
.student-actions {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
}

.btn-draw {
  padding: 1.1rem 3.5rem;
  font-family: var(--font);
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px var(--primary-glow);
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
  letter-spacing: -0.01em;
}
.btn-draw:hover {
  background: var(--primary-hover);
  box-shadow: 0 6px 20px rgba(49, 130, 246, 0.25);
}
.btn-draw:active {
  background: #1557B0;
}
.btn-draw:disabled {
  opacity: 0.4;
  box-shadow: none;
}

/* Loading animation on draw button */
.btn-draw.loading::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

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

.btn-redraw {
  padding: 0.8rem 2.2rem;
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--primary);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  letter-spacing: -0.01em;
}
.btn-redraw:hover {
  background: var(--primary-light);
  box-shadow: var(--shadow);
}

/* Student toolbar (save/print/fullscreen) */
.student-toolbar {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: none;
  box-shadow: var(--shadow);
}

/* Teacher link button */
.teacher-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
  cursor: pointer;
}
.teacher-link-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.teacher-link-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  box-shadow: var(--shadow-md);
}

/* Hidden name - 3D card flip */
.student-grid .seat.hidden-name {
  perspective: 400px;
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
}
.student-grid .seat.hidden-name .seat-inner {
  position: absolute;
  inset: 0;
  transition: transform 0.5s ease;
  transform-style: preserve-3d;
}
.student-grid .seat.hidden-name .seat-front,
.student-grid .seat.hidden-name .seat-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 2px solid transparent;
}
.student-grid .seat.hidden-name .seat-front {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  font-size: 1.3rem;
  font-weight: 800;
}
.student-grid .seat.hidden-name .seat-back {
  background: var(--seat-assigned);
  border-color: var(--seat-assigned-border);
  transform: rotateY(180deg);
}
.student-grid .seat.hidden-name .seat-back .seat-name {
  font-size: inherit;
  font-weight: 600;
  color: var(--text);
}
.student-grid .seat.hidden-name .seat-back .seat-number {
  position: absolute;
  top: 2px;
  left: 5px;
  font-size: 0.6rem;
  color: var(--text-light);
}
/* 기존 seat-name/seat-number 숨기기 (seat-inner로 대체) */
.student-grid .seat.hidden-name > .seat-name,
.student-grid .seat.hidden-name > .seat-number {
  display: none;
}
/* 뒤집힌 상태 */
.student-grid .seat.hidden-name.flipped .seat-inner {
  transform: rotateY(180deg);
}
/* assigned 체크마크 숨기기 */
.student-grid .seat.hidden-name::after,
.student-grid .seat.hidden-name.flipped::after {
  display: none !important;
}

/* Swap mode */
#btn-swap-mode.active {
  background: var(--primary-light);
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.student-grid .seat.swap-selected {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px var(--primary-glow) !important;
  animation: pulse 1.2s ease infinite;
}

/* Slot machine animation for seats */
.seat.animating .seat-name {
  animation: slotSpin 0.4s ease forwards;
}

/* Staggered pop-in animation */
.seat.reveal {
  animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0;
}

/* U-shape specific */
.ushape-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.ushape-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.ushape-side-wrapper {
  display: flex;
  gap: 40px;
}
.ushape-side {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Pair group */
.pair-grid {
  display: grid;
  gap: 12px 24px;
  justify-content: center;
}
.seat-pair-group {
  display: flex;
  gap: 2px;
  background: var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

/* === Fullscreen mode === */
#student-screen.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9000; /* below modal-overlay z-index:10000 */
}
#student-screen.fullscreen .student-title {
  font-size: 2.2rem;
}
#student-screen.fullscreen .teacher-link-btn,
#student-screen.fullscreen .student-toolbar {
  display: none !important;
}

/* Responsive for projector / large screens */
@media (min-width: 1200px) {
  .student-title {
    font-size: 3rem;
  }
  .btn-draw {
    font-size: 1.8rem;
    padding: 1.3rem 4.5rem;
  }
}
@media (min-width: 1920px) {
  .student-container {
    max-width: 1600px;
    margin: 0 auto;
  }
  .student-title {
    font-size: 3.5rem;
  }
  .student-grid .blackboard {
    font-size: 1.2rem;
    padding: 0.8rem;
  }
}

/* Mobile responsive */
@media (max-width: 600px) {
  .student-container {
    padding: 1rem;
    gap: 1rem;
  }
  .student-title {
    font-size: 1.8rem;
  }
  /* Horizontal scroll for seat grid on small screens */
  .student-grid {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem;
  }
  .student-grid .seat {
    width: clamp(48px, 14vw, 60px);
    height: clamp(40px, 11vw, 50px);
    font-size: 0.72rem;
    min-width: 48px;
  }
  .student-grid .seat .seat-number {
    font-size: 0.5rem;
  }
  .btn-draw {
    font-size: 1.2rem;
    padding: 0.8rem 2rem;
  }
  /* Compact toolbar: 2 rows with smaller buttons */
  .student-toolbar {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.4rem;
  }
  .student-toolbar .btn {
    font-size: 0.72rem;
    padding: 0.3rem 0.5rem;
  }
  .student-toolbar .btn svg {
    width: 14px;
    height: 14px;
  }
  .btn-redraw {
    font-size: 0.95rem;
    padding: 0.6rem 1.5rem;
  }
}

/* === History Modal === */
.history-modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 420px;
  max-height: 70vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.9);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-overlay.active .history-modal-content {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.history-list {
  overflow-y: auto;
  padding: 0.75rem;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 0.5rem;
  transition: border-color 0.15s, background 0.15s;
}
.history-item:hover {
  background: var(--bg);
}

.history-item.current {
  border-color: var(--primary);
  background: var(--primary-light);
}

.history-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--primary);
  color: #fff;
  white-space: nowrap;
}

.history-badge.past {
  background: var(--text-light);
}

.history-info {
  flex: 1;
  min-width: 0;
}

.history-date {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}

.history-detail {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}
.history-restore-btn {
  flex-shrink: 0;
  font-size: 0.7rem !important;
  padding: 0.2rem 0.5rem !important;
}
