:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #7c8ea5;
  --accent-soft: #eef2f7;
  --nav-height: 76px;
  --radius: 14px;
  --card-radius: 18px;
  --space-1: 8px;
  --space-2: 12px;
  --space-3: 16px;
  --space-4: 22px;
  --space-5: 30px;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.07);
  --shadow-hover: 0 16px 34px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--nav-height);
  width: 100%;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1280px;
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--space-4);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.breadcrumb strong {
  color: var(--text);
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: #d1d5db;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.1);
}

.btn:active {
  transform: scale(0.97);
}

.btn:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 38%, white);
  outline-offset: 2px;
}

.btn-textbook {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 36%, white);
  color: color-mix(in srgb, var(--accent) 80%, black);
}

.room-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) 36px;
}

.room-title {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.room-subtitle {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 15px;
}

.topbar-actions .room-textbook-link {
  text-decoration: none;
  white-space: nowrap;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.study-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  cursor: pointer;
}

.study-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.study-card:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 40%, white);
  outline-offset: 2px;
}

.card-title-badge {
  margin: var(--space-3) var(--space-3) 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: calc(100% - 32px);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 34%, white);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 16px;
  line-height: 1.2;
  font-weight: 800;
  text-align: center;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}

.card-title-badge:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, white);
  outline-offset: 2px;
}

.card-media {
  margin: 12px var(--space-3) 0;
  border-radius: 12px;
  width: calc(100% - 32px);
  aspect-ratio: 3 / 2;
  height: auto;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, #f8fafc, #f1f5f9);
  position: relative;
  overflow: hidden;
  display: block;
  padding: 0;
  cursor: pointer;
}

.card-media:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, white);
  outline-offset: 2px;
}

.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-media .placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  text-align: center;
  color: #94a3b8;
  font-size: 13px;
  font-weight: 600;
}

.card-body {
  padding: 14px var(--space-3) var(--space-3);
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-desc {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 13px;
  text-align: center;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.56);
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal.show {
  display: flex;
}

/* 게임 모달: 기본을 뷰포트에 가깝게 크게, iframe은 남은 높이 전부 사용 */
#game-modal.modal {
  padding: max(10px, env(safe-area-inset-top, 0px)) max(10px, env(safe-area-inset-right, 0px))
    max(10px, env(safe-area-inset-bottom, 0px)) max(10px, env(safe-area-inset-left, 0px));
  align-items: stretch;
  justify-content: stretch;
}

#game-modal .modal-panel {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  max-width: none;
  display: flex;
  flex-direction: column;
}

.modal-panel {
  width: min(1080px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-hover);
  overflow: hidden;
}

.modal-head {
  height: 56px;
  padding: 0 var(--space-3);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  min-width: 0;
}

#game-modal .modal-head .modal-tools {
  flex-shrink: 0;
}

.modal-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.game-frame {
  width: 100%;
  height: min(84vh, 860px);
  border: 0;
}

#game-modal .game-frame {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: none;
}

/* 게임 모달을 전체화면으로 켰을 때: iframe이 헤더 아래 높이를 꽉 쓰고(860px 상한 해제), 안쪽 게임이 더 크게 스케일되도록 */
#game-modal.show .modal-panel:fullscreen,
#game-modal.show .modal-panel:-webkit-full-screen {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#game-modal.show .modal-panel:fullscreen .modal-head,
#game-modal.show .modal-panel:-webkit-full-screen .modal-head {
  flex-shrink: 0;
}

#game-modal.show .modal-panel:fullscreen .game-frame,
#game-modal.show .modal-panel:-webkit-full-screen .game-frame {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: auto;
  max-height: none;
}

/* 학습지(text book) 목록·PDF 뷰어: 화면 안에 맞추고 목록은 스크롤 */
#pdf-modal.modal,
#pdf-viewer.modal {
  padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  align-items: center;
}

#pdf-modal .modal-panel,
#pdf-viewer .modal-panel {
  display: flex;
  flex-direction: column;
  width: min(1080px, 100%);
  max-height: min(92vh, calc(100dvh - 24px));
  min-height: 0;
}

#pdf-modal .modal-head,
#pdf-viewer .modal-head {
  flex-shrink: 0;
}

.pdf-frame {
  width: 100%;
  height: min(78vh, 820px);
  border: 0;
}

#pdf-viewer .pdf-frame {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: none;
}

.pdf-list {
  padding: var(--space-3);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.pdf-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px;
}

.pdf-item h4 {
  margin: 0 0 8px;
  font-size: 15px;
}

.pdf-item p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

@media (min-width: 768px) {
  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1280px) {
  .card-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
