/* Hangul learning page */

.nav-active {
  color: var(--text) !important;
  font-weight: 600;
}

.hangul-page {
  min-height: calc(100dvh - 72px);
}

body.hangul-detail-open {
  overflow: hidden;
}

.hangul-hero {
  padding: 2rem 0 1.5rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 1.5rem;
  transition: color 0.2s;
}

.back-link:hover {
  color: var(--red);
}

.hangul-hero h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
}

.hangul-hero p {
  color: var(--text-muted);
  max-width: 520px;
  margin-bottom: 1.5rem;
}

.progress-overview {
  max-width: 400px;
}

.progress-overview-text {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 0.5rem;
}

.progress-bar--lg {
  height: 10px;
}

#progress-percent {
  color: var(--red);
}

.hangul-learn {
  padding: 1rem 0 4rem;
}

.hangul-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 2rem;
  align-items: start;
}

.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.tab {
  padding: 0.55rem 1.1rem;
  border: 1.5px solid var(--border);
  border-radius: 100px;
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.tab:hover {
  border-color: var(--navy-muted);
  color: var(--text);
}

.tab.active {
  background: var(--navy);
  border-color: var(--navy);
  color: white;
}

.tab--builder.active {
  background: var(--red);
  border-color: var(--red);
}

/* Syllable builder */
.syllable-builder {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.syllable-builder.hidden {
  display: none;
}

.syllable-builder-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 0.25rem;
}

.syllable-builder-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.syllable-builder-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.syllable-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  min-height: 88px;
  padding: 0.5rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--cream);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.syllable-slot:hover,
.syllable-slot:focus-visible {
  border-color: var(--navy-light);
  outline: none;
}

.syllable-slot.is-active {
  border-color: var(--red);
  background: var(--red-light);
  box-shadow: 0 0 0 2px var(--red-glow);
}

.syllable-slot.is-filled {
  border-style: solid;
  border-color: var(--navy-light);
  background: var(--surface);
}

.syllable-slot--optional {
  border-color: var(--cream-darker);
}

.syllable-slot--optional .syllable-slot-label::after {
  content: " (optional)";
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.builder-jamo-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.syllable-compose {
  padding-top: 0.15rem;
}

.syllable-builder-status {
  margin: 0.65rem 0 0;
  min-height: 1.2em;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--red);
}

.builder-jamo-heading {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.55rem;
}

.builder-jamo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 0.45rem;
}

.builder-jamo-card {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0.35rem 0.25rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--cream);
  cursor: grab;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.builder-jamo-card:active {
  transform: scale(0.96);
  border-color: var(--red);
}

.builder-jamo-card.is-dragging {
  opacity: 0.55;
  cursor: grabbing;
}

.builder-jamo-char {
  font-size: 1.45rem;
  line-height: 1;
  color: var(--navy);
}

.syllable-slot.is-dragover {
  border-color: var(--red);
  background: var(--red-light);
}

.syllable-slot-label {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.syllable-slot-char {
  font-size: 2rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1;
}

.syllable-slot-char.is-empty {
  color: var(--cream-darker);
}

.syllable-op {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-muted);
  user-select: none;
}

.syllable-result-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  min-width: 100px;
}

.syllable-result {
  font-size: 3rem;
  line-height: 1;
  color: var(--red);
  min-height: 3rem;
}

.syllable-play-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: 100px;
  background: var(--surface);
  color: var(--red);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, opacity 0.15s;
}

.syllable-play-btn:hover:not(:disabled) {
  border-color: var(--red);
  background: var(--red-light);
}

.syllable-play-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.syllable-clear-btn {
  padding: 0.45rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--cream);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  margin-left: auto;
  transition: border-color 0.15s, color 0.15s;
}

.syllable-clear-btn:hover {
  border-color: var(--navy-muted);
  color: var(--text);
}

.jamo-card[draggable="true"] {
  cursor: grab;
}

.jamo-card.is-dragging {
  opacity: 0.55;
  cursor: grabbing;
}

.jamo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.85rem;
}

.jamo-card {
  position: relative;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 0.75rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

@media (hover: hover) {
  .jamo-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
    border-color: var(--navy-light);
  }

  .builder-jamo-card:hover {
    border-color: var(--navy-light);
    background: var(--surface);
    transform: translateY(-1px);
  }
}

.jamo-card:active {
  transform: scale(0.97);
  border-color: var(--navy-light);
}

.jamo-card.selected {
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-glow);
}

.jamo-card.learned::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  background: var(--red);
  border-radius: 50%;
}

.jamo-char {
  font-size: 2.5rem;
  line-height: 1.2;
  margin-bottom: 0.35rem;
}

.jamo-roman {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.detail-panel {
  position: sticky;
  top: 96px;
}

.detail-panel-close,
.detail-panel-handle {
  display: none;
}

.detail-panel-backdrop {
  display: none;
}

.detail-empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
}

.detail-empty-icon {
  font-size: 3rem;
  color: var(--navy-light);
  margin-bottom: 1rem;
}

.detail-empty h3 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.detail-empty p {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.detail-content.hidden,
.hidden {
  display: none;
}

.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.detail-char {
  font-size: 4rem;
  text-align: center;
  line-height: 1;
  margin-bottom: 1rem;
  color: var(--navy);
}

.word-play-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.word-play-row .detail-char {
  margin-bottom: 0;
}

.example-play-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--red);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: border-color 0.2s, background 0.2s;
}

.example-play-btn:hover {
  border-color: var(--red);
  background: var(--red-light);
}

.detail-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.detail-type {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--red);
  background: var(--red-light);
  padding: 0.3rem 0.65rem;
  border-radius: 100px;
}

.learned-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--cream);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.learned-btn:hover {
  border-color: var(--red);
  color: var(--red);
}

.learned-btn.is-learned {
  background: var(--red-light);
  border-color: var(--red);
  color: var(--red);
}

.detail-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.detail-pronunciation {
  margin-bottom: 1rem;
}

.detail-roman {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--navy);
}

.detail-sound,
.detail-tip p {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.5;
}

.detail-tip {
  background: var(--cream);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 1rem;
}

.detail-examples {
  margin-bottom: 1.25rem;
}

.example-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.example-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.6rem 0.9rem;
  background: var(--navy-light);
  border-radius: var(--radius-sm);
  min-width: 64px;
}

.example-chip .learning-kr {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--navy);
}

.example-chip span:last-child {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.btn-block {
  width: 100%;
}

.footer--compact {
  padding: 1.5rem 0;
}

.footer--compact .footer-bottom {
  border-top: none;
  padding-top: 0;
}

.footer--compact a {
  color: rgba(255, 255, 255, 0.6);
  text-decoration: none;
  font-size: 0.8rem;
}

.footer--compact a:hover {
  color: white;
}

@media (max-width: 900px) {
  .hangul-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .hangul-learn {
    padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0));
  }

  .detail-panel-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .detail-panel-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .detail-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 201;
    max-height: min(88dvh, 640px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    transform: translateY(110%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
    padding: 0 0 calc(1rem + env(safe-area-inset-bottom, 0));
    background: transparent;
    pointer-events: none;
  }

  .detail-panel.is-open {
    transform: translateY(0);
    pointer-events: auto;
    background: var(--surface);
    border-radius: 1rem 1rem 0 0;
    box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.15);
  }

  .detail-panel-handle {
    display: block;
    width: 2.5rem;
    height: 4px;
    margin: 0.65rem auto 0.35rem;
    border-radius: 100px;
    background: var(--cream-darker);
  }

  .detail-panel-close {
    display: grid;
    place-items: center;
    position: absolute;
    top: 0.65rem;
    right: 0.75rem;
    z-index: 2;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--cream);
    color: var(--text-muted);
    cursor: pointer;
    touch-action: manipulation;
  }

  .detail-panel-close:active {
    background: var(--cream-darker);
  }

  .detail-empty,
  .detail-card {
    margin: 0 0.75rem;
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.12);
  }

  .detail-empty {
    padding: 2rem 1.25rem 1.75rem;
  }

  .detail-card {
    padding: 2.75rem 1.25rem 1.75rem;
  }

  .detail-panel:not(.is-open) {
    visibility: hidden;
  }

  .detail-panel.is-open {
    visibility: visible;
  }
}

@media (max-width: 720px) {
  .hangul-hero {
    padding: calc(1.25rem + env(safe-area-inset-top, 0)) 0 1rem;
  }

  .hangul-hero h1 {
    font-size: clamp(1.5rem, 7vw, 2rem);
  }

  .hangul-hero p {
    font-size: 0.92rem;
    margin-bottom: 1.15rem;
  }

  .progress-overview {
    max-width: none;
  }

  .tab-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.35rem;
    margin-bottom: 1.25rem;
    margin-inline: -0.15rem;
    padding-inline: 0.15rem;
  }

  .tab-bar::-webkit-scrollbar {
    display: none;
  }

  .tab {
    flex: 0 0 auto;
    min-height: 44px;
    white-space: nowrap;
    padding: 0.55rem 1rem;
  }

  .syllable-builder {
    padding: 1rem;
  }

  .builder-jamo-picker {
    grid-template-columns: 1fr;
  }

  .builder-jamo-grid {
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 0.4rem;
  }

  .jamo-card,
  .builder-jamo-card {
    min-height: 44px;
  }

  .syllable-slot {
    min-width: 76px;
    min-height: 76px;
  }

  .syllable-play-btn,
  .syllable-clear-btn,
  .learned-btn,
  .example-play-btn {
    min-height: 44px;
  }

  .example-play-btn {
    width: 44px;
    height: 44px;
  }

  .detail-meta {
    flex-wrap: wrap;
    gap: 0.65rem;
  }

  .detail-char {
    font-size: 3.25rem;
  }

  .voice-bottom {
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0));
  }
}

@media (max-width: 480px) {
  .syllable-builder-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
    justify-items: center;
  }

  .syllable-op {
    display: none;
  }

  .syllable-slot {
    width: 100%;
    min-width: 0;
    min-height: 72px;
  }

  .syllable-result-wrap {
    grid-column: 1 / -1;
    width: 100%;
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
    padding-top: 0.35rem;
    border-top: 1px dashed var(--border);
  }

  .syllable-result {
    font-size: 2.5rem;
    min-height: 2.5rem;
  }

  .syllable-play-btn {
    flex: 1 1 auto;
    justify-content: center;
    min-width: 0;
  }

  .syllable-clear-btn {
    grid-column: 1 / -1;
    margin-left: 0;
    width: 100%;
    justify-content: center;
  }

  .builder-jamo-grid {
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  }

  .jamo-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.55rem;
  }

  .jamo-char {
    font-size: 1.85rem;
  }

  .jamo-roman {
    font-size: 0.72rem;
  }

  .jamo-card {
    padding: 0.75rem 0.35rem 0.65rem;
  }

  .detail-card,
  .detail-empty {
    margin-inline: 0.5rem;
  }

  .example-chip {
    min-width: 56px;
    padding: 0.5rem 0.65rem;
  }
}
