@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;600;700;800&display=swap');

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

:root { --vkb-height: 0px; }

body {
  font-family: 'Noto Sans KR', 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(135deg, #fce7f3 0%, #fef9c3 33%, #dcfce7 66%, #dbeafe 100%);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1.5rem 1rem;
  padding-bottom: calc(1.5rem + var(--vkb-height));
  transition: padding-bottom 0.2s ease;
}

#app {
  background: #fff;
  border-radius: 20px;
  padding: 1.6rem 2rem 2rem;
  width: 100%;
  max-width: 860px;
  box-shadow: 0 2px 0 rgba(0,0,0,0.04), 0 12px 48px rgba(244, 114, 182, 0.12);
  border: 1px solid rgba(244, 114, 182, 0.1);
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #f3f4f6;
  gap: 1rem;
}

h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  white-space: nowrap;
  background: linear-gradient(90deg, #ec4899 0%, #ca8a04 40%, #16a34a 70%, #2563eb 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.mode-select {
  padding: 0.38rem 2rem 0.38rem 0.8rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  color: #2563eb;
  background: #eff6ff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' fill='none' stroke='%232563eb' stroke-width='2' stroke-linecap='round'/></svg>") no-repeat right 0.6rem center;
  border: 2px solid #93c5fd;
  border-radius: 20px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, background 0.15s;
}
.mode-select:hover { border-color: #3b82f6; background-color: #dbeafe; }
.mode-select:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(147,197,253,0.4); }

/* ── Lesson bar ── */
.lesson-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
  font-size: 0.88rem;
}

#lesson-num { color: #aaa; font-weight: 600; }

.lesson-select {
  flex: 1;
  max-width: 280px;
  padding: 0.45rem 2rem 0.45rem 0.8rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: #16a34a;
  background: #f0fdf4 url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' fill='none' stroke='%2316a34a' stroke-width='2' stroke-linecap='round'/></svg>") no-repeat right 0.7rem center;
  border: 2px solid #86efac;
  border-radius: 10px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, background 0.15s;
}
.lesson-select:hover { border-color: #4ade80; background-color: #dcfce7; }
.lesson-select:focus { outline: none; border-color: #4ade80; box-shadow: 0 0 0 3px rgba(134,239,172,0.4); }

#lesson-desc {
  margin: 0.4rem 0 0.2rem;
  font-size: 0.85rem;
  color: #888;
  line-height: 1.4;
}

.kbd-hint {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.1rem 0.45rem;
  background: rgba(255,255,255,0.25);
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* ── Practice area ── */
.practice-area {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  margin: 0.4rem 0 0.8rem;
  background: #fafafa;
  border-radius: 14px;
  border: 1px solid #f0f0f0;
}

#target-display {
  text-align: center;
  transition: transform 0.15s;
}

#target-display.shake {
  animation: shake 0.32s ease;
}

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-10px); }
  60%      { transform: translateX(10px); }
}

.target-char {
  font-size: 6.5rem;
  font-weight: 800;
  color: #222;
  line-height: 1;
}

.target-word {
  font-size: 4rem;
  font-weight: 800;
  color: #222;
  margin-bottom: 0.6rem;
}

.target-jamo {
  display: flex;
  gap: 0.45rem;
  justify-content: center;
  flex-wrap: wrap;
}

.target-jamo span {
  font-size: 1.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 8px;
  color: #ccc;
  background: #f6f6f6;
  transition: all 0.12s;
}

.target-jamo span.active {
  color: #ec4899;
  background: #fce7f3;
  transform: scale(1.15);
}

.target-jamo span.done {
  color: #16a34a;
  background: #dcfce7;
}

.complete-msg {
  text-align: center;
}
.big-star { font-size: 4rem; line-height: 1; }
.complete-msg > div:last-child {
  font-size: 2.6rem;
  font-weight: 800;
  background: linear-gradient(90deg, #ec4899, #eab308, #22c55e, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-top: 0.2rem;
}

/* ── Progress ── */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

#progress-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #e8e8e8;
  transition: background 0.2s, transform 0.15s;
}
.dot.done { background: #86efac; }
.dot.cur  { background: #93c5fd; transform: scale(1.25); }

#score {
  margin-left: auto;
  font-size: 0.88rem;
  font-weight: 700;
  color: #999;
}

/* ── Keyboard ── */
#keyboard-container {
  --key: 2.9rem;
  --gap: 0.38rem;
  background: #f8f8fb;
  border-radius: 14px;
  padding: 1rem 1rem 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap);
  user-select: none;
}

.kb-row {
  display: flex;
  gap: var(--gap);
}
.row-mid { padding-left: calc(var(--key) * 0.5); }
.row-bot { padding-left: calc(var(--key) * 1.0); }

.key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: var(--key);
  height: var(--key);
  background: #f0f0f0;
  border-radius: 7px;
  box-shadow: 0 2px 0 #ccc, 0 2px 4px rgba(0,0,0,0.07);
  cursor: default;
  transition: background 0.1s, box-shadow 0.1s, transform 0.08s;
  gap: 0;
}

.key.consonant { background: #c8e6c9; box-shadow: 0 2px 0 #a5d6a7, 0 2px 4px rgba(0,0,0,0.07); }
.key.vowel     { background: #ffe0b2; box-shadow: 0 2px 0 #ffcc80, 0 2px 4px rgba(0,0,0,0.07); }
.key.special   { background: #eeeeee; box-shadow: 0 2px 0 #bdbdbd, 0 2px 4px rgba(0,0,0,0.07); }

.kp {
  font-size: calc(var(--key) * 0.345);
  font-weight: 700;
  color: #222;
  line-height: 1.1;
}
.ks {
  font-size: calc(var(--key) * 0.2);
  color: #bbb;
  line-height: 1;
}

/* ── Mobile input (hidden, for virtual keyboard) ── */
#mobile-input {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  font-size: 16px;
  border: none;
  outline: none;
  padding: 0;
  margin: 0;
  pointer-events: none;
}

/* Target highlight — pastel yellow */
.key.target {
  background: #fef9c3;
  box-shadow: 0 0 0 3px #fde047, 0 3px 8px rgba(234,179,8,0.2);
  transform: scale(1.08);
}

/* Correct flash — pastel green */
.key.correct {
  background: #dcfce7;
  box-shadow: 0 0 0 3px #86efac;
  transform: scale(1.05);
}

/* Wrong flash — pastel pink-red */
.key.wrong {
  background: #fce7f3;
  box-shadow: 0 0 0 3px #f9a8d4;
  animation: keyWrong 0.32s ease;
}

@keyframes keyWrong {
  0%,100% { transform: translateX(0); }
  30%     { transform: translateX(-4px); }
  70%     { transform: translateX(4px); }
}

/* ── Space hint ── */
.space-hint {
  text-align: center;
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: #bbb;
}

.touch-hint { display: none; }

/* ── Mobile action buttons ── */
.mobile-actions {
  display: none;
}

@media (hover: none) and (pointer: coarse) {
  .mobile-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 0.8rem;
  }
  .mobile-btn {
    flex: 1;
    padding: 0.65rem 0.5rem;
    border: none;
    border-radius: 14px;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    active: opacity 0.75;
  }
  .mobile-btn:active { opacity: 0.75; transform: scale(0.97); }
  .btn-tap {
    background: #dbeafe;
    color: #1d4ed8;
  }
  .btn-shuffle {
    background: #fce7f3;
    color: #be185d;
  }
}

.kbd-hint-key {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  background: #f8f8fb;
  border: 1px solid #e0e0ea;
  border-bottom: 2px solid #c8c8d8;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #888;
}

/* ── Next button — pastel blue ── */
#btn-next {
  display: block;
  margin: 1.1rem auto 0;
  padding: 0.65rem 2.2rem;
  background: #93c5fd;
  color: #1e3a5f;
  border: none;
  border-radius: 25px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.18s, transform 0.1s;
}

#btn-next:hover { background: #60a5fa; transform: scale(1.03); }
#btn-next.hidden { display: none; }

/* ── Responsive ── */
@media (max-width: 620px) {
  body { padding: 0.8rem 0.6rem; }
  #app { padding: 1rem 0.9rem 1.2rem; }

  /* 헤더: 타이틀 작게, 드랍다운 오른쪽 */
  header { margin-bottom: 0.7rem; padding-bottom: 0.7rem; }
  h1 { font-size: 1.1rem; }
  .logo-icon { font-size: 1rem; }
  .mode-select {
    padding: 0.25rem 1.6rem 0.25rem 0.6rem;
    font-size: 0.78rem;
    border-radius: 14px;
  }

  /* 레슨 선택: 카운터 숨기고 전체 너비 */
  #lesson-num { display: none; }
  .lesson-bar { margin-bottom: 0.4rem; }
  .lesson-select { max-width: none; flex: 1; }

  /* 설명 텍스트 숨김 */
  #lesson-desc { display: none; }

  /* 진행 점수 숨김 */
  #score { display: none; }

  /* 연습 영역 */
  .practice-area { min-height: 110px; }

  /* key = (100vw - body_pad 1.2rem - app_pad 1.8rem - kb_pad 1.2rem - gaps 9*0.28rem) / 10 */
  #keyboard-container {
    --key: min(2.1rem, calc((100vw - 7.52rem) / 10));
    --gap: 0.28rem;
    padding: 0.7rem 0.6rem 0.6rem;
  }
  .target-char { font-size: 5rem; }
  .target-word { font-size: 3rem; }
  .target-jamo span { font-size: 1.4rem; }
  .space-key-hint { display: none; }
  .touch-hint { display: inline; }
}

/* ── Tap banner (mobile only) ── */
.tap-banner {
  display: none;
}

@media (hover: none) and (pointer: coarse) {
  .tap-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    position: fixed;
    bottom: calc(1.2rem + var(--vkb-height));
    left: 50%;
    transform: translateX(-50%);
    padding: 0.7rem 1.6rem;
    background: #ec4899;
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    font-family: inherit;
    border-radius: 50px;
    box-shadow: 0 4px 20px rgba(236, 72, 153, 0.4);
    animation: tapPulse 1.6s ease-in-out infinite;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    z-index: 100;
    white-space: nowrap;
  }

  .tap-banner.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(12px);
  }
}

@keyframes tapPulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(236, 72, 153, 0.4); }
  50%       { box-shadow: 0 4px 32px rgba(236, 72, 153, 0.75); transform: translateX(-50%) scale(1.04); }
}

@media (max-width: 400px) {
  /* key = (100vw - 7rem) / 10 */
  #keyboard-container {
    --key: min(1.75rem, calc((100vw - 7rem) / 10));
    --gap: 0.22rem;
  }
}
