﻿/* Hangul-like study UI inside Class & Study (scoped) */
.cs-hangul-study {
  --surface: #fff;
  --border: #e5e0d8;
  --radius-sm: 12px;
  --red: #c73e3a;
  --red-light: #fde8e7;
  --cream: #f7f5f0;
  --navy: #1a2332;
  --text: #0f1623;
  --text-muted: #5c5a56;
}
.cs-hangul-study .hidden { display: none !important; }
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.tab-bar--icons {
  flex-wrap: wrap;
}

.tab-bar--icons .tab {
  flex-direction: column;
  gap: 0.2rem;
  line-height: 1.15;
  text-align: center;
}

.tab-icon {
  display: none;
  font-size: 1.35rem;
  line-height: 1;
}

.tab-icon--plus {
  font-family: var(--font-ui);
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1;
}

.tab-label-short {
  display: none;
}

.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  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);
}

.tab--builder:not(.active) {
  border-color: rgba(199, 62, 58, 0.35);
  color: var(--red);
}

.tab--builder:not(.active):hover {
  background: rgba(199, 62, 58, 0.08);
  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);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body.hangul-builder-active .syllable-builder,
body.hangul-builder-active .builder-jamo-picker,
body.hangul-builder-active .builder-jamo-grid {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body.builder-jamo-dragging,
body.builder-jamo-dragging * {
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}

.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(68px, 1fr));
  gap: 0.55rem;
}

.builder-jamo-card {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 68px;
  padding: 0.45rem 0.35rem;
  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;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.builder-jamo-card:active {
  transform: scale(0.96);
  border-color: var(--red);
}

.builder-jamo-card.is-dragging {
  opacity: 0.55;
  cursor: grabbing;
}

body.builder-jamo-dragging .builder-jamo-card:not(.is-dragging) {
  pointer-events: none;
}

.builder-jamo-drag-ghost {
  position: fixed;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  min-height: 68px;
  padding: 0.45rem 0.35rem;
  border: 2px solid var(--red);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(15, 22, 35, 0.22);
  pointer-events: none;
  transform: translate(-50%, -50%);
  opacity: 0.96;
}

.builder-jamo-char {
  font-size: 2rem;
  line-height: 1;
  color: var(--navy);
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.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-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.syllable-compose-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
}

.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 svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.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(142px, 1fr));
  gap: 0.8rem;
  width: 100%;
  min-width: 0;
}

.jamo-card {
  position: relative;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 0.6rem 0.75rem;
  text-align: center;
  cursor: default;
  transition: border-color 0.15s, box-shadow 0.15s;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
  z-index: 1;
}

.jamo-card:hover,
.jamo-card.is-popup-open {
  z-index: 20;
}

.jamo-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
}

.jamo-card-play {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-top: 0.05rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--red);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.jamo-card-play:hover {
  border-color: var(--red);
  background: var(--red-light);
}

@media (hover: hover) {
  .jamo-card:hover {
    border-color: var(--navy-light);
    box-shadow: var(--shadow);
  }

  .builder-jamo-card:hover {
    border-color: var(--navy-light);
    background: var(--surface);
    transform: translateY(-1px);
  }
}

.jamo-card.learned::after {
  content: "";
  position: absolute;
  top: 6px;
  left: 6px;
  width: 8px;
  height: 8px;
  background: var(--red);
  border-radius: 50%;
}

.jamo-char {
  font-size: 2.7rem;
  line-height: 1.1;
  margin: 0;
}

.jamo-roman {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  line-height: 1.25;
}

/* Hover / tap popup */
.jamo-popup {
  position: absolute;
  top: calc(100% - 2px);
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  width: max(240px, 18vw);
  max-width: 280px;
  padding-top: 10px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}

.jamo-popup-inner {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
  box-shadow: var(--shadow-lg);
  text-align: left;
}

.jamo-popup-close {
  display: none;
}

.hangul-jamo-popup-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1090;
  border: 0;
  padding: 0;
  background: rgba(15, 23, 42, 0.45);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hangul-jamo-popup-backdrop.hidden {
  display: none;
}

body.hangul-jamo-popup-open {
  overflow: hidden;
}

body.hangul-jamo-popup-open .mobile-tabbar {
  z-index: 1080;
}

.jamo-popup-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  margin: 0 0 0.45rem;
  font-size: 0.72rem;
}

.jamo-popup-type {
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: var(--navy-light);
  color: var(--navy);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.jamo-popup-name {
  font-weight: 600;
  color: var(--text-muted);
}

.jamo-popup-line {
  margin: 0 0 0.4rem;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text);
}

.jamo-popup-label {
  display: block;
  margin-bottom: 0.1rem;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.jamo-popup-examples {
  margin-top: 0.45rem;
}

.jamo-popup-examples-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.jamo-popup-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.jamo-example-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.05rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--cream);
  font: inherit;
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.jamo-example-chip:hover {
  border-color: var(--red);
  background: var(--red-light);
}

.jamo-example-chip .learning-kr {
  font-size: 0.95rem;
  color: var(--navy);
}

.jamo-popup-learn {
  display: block;
  width: 100%;
  margin-top: 0.55rem;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.jamo-popup-learn:hover {
  border-color: var(--navy-muted);
  color: var(--text);
}

.jamo-popup-learn.is-learned {
  border-color: var(--red);
  background: var(--red-light);
  color: var(--red);
}

@media (hover: hover) {
  /* Hover preview only when not explicitly dismissed by a second click */
  .jamo-card:hover:not(.is-popup-dismissed) .jamo-popup,
  .jamo-card:focus-within:not(.is-popup-dismissed) .jamo-popup {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
  }
}

/* Inside Class: click-to-toggle only (no sticky hover popup) */
.cs-hangul-study .jamo-card:hover .jamo-popup,
.cs-hangul-study .jamo-card:focus-within .jamo-popup {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-50%) translateY(6px);
}

.cs-hangul-study .jamo-card.is-popup-open .jamo-popup,
.cs-hangul-study .jamo-card.is-popup-open:hover .jamo-popup,
.cs-hangul-study .jamo-card.is-popup-open:focus-within .jamo-popup {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.jamo-card.is-popup-dismissed .jamo-popup {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.jamo-card.is-popup-open .jamo-popup {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

@media (hover: none) and (pointer: coarse) {
  .hangul-main,
  .jamo-grid {
    overflow: visible;
  }

  .jamo-card.is-popup-open {
    z-index: 1100;
  }

  .jamo-card.is-popup-open .jamo-popup {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    transform: none;
    width: 100%;
    max-width: none;
    padding: 0;
  }

  .jamo-card.is-popup-open .jamo-popup-inner {
    max-height: min(78dvh, 560px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border: 0;
    border-radius: 1rem 1rem 0 0;
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0));
    box-shadow: 0 -10px 40px rgba(15, 23, 42, 0.18);
  }

  .jamo-popup-close {
    display: grid;
    place-items: center;
    position: sticky;
    top: 0;
    z-index: 2;
    width: 2rem;
    height: 2rem;
    margin: 0 0 0.35rem auto;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--cream);
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
  }

  body.has-mobile-tabbar .jamo-card.is-popup-open .jamo-popup {
    bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  body.has-mobile-tabbar .jamo-card.is-popup-open .jamo-popup-inner {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0));
  }
}

.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) {
  .jamo-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.7rem;
  }

  .jamo-card {
    padding: 0.75rem 0.5rem 0.65rem;
  }

  .jamo-char {
    font-size: 2.25rem;
  }


/* Class Hangul combine + scoping fixes */
.cs-hangul-words-mount { min-width: 0; }
.cs-hangul-study { display: grid; gap: 0.85rem; }
.cs-hangul-study .tab-bar { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.cs-hangul-study .tab {
  display: inline-flex; align-items: center; gap: 0.35rem;
  border: 1.5px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 0.45rem 0.8rem; cursor: pointer;
  color: var(--text); font-weight: 700; font-size: 0.82rem;
}
.cs-hangul-study .tab.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.cs-hangul-study .tab-label-short { display: none; }
@media (max-width: 640px) {
  .cs-hangul-study .tab-label-full { display: none; }
  .cs-hangul-study .tab-label-short { display: inline; }
}
.cs-hangul-combine { display: grid; gap: 0.75rem; }
.cs-hangul-combine-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.6rem; }
.cs-hangul-combine-row label { display: grid; gap: 0.25rem; font-size: 0.78rem; font-weight: 700; color: var(--text-muted); }
.cs-hangul-select {
  border: 1.5px solid var(--border); border-radius: 10px; padding: 0.55rem 0.65rem;
  font-size: 1rem; background: #fff; color: var(--text);
}
.cs-hangul-syllable-box {
  display: flex; align-items: center; justify-content: center; gap: 0.75rem;
  border: 1.5px solid var(--border); border-radius: 14px; background: var(--cream);
  padding: 1.1rem; min-height: 5rem;
}
.cs-hangul-syllable-box .learning-kr { font-size: 2.4rem; line-height: 1; }
.cs-hangul-full-link { color: var(--red); font-weight: 700; text-decoration: none; }
.cs-hangul-full-link:hover { text-decoration: underline; }
@media (max-width: 640px) {
  .cs-hangul-combine-row { grid-template-columns: 1fr; }
}

/* Class Combine: match Hangul page builder layout inside Words stage */
.cs-hangul-study.cs-hangul-builder-active .cs-stage-sub:first-of-type {
  display: none;
}
.cs-hangul-study #cs-hangul-combine-panel:not(.hidden) {
  display: block;
}
.cs-hangul-study .syllable-builder {
  margin-top: 0.25rem;
}
.cs-hangul-study .builder-jamo-picker {
  max-height: min(42vh, 360px);
  overflow: auto;
}
.cs-hangul-study.builder-jamo-dragging,
.cs-hangul-study.builder-jamo-dragging * {
  user-select: none;
  -webkit-user-select: none;
}
