/**
 * practice.css
 * ------------
 * 따라쓰기 연습 페이지 공통 레이아웃 (히라가나 / 추후 가타카나·한자)
 * - 글자 표시 영역(.practice-char-display)과 캔버스(.practice-canvas-area)는 역할이 다르므로
 *   HTML에서도 섹션을 나눴습니다.
 */

/* 페이지 전체 */
.page-practice {
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, #fefefe 0%, #f7f8ff 38%, #f7fbff 100%);
  padding-bottom: 0;
}

.page-practice [data-include="site-footer"] {
  display: none;
}

.page-practice .practice-seo-hero,
.page-practice .practice-seo-article {
  display: none !important;
}

.practice-main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding-bottom: 94px;
}

.practice-inner {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding-top: 0.8rem;
  padding-bottom: 0.75rem;
  max-width: 980px;
  margin-left: auto;
  margin-right: auto;
  overflow: hidden;
}

.practice-utility-row {
  width: min(100%, 760px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.card-like {
  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 12px 28px rgba(103, 116, 176, 0.14);
  padding: 0.7rem 0.85rem;
}

.practice-progress {
  flex: 1;
}

.practice-progress-text {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: #586395;
}

.practice-progress-track {
  margin-top: 0.4rem;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #eef1ff;
  overflow: hidden;
}

.practice-progress-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #8b9bff 0%, #62a4ff 100%);
  transition: width 0.25s ease;
}

.btn-continue {
  min-width: 6.5rem;
}

.btn.is-press {
  animation: microPress 180ms ease;
}

@keyframes microPress {
  0% { transform: scale(1); }
  50% { transform: scale(0.97); }
  100% { transform: scale(1); }
}

.theme-toggle-btn {
  margin-left: auto;
  padding: 0.35rem 0.8rem;
  border-radius: 10px;
  background: #f2f5ff;
  color: #45518e;
  font-size: 0.75rem;
  font-weight: 700;
}

.onboarding-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 20, 40, 0.55);
  padding: 1rem;
}

.onboarding-overlay[hidden] {
  display: none;
}

.onboarding-card {
  width: min(92vw, 420px);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.25);
  padding: 1.2rem 1rem;
  text-align: center;
}

.onboarding-card h2 {
  margin: 0;
  font-size: 1.2rem;
}

.onboarding-card p {
  margin: 0.7rem 0 0.9rem;
  color: #5b6482;
  line-height: 1.65;
}

.toast-container {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 130;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast-item {
  min-width: 170px;
  max-width: 300px;
  background: #1f2947;
  color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
  padding: 0.62rem 0.78rem;
  font-size: 0.82rem;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast-item.is-show {
  opacity: 1;
  transform: translateY(0);
}

.loading-indicator {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 125;
  background: #ffffff;
  color: #445087;
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(42, 50, 90, 0.2);
  padding: 0.45rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
}

/* ----- 탭: 히라가나 / 가타카나 / 한자 ----- */
.practice-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 0.75rem;
  width: 100%;
}

.practice-tab {
  padding: 0.5rem 1.15rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: #444;
  background-color: #fff;
  border: 2px solid #e0e0e0;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}

.practice-tab:hover,
.practice-tab:focus-visible {
  border-color: #90caf9;
  outline: none;
}

.practice-tab[aria-selected="true"] {
  color: #0d47a1;
  background-color: #e3f2fd;
  border-color: #0d47a1;
}

.practice-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  min-height: 0;
  justify-content: center;
}

/* ----- JLPT 급수 탭 (한자 모드 전용) ----- */
.jlpt-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem 0.5rem;
  width: 100%;
  max-width: 760px;
  padding: 0.55rem 0.7rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 10px 30px rgba(90, 103, 216, 0.08);
}

.jlpt-tab {
  min-width: 2.75rem;
  padding: 0.4rem 0.65rem;
  font-size: 0.8125rem;
  font-weight: 700;
  color: #555;
  background: #ffffff;
  border: 0;
  border-radius: 0.5rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(56, 65, 157, 0.1);
  transition: background 0.2s, color 0.2s, transform 0.2s;
}

.jlpt-tab:hover,
.jlpt-tab:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.jlpt-tab[aria-selected="true"] {
  color: #ffffff;
  background: linear-gradient(135deg, #8e9cff 0%, #7694ff 100%);
}

/* ----- 한자: 의미·독음 ----- */
.kanji-meta {
  margin-top: 0.95rem;
  width: min(100%, 760px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.kanji-meta-row {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.45;
  text-align: left;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(93, 106, 164, 0.1);
  padding: 0.62rem 0.7rem;
}

.kanji-meta-row:last-child {
  margin-bottom: 0;
}

.kanji-meta-row--small {
  font-size: 0.75rem;
  color: #666;
}

.kanji-meta-label {
  display: block;
  min-width: 0;
  font-weight: 700;
  color: #7d87b0;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kanji-meta-value {
  color: #262f56;
  font-weight: 600;
}

/* ----- 1. 글자 표시 (캔버스와 분리) ----- */
.practice-char-display {
  width: min(100%, 760px);
  text-align: center;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 18px 44px rgba(93, 106, 164, 0.16);
  padding: 0.75rem 0.9rem 0.85rem;
  flex-shrink: 0;
}

.practice-char-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #8691ba;
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/**
 * 매우 크게: 따라쓰기 시각 참고용
 * clamp(최소, 선호, 최대)로 화면 크기에 맞춤
 */
.practice-char-text {
  font-size: clamp(5.4rem, 20vw, 9rem);
  font-weight: 800;
  line-height: 1;
  margin: 0;
  color: #3f4f8f;
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  user-select: none;
}

/* 한자 큰 글자만 명조 (JS에서 .practice-char-text--kanji 부여) */
.practice-char-text.practice-char-text--kanji {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "MS Mincho", "Hiragino Sans",
    "Yu Gothic UI", serif;
}

.practice-char-romaji {
  margin: 0.45rem 0 0;
  font-size: clamp(0.82rem, 2.6vw, 0.98rem);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.06em;
  color: #97a0c2;
  text-transform: lowercase;
}

/* ----- 2. 캔버스 영역 (중앙 정렬) — 한자 보조 UI는 아래로 이어짐 ----- */
.practice-canvas-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  min-height: 0;
}

.practice-canvas-area > .canvas-stack {
  width: 100%;
  max-width: 760px;
  max-height: min(54dvh, 430px);
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background-color: #ffffff;
  box-shadow: 0 18px 42px rgba(104, 119, 178, 0.2);
}

/**
 * 캔버스 뒤 가이드: 반투명 히라가나 (텍스트 렌더링)
 * 이미지 파일 없이도 동작하며, 글자 변경 시 JS로 동기화합니다.
 * pointer-events: none — 필기는 위 canvas로만 전달
 */
.practice-guide-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.practice-guide-char {
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-weight: 600;
  line-height: 1;
  /* 영역 안에 크게 맞춤 (캔버스 비율과 어울리게) */
  font-size: clamp(7rem, 42vmin, 14rem);
  color: #7c8ee0;
  opacity: 0.2;
  user-select: none;
}

.stroke-animation-root {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.practice-canvas-area .practice-canvas {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 560 / 320;
  vertical-align: top;
  touch-action: none;
}

/**
 * 데이터가 없을 때(한자 준비 중 등): 필기만 비활성 — 보조 UI(틀린 한자)는 계속 조작 가능
 */
.practice-canvas-stack--disabled {
  opacity: 0.65;
  pointer-events: none;
}

.practice-canvas-stack--disabled .practice-canvas {
  touch-action: auto;
}

.practice-actions-bar .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ----- 3. 하단 버튼 바: 화면 하단에 고정되는 느낌 ----- */
.practice-actions-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 110;
  width: 100%;
  margin-top: 0;
  padding-top: 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  pointer-events: none;
  background: linear-gradient(180deg, rgba(245, 248, 255, 0.05) 0%, rgba(245, 248, 255, 0.9) 45%, rgba(245, 248, 255, 1) 100%);
}

.practice-actions-inner {
  display: block;
  width: min(100%, 760px);
  justify-content: center;
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 0;
  padding-right: 0;
  padding-top: 0.9rem;
  padding-bottom: 0.9rem;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 14px 36px rgba(100, 112, 168, 0.14);
  pointer-events: auto;
}

.practice-actions-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem 0.75rem;
}

.practice-actions-bar .btn {
  min-width: 8.75rem;
  border: 0;
  border-radius: 14px;
  padding: 0.72rem 1.15rem;
  box-shadow: 0 8px 18px rgba(82, 93, 153, 0.14);
  transition: transform 0.2s, box-shadow 0.2s, filter 0.2s;
}

.page-practice .btn:hover,
.page-practice .btn:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(82, 93, 153, 0.18);
  outline: none;
}

.page-practice .btn-primary {
  background: linear-gradient(135deg, #9ba9ff 0%, #8bb8ff 100%);
  color: #ffffff;
}

.page-practice .btn-secondary {
  background: #f2f5ff;
  color: #4b598f;
}

/* ----- 한자 보조: 캔버스 아래, 시각적 우선순위 낮춤 ----- */
.kanji-tools-below-canvas {
  width: 100%;
  max-width: 760px;
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  opacity: 0.88;
}

.theme-dark.page-practice {
  background: linear-gradient(180deg, #121522 0%, #171d31 42%, #151d2e 100%);
}

.theme-dark .practice-char-display,
.theme-dark .practice-canvas-area > .canvas-stack,
.theme-dark .practice-actions-inner,
.theme-dark .jlpt-tabs,
.theme-dark .kanji-meta-row,
.theme-dark .card-like {
  background: #1e263b;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

.theme-dark .practice-char-text,
.theme-dark .kanji-meta-value {
  color: #e4ebff;
}

.theme-dark .practice-char-label,
.theme-dark .practice-progress-text,
.theme-dark .kanji-meta-label {
  color: #b8c4f2;
}

.theme-dark .practice-progress-track {
  background: #2d3757;
}

.theme-dark .theme-toggle-btn {
  background: #2c3553;
  color: #d5deff;
}

.theme-dark .onboarding-card,
.theme-dark .loading-indicator {
  background: #1e263b;
  color: #dbe5ff;
}

.theme-dark .onboarding-card p {
  color: #bcc9ef;
}

@media (max-width: 768px) {
  .page-practice {
    height: 100dvh;
  }

  .practice-main {
    padding-bottom: 84px;
  }

  .practice-inner {
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
    gap: 0.55rem;
  }

  .practice-char-display,
  .practice-canvas-area > .canvas-stack,
  .practice-actions-inner,
  .kanji-tools-below-canvas {
    width: 100%;
  }

  .practice-utility-row {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .practice-char-display {
    padding: 0.65rem 0.65rem 0.72rem;
    border-radius: 14px;
  }

  .practice-canvas-area > .canvas-stack {
    max-height: min(46dvh, 360px);
  }

  .kanji-meta {
    grid-template-columns: 1fr;
  }

  .practice-actions-inner {
    border-radius: 14px;
    padding: 0.62rem 0.52rem;
  }

  .practice-actions-bar .btn {
    min-width: 7.8rem;
  }
}
