@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; }

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;
}

#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 {
  margin-bottom: 0.6rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid #f3f4f6;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

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

.home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-height: 2rem;
  padding: 0.35rem 0.8rem;
  color: #2563eb;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 800;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.home-link:hover {
  background: #dbeafe;
  border-color: #93c5fd;
  transform: translateY(-1px);
}

.home-link:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(147,197,253,0.45);
}

.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); }

.method-select {
  padding: 0.38rem 2rem 0.38rem 0.8rem;
  font-family: inherit;
  font-size: 0.9rem;
  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.6rem center;
  border: 2px solid #86efac;
  border-radius: 20px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, background 0.15s;
}
.method-select:hover { border-color: #4ade80; background-color: #dcfce7; }
.method-select:focus { outline: none; border-color: #4ade80; box-shadow: 0 0 0 3px rgba(134,239,172,0.4); }

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

.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: #a16207;
  background: #fefce8 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='%23a16207' stroke-width='2' stroke-linecap='round'/></svg>") no-repeat right 0.7rem center;
  border: 2px solid #fde047;
  border-radius: 10px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, background 0.15s;
}
.lesson-select:hover { border-color: #ca8a04; background-color: #fef9c3; }
.lesson-select:focus { outline: none; border-color: #ca8a04; box-shadow: 0 0 0 3px rgba(253,224,71,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;
  overflow: hidden;
  isolation: isolate;
  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-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.target-hint {
  position: relative;
  display: inline-block;
  font-size: 3rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: rgba(0,0,0,0.2);
}

.hint-arrow {
  font-size: 1.8rem;
  color: #ccc;
  font-weight: 400;
  user-select: none;
}

.hint-fill {
  position: absolute;
  left: 0;
  top: 0;
  overflow: hidden;
  white-space: nowrap;
  color: rgba(255,140,20,0.95);
  width: 0;
}

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

.target-jamo span {
  font-size: 3.5rem;
  font-weight: 800;
  padding: 0.1rem 0.4rem;
  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); }

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

.kb-row {
  display: flex;
  gap: var(--gap);
}
.row-bot { padding-left: 0; }
.row-space { align-self: stretch; justify-content: center; }

.key {
  position: relative;
  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: pointer;
  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); }

.key:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 transparent, 0 1px 2px rgba(0,0,0,0.05);
}

.kp {
  position: relative;
  z-index: 1;
  font-size: calc(var(--key) * 0.345);
  font-weight: 700;
  color: #222;
  line-height: 1.1;
}

.finger-overlay {
  position: absolute;
  pointer-events: none;
  z-index: 0;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.12));
}
.finger-overlay svg {
  width: 100%;
  height: 100%;
  display: block;
}
.home-key .kp {
  display: inline-block;
  border-bottom: 2px solid #555;
  padding-bottom: 1px;
  line-height: 1;
}

.kp-shift {
  position: absolute;
  top: 0.1em;
  right: 0.18em;
  font-size: calc(var(--key) * 0.22);
  font-weight: 600;
  color: #888;
  line-height: 1;
  z-index: 1;
}

/* Shift 활성 시: shift 라벨이 있는 키는 shift 문자를 크게, 기본 문자 숨김 */
#keyboard-container.shift-active .key.has-shift-label .kp { display: none; }
#keyboard-container.shift-active .key.has-shift-label .kp-shift {
  position: static;
  font-size: calc(var(--key) * 0.345);
  font-weight: 700;
  color: #222;
}
/* shift 라벨 없는 문자 키(en 등)는 대문자로 전환. Ctrl/Alt/Space 같은 기능키는 제외한다. */
#keyboard-container.shift-active .key:not(.has-shift-label):not(.shift-key):not(.special) .kp {
  text-transform: uppercase;
}


/* shift-once: 1회 누름 대기 — 연노랑 배경 + 노랑 테두리 */
#keyboard-container.shift-once .key.shift-key {
  background: #fef9c3;
  box-shadow: 0 0 0 3px #fde047, 0 2px 0 #fde047;
}
/* shift-lock: 2회 눌러 고정 — 진한 노랑 배경 + 짙은 테두리 */
#keyboard-container.shift-lock .key.shift-key {
  background: #fde047;
  box-shadow: 0 0 0 3px #ca8a04, 0 2px 0 #ca8a04;
}
.shift-label {
  font-size: calc(var(--key) * 0.28) !important;
  color: #4a5580;
}
.tab-label {
  font-size: calc(var(--key) * 0.22) !important;
  color: #4a5580;
}

/* Target highlight — 연노랑 배경 + 원형 ripple, 테두리·scale 없음 */
.key.target {
  z-index: 10;
  background: #fef9c3;
  transform: none;
}
.key.target::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  width: var(--key-h, var(--key, 40px));
  height: var(--key-h, var(--key, 40px));
  border-radius: 50%;
  background: rgba(234,179,8,0.6);
  transform: translate(-50%, -50%) scale(0);
  animation: target-ripple 1.1s ease-out infinite;
  pointer-events: none;
}
@keyframes target-ripple {
  0%   { transform: translate(-50%, -50%) scale(0); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.1); opacity: 0; }
}

/* Correct flash — pastel green */
.key.correct {
  background: #dcfce7;
  box-shadow: 0 0 0 3px #86efac;
  transition: none;
}

/* 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;
}

.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; }
.method-select.hidden { display: none; }

/* ── Responsive ── */
@media (max-width: 620px) {
  .finger-overlay { display: none; }

  body { padding: 0.8rem 0.6rem; }
  #app { padding: 1rem 0.9rem 1.2rem; }

  header { margin-bottom: 0.4rem; padding-bottom: 0.5rem; }
  h1 { font-size: 1.1rem; }
  .title-row { gap: 0.55rem; }
  .home-link {
    min-height: 1.8rem;
    padding: 0.28rem 0.65rem;
    font-size: 0.78rem;
  }
  .mode-select, .method-select {
    padding: 0.25rem 1.6rem 0.25rem 0.6rem;
    font-size: 0.78rem;
    border-radius: 14px;
  }

  .lesson-bar { margin-bottom: 0.4rem; gap: 0.4rem; }
  .lesson-select { max-width: none; flex: 1; }

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

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

  /* key = (100vw - body_pad 1.2rem - app_pad 1.8rem - kb_pad 1.2rem - gaps 14*0.28rem) / 15 */
  #keyboard-container {
    --key: calc((100vw - 8.1rem) / 15);
    --gap: 0.28rem;
    padding: 0.7rem 0.6rem 0.6rem;
  }
  .target-jamo span { font-size: 2.5rem; }
  .target-hint { font-size: 2.2rem; }
  .hint-arrow { font-size: 1.4rem; }
  .space-key-hint { display: none; }
}

@media (max-width: 400px) {
  /* key = (100vw - body_pad 1.2rem - app_pad 1.8rem - kb_pad 1.2rem - gaps 14*0.22rem) / 15 */
  #keyboard-container {
    --key: calc((100vw - 7.3rem) / 15);
    --gap: 0.22rem;
  }
}

/* ── Feedback section ── */
.feedback-section {
  margin-top: 1.4rem;
  border-top: 1px solid #f3f4f6;
}

.feedback-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.65rem 1rem;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: #9ca3af;
  cursor: pointer;
  transition: color 0.15s;
}

.feedback-toggle:hover { color: #ec4899; }

.feedback-toggle-icon {
  font-size: 0.7rem;
  transition: transform 0.25s ease;
}

.feedback-toggle[aria-expanded="true"] .feedback-toggle-icon {
  transform: rotate(180deg);
}

.feedback-body {
  overflow: hidden;
  animation: feedbackOpen 0.25s ease;
}

@keyframes feedbackOpen {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.feedback-iframe {
  display: block;
  width: 100%;
  height: 520px;
  border: none;
  border-radius: 12px;
  background: #fafafa;
}
