/* ============================================
   성경 낭독 웹앱 — 디자인 시스템
   고령자 최적화 (WCAG AAA 명도 대비 7:1+)
   ============================================ */

/* ── 웹폰트 ── */
@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css');

/* ── CSS 변수 ── */
:root {
  --bg-primary: #1E1E1E;
  --bg-secondary: #282828;
  --bg-card: #2F2F2F;
  --bg-card-hover: #383838;

  --text-primary: #EAEAEA;
  --text-secondary: #B0B0B0;
  --text-muted: #787878;

  --accent: #F5A623;
  --accent-hover: #FFB84D;
  --accent-glow: rgba(245, 166, 35, 0.15);
  --accent-subtle: rgba(245, 166, 35, 0.08);

  --danger: #E85D5D;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-btn: 0 6px 24px rgba(245, 166, 35, 0.25);

  --font-body: 'Pretendard Variable', 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;

  --transition-fast: 0.2s ease;
  --transition-normal: 0.35s ease;
}

/* ── 리셋 ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-weight: 500;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  font-size: 18px;
  user-select: none;
  -webkit-user-select: none;
}

/* ── 화면 시스템 ── */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  flex-direction: column;
}

.screen.active {
  display: flex;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============================================
   홈 화면 (screen-home)
   ============================================ */
.home-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 28px 10px;
  flex-shrink: 0;
}

.home-logo {
  width: 42px;
  height: 42px;
}

.home-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.home-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 400;
  margin-top: 2px;
}

/* ── 모드 선택 ── */
.mode-section {
  padding: 20px 28px 12px;
  flex-shrink: 0;
}

.section-label {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 14px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px 16px;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-normal);
  -webkit-appearance: none;
  appearance: none;
  color: var(--text-primary);
  font-family: var(--font-body);
}

.mode-card:hover,
.mode-card:focus-visible {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
}

.mode-card.selected {
  background: var(--accent-subtle);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.mode-icon {
  font-size: 36px;
  line-height: 1;
}

.mode-name {
  font-size: 21px;
  font-weight: 700;
}

.mode-desc {
  font-size: 15px;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.4;
}

/* ── 파일 목록 ── */
.file-section {
  display: none;
  padding: 10px 28px 120px;
  flex: 1;
  overflow-y: auto;
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-appearance: none;
  appearance: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  text-align: left;
  width: 100%;
  font-size: 19px;
}

.file-item:hover,
.file-item:focus-visible {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.file-item.selected {
  background: var(--accent-subtle);
  border-color: var(--accent);
}

.file-day {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 60px;
  padding: 4px 10px;
  background: var(--accent);
  color: #1a1a1a;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}

.file-label {
  font-weight: 500;
  color: var(--text-primary);
}

/* ── 새 탐색 UI (계층형) ── */
.testament-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.testament-tab {
  flex: 1;
  padding: 12px;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.testament-tab.active {
  background: var(--accent);
  color: #1a1a1a;
  border-color: var(--accent);
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}

.book-grid button {
  padding: 12px 4px;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.book-grid button:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

.btn-back {
  width: 100%;
  padding: 14px;
  background: var(--bg-secondary);
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-back:hover {
  background: var(--bg-card-hover);
}

/* PC 홈 화면 중앙 정렬 및 폰트 크기 유지 */
@media (min-width: 768px) {
  .home-header, .mode-section, .file-section {
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
  }

  .section-label { font-size: 15px; }
  .mode-name { font-size: 18px; }
  .mode-desc { font-size: 13px; }
  .file-item { font-size: 16px; }
  .file-day { font-size: 14px; }
  .testament-tab { font-size: 16px; }
  .book-grid button { font-size: 15px; }
  .btn-back { font-size: 15px; }
}


/* ============================================
   준비 화면 (screen-ready)
   ============================================ */
.ready-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px;
  text-align: center;
  gap: 30px;
}

.ready-actions {
  display: flex;
  gap: 16px;
}

.btn-pc { display: none; }

@media (min-width: 768px) {
  .btn-landscape, .btn-portrait { display: none !important; }
  .btn-pc { display: block !important; }
}

.ready-back {
  position: absolute;
  top: 20px;
  left: 20px;
  background: var(--bg-card);
  border: 1px solid var(--text-muted);
  color: var(--text-secondary);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.ready-back:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

#ready-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--accent);
}

.ready-message {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.6;
  color: var(--text-primary);
}

.btn-start {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1a1a;
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-body);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(245, 166, 35, 0.3);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.4;
}

.btn-start:hover {
  transform: scale(1.05);
  background: var(--accent-hover);
}

.btn-start-portrait {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 2px solid var(--text-muted);
  box-shadow: none;
}

.btn-start-portrait:hover {
  background: var(--bg-card-hover);
}

.btn-start::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 3px solid var(--accent-glow);
  animation: pulse-ring 2s ease-in-out infinite;
}

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

.btn-start:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-btn), 0 0 80px rgba(245, 166, 35, 0.35);
}

.btn-start:active {
  transform: scale(0.97);
}

/* ============================================
   모드 1: 말씀 듣기 (screen-mode1)
   ============================================ */
.mode1-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: calc(100% - 90px); /* 컨트롤러 높이 제외 */
  padding: 30px;
  text-align: center;
  gap: 16px;
}

.mode1-top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
}

#mode1-title {
  font-size: 16px;
  color: var(--text-secondary);
  font-weight: 500;
}

#mode1-percent {
  font-size: 96px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  letter-spacing: -3px;
  text-shadow: 0 4px 30px rgba(245, 166, 35, 0.3);
}

#mode1-remaining {
  font-size: 22px;
  color: var(--text-secondary);
  font-weight: 500;
}

.progress-bar {
  width: 80%;
  max-width: 500px;
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 10px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #FFD280);
  border-radius: 4px;
  width: 0%;
  transition: width 0.5s ease;
}

/* ============================================
   모드 2: 말씀 따라가기 (screen-mode2)
   ============================================ */
.mode2-container {
  position: relative;
  height: calc(100% - 60px);
  display: flex;
  flex-direction: column;
}

.mode2-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid #3a3a3a;
  flex-shrink: 0;
  z-index: 10;
}

#mode2-header-title {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.mode2-audio-bar {
  height: 3px;
  background: #3a3a3a;
  flex-shrink: 0;
}

#mode2-audio-progress {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.5s ease;
}

.verse-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 24px;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

#verse-ref {
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 10px;
  opacity: 0.9;
  flex-shrink: 0;
  transition: opacity 0.2s ease;
}

#verse-content {
  font-size: 34px;
  font-weight: 600;
  line-height: 1.65;
  color: var(--text-primary);
  text-align: center;
  word-break: keep-all;
  transition: opacity 0.2s ease;
}

#verse-counter {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 10px;
  flex-shrink: 0;
}

/* ── 터치 영역 ── */
.touch-next {
  position: absolute;
  top: 0;
  right: 0;
  width: 88%;
  height: 100%;
  cursor: pointer;
  z-index: 5;
  /* 보이지 않는 영역 */
}

/* ============================================
   공통 컨트롤러 (하단 고정)
   ============================================ */
.controller {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--bg-secondary);
  border-top: 1px solid #3a3a3a;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 50;
}

.ctrl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 10px;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  cursor: pointer;
  transition: all var(--transition-fast);
  min-width: 60px;
  min-height: 44px;
}

.ctrl-btn:hover,
.ctrl-btn:focus-visible {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.ctrl-btn.btn-play-pause {
  background: var(--accent);
  color: #1a1a1a;
  min-width: 100px;
  border-color: var(--accent);
}

.ctrl-btn.btn-play-pause:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.ctrl-icon {
  font-size: 18px;
  line-height: 1;
}

.ctrl-label {
  font-size: 11px;
  font-weight: 600;
}

.speed-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}



.ctrl-btn.btn-go-home {
  border-color: var(--danger);
  color: var(--danger);
}

.ctrl-btn.btn-go-home:hover {
  background: rgba(232, 93, 93, 0.1);
}

/* ── 컨트롤러 구분선 ── */
.ctrl-divider {
  width: 1px;
  height: 40px;
  background: #444;
}

/* ============================================
   반응형
   ============================================ */

/* 태블릿 가로 */
@media (min-width: 768px) {
  .mode-cards {
    max-width: 600px;
  }

  .file-list {
    max-width: 700px;
    margin: 0 auto;
  }

  #verse-content {
    font-size: 38px;
  }

  #mode1-percent {
    font-size: 120px;
  }
}

/* 데스크탑 */
@media (min-width: 1024px) {
  .home-header {
    padding: 30px 60px 10px;
  }

  .mode-section {
    padding: 20px 60px 12px;
  }

  .file-section {
    padding: 10px 60px 120px;
  }

  #verse-content {
    font-size: 48px;
    line-height: 1.7;
    max-width: 1000px;
  }

  #mode1-percent {
    font-size: 180px;
  }
  
  #verse-ref {
    font-size: 26px;
  }
}

/* 가로 모드 (Landscape) 최적화 */
@media (orientation: landscape) and (max-height: 500px) {
  .ready-container {
    flex-direction: row;
    gap: 40px;
    padding: 20px;
  }

  .btn-start {
    width: 160px;
    height: 160px;
    font-size: 28px;
  }

  .ready-message {
    font-size: 20px;
  }

  .mode1-container {
    height: calc(100% - 80px);
    padding: 10px 30px;
  }

  #mode1-percent {
    font-size: 72px;
  }

  .controller {
    height: 80px;
  }

  .mode2-container {
    height: calc(100% - 80px);
  }

  #verse-content {
    font-size: 28px;
  }

  .verse-area {
    padding: 16px 30px;
  }
}

/* 좁은 스마트폰 (세로모드 컨트롤러 잘림 방지) */
@media (max-width: 395px) {
  .controller {
    gap: 4px;
    padding: 0 4px;
  }
  .ctrl-btn {
    min-width: 50px;
    padding: 4px 6px;
  }
  .ctrl-icon {
    font-size: 16px;
  }
  .ctrl-label {
    font-size: 10px;
  }
  .ctrl-btn.btn-play-pause {
    min-width: 80px;
  }
  .speed-value {
    font-size: 14px;
  }
  .ctrl-divider {
    height: 30px;
    margin: 0 2px;
  }
}

/* ── 로딩 오버레이 ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  gap: 16px;
  transition: opacity 0.5s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--bg-card);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  font-size: 16px;
  color: var(--text-secondary);
}

/* ── 스크롤바 커스텀 ── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #777;
}

/* ============================================
   iOS 등 가로모드 강제 (CSS Rotation)
   모바일 기기에서 세로(Portrait) 상태일 때 강제로 가로로 눕힘
   ============================================ */
@media screen and (max-width: 899px) and (orientation: portrait) {
  body.force-landscape #screen-ready,
  body.force-landscape #screen-mode1,
  body.force-landscape #screen-mode2 {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vh; /* fallback */
    height: 100vw; /* fallback */
    width: 100dvh;
    height: 100dvw;
    transform: rotate(90deg) translateY(-100%);
    transform-origin: top left;
    overflow: hidden;
  }
}
