:root {
  --bg-night: #0f1726;
  --panel-bg: rgba(16, 23, 38, 0.82);
  --panel-border: rgba(235, 200, 125, 0.35);
  --text-main: #f7f4eb;
  --text-muted: #d5deec;
  --accent-gold: #edc25e;
  --accent-danger: #f28b82;
  --accent-success: #7dd3a8;
  --btn-primary: #d9a33a;
  --btn-primary-hover: #c5902b;
  --btn-primary-text: #161922;
  --btn-secondary: rgba(40, 53, 78, 0.92);
  --btn-secondary-hover: #354564;
  --btn-secondary-text: #f7f4eb;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-night);
  color: var(--text-main);
  font-family: 'Prompt', 'Tahoma', system-ui, -apple-system, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  word-break: normal;
  line-break: strict;
  overflow-wrap: break-word;
  user-select: none;
}

#canvas-container {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* กรอบคำพูดฝ่ายร้ายเหนือหัว (16px ตามเกณฑ์) */
.villain-bubble {
  position: fixed;
  z-index: 8;
  pointer-events: none;
  max-width: min(380px, calc(100vw - 32px));
  min-width: 200px;
  background: rgba(22, 18, 36, 0.92);
  border: 1.5px solid #e09f5a;
  border-radius: 14px;
  padding: 8px 14px;
  color: #fff8eb;
  font-size: 16px;
  line-height: 1.45;
  word-break: normal;
  line-break: strict;
  text-align: center;
  transform: translate(-50%, -100%);
  backdrop-filter: blur(6px);
  transition: opacity 0.2s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.villain-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  transform: translateX(-50%);
  border-width: 8px 8px 0 8px;
  border-style: solid;
  border-color: #e09f5a transparent transparent transparent;
}

.villain-bubble.hidden,
#quiz-question-view.hidden,
#quiz-wrong-view.hidden {
  display: none;
}

.villain-bubble-name {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  color: #f6b96e;
  margin-bottom: 2px;
}

.villain-bubble-text {
  font-size: 16px;
  font-weight: 500;
  color: #fff9f0;
  word-break: normal;
  line-break: strict;
}

/* ชั้น UI ทั้งหมดห่างขอบจออย่างน้อย 16px */
.ui-layer {
  position: fixed;
  inset: 0;
  padding: 14px 16px;
  pointer-events: none;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* แถบด้านบน: ดวงแก้ว x / 38, เปลี่ยนตัวเอก, เมนูคาถา 1-10, และปุ่มเริ่มใหม่ */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 6px 12px;
  pointer-events: auto;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  backdrop-filter: blur(8px);
}

.progress-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: max-content;
  flex-shrink: 0;
  flex: 1;
}

.gem-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  background: var(--accent-gold);
  transform: rotate(45deg);
  border-radius: 2px;
  flex-shrink: 0;
  box-shadow: 0 0 8px rgba(237, 194, 94, 0.6);
}

.progress-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-gold);
  white-space: nowrap;
}

.progress-track {
  flex: 1;
  height: 8px;
  background: #1f2b42;
  border-radius: 99px;
  overflow: hidden;
  min-width: 40px;
  max-width: 130px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-gold);
  border-radius: 99px;
  transition: width 0.25s ease;
}

.verse-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.verse-select,
.hero-top-select {
  min-height: 40px;
  padding: 4px 10px;
  background-color: var(--btn-secondary);
  color: var(--btn-secondary-text);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
}

.verse-select:focus-visible,
.hero-top-select:focus-visible {
  border-color: var(--accent-gold);
}

.verse-menu-toggle,
.reset-top-btn {
  min-height: 40px;
  padding: 0 10px;
  background-color: var(--btn-secondary);
  color: var(--btn-secondary-text);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.verse-menu-toggle:hover,
.reset-top-btn:hover {
  background-color: var(--btn-secondary-hover);
}

/* ปุ่มไอคอนตัวเอกบนจอมือถือ (ซ่อนบนจอใหญ่) */
.hero-mobile-btn {
  display: none;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 0 8px;
  background-color: var(--btn-secondary);
  color: var(--btn-secondary-text);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.hero-mobile-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.75);
  flex-shrink: 0;
}

/* แผงลิ้นชักเลือกตัวเอกและคาถา 1-10 */
.verse-drawer {
  pointer-events: auto;
  max-width: 860px;
  width: 100%;
  margin: 8px auto 0;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 10px;
  display: none;
  flex-direction: column;
  gap: 10px;
  backdrop-filter: blur(8px);
}

.verse-drawer.open {
  display: flex;
}

.drawer-hero-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(235, 200, 125, 0.2);
}

.drawer-section-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent-gold);
}

.drawer-hero-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.drawer-hero-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 36px;
  padding: 4px 6px;
  background: var(--btn-secondary);
  color: var(--text-muted);
  border: 1px solid rgba(235, 200, 125, 0.2);
  border-radius: 8px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.drawer-hero-chip.active {
  background: rgba(217, 163, 58, 0.25);
  color: #fff9eb;
  border-color: var(--accent-gold);
  font-weight: 600;
}

.drawer-verse-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.verse-chip {
  min-height: 42px;
  background-color: var(--btn-secondary);
  color: var(--btn-secondary-text);
  border: 1px solid transparent;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 6px;
  text-align: center;
}

.verse-chip:hover {
  background-color: var(--btn-secondary-hover);
}

.verse-chip.active {
  background-color: var(--btn-primary);
  color: var(--btn-primary-text);
  font-weight: 600;
}

/* หน้าแรก (Intro Card) */
.intro-modal {
  pointer-events: auto;
  margin: auto auto 8px auto;
  max-width: 540px;
  width: 100%;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 16px 20px;
  text-align: center;
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.intro-modal.hidden {
  display: none;
}

.intro-subtitle-tag {
  font-size: 13.5px;
  color: var(--accent-gold);
  font-weight: 600;
  margin-bottom: 2px;
}

.intro-title {
  font-size: clamp(24px, 4.5vw, 30px);
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.25;
  margin-bottom: 6px;
}

.intro-desc {
  font-size: 15.5px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 12px;
  word-break: normal;
  line-break: strict;
  user-select: text;
}

/* แถวเลือกตัวเอกในหน้าแรก */
.hero-picker-box {
  background: rgba(11, 17, 30, 0.65);
  border: 1px solid rgba(235, 200, 125, 0.25);
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.hero-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.hero-picker-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent-gold);
}

.hero-stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hero-arrow-btn {
  min-width: 34px;
  min-height: 32px;
  padding: 2px 8px;
  background: var(--btn-secondary);
  color: var(--text-main);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.hero-arrow-btn:hover {
  background: var(--btn-secondary-hover);
}

.hero-current-name {
  min-width: 92px;
  font-size: 15px;
  font-weight: 700;
  color: #fff8e7;
  text-align: center;
}

.hero-cards-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}

.hero-card-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 54px;
  padding: 6px 4px;
  background: rgba(34, 46, 70, 0.85);
  color: var(--text-muted);
  border: 1.5px solid rgba(235, 200, 125, 0.2);
  border-radius: 10px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}

.hero-card-btn:hover {
  background: rgba(52, 69, 102, 0.95);
  border-color: rgba(237, 194, 94, 0.55);
}

.hero-card-btn.active {
  background: rgba(217, 163, 58, 0.22);
  color: #fff9eb;
  border-color: var(--accent-gold);
  box-shadow: 0 0 12px rgba(237, 194, 94, 0.28);
}

.hero-card-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.65);
  flex-shrink: 0;
}

.hero-card-title {
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.hero-picker-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.35;
  min-height: 18px;
}

/* ปุ่มกด */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.btn-primary {
  background-color: var(--btn-primary);
  color: var(--btn-primary-text);
}

.btn-primary:hover {
  background-color: var(--btn-primary-hover);
}

.btn-secondary {
  background-color: var(--btn-secondary);
  color: var(--btn-secondary-text);
  border: 1px solid var(--panel-border);
}

.btn-secondary:hover {
  background-color: var(--btn-secondary-hover);
}

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

.btn-full {
  width: 100%;
}

/* พื้นที่แผงด้านล่าง: อยู่ครึ่งล่างของจอเสมอ ไม่บังตัวละครที่อยู่ครึ่งบน */
.bottom-area {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  pointer-events: none;
}

.stage-panel {
  pointer-events: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 14px 18px;
  backdrop-filter: blur(10px);
}

.stage-panel.hidden {
  display: none;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.card-meta {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-gold);
}

.card-nav-mini {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mini-step-btn {
  min-width: 34px;
  min-height: 32px;
  padding: 2px 8px;
  background: var(--btn-secondary);
  color: var(--text-main);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

.mini-step-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* โหมดคำถาม (สถานการณ์ + ปุ่มทางเลือก) */
.quiz-situation {
  font-size: 17.5px;
  color: var(--text-main);
  line-height: 1.6;
  margin-bottom: 10px;
  word-break: normal;
  line-break: strict;
  user-select: text;
}

.choices-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.choice-btn {
  width: 100%;
  min-height: 44px;
  padding: 9px 14px;
  background: rgba(36, 49, 74, 0.92);
  color: var(--text-main);
  border: 1px solid rgba(235, 200, 125, 0.28);
  border-radius: 10px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
  word-break: normal;
  line-break: strict;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.choice-btn:hover {
  background: rgba(54, 72, 107, 0.96);
  border-color: var(--accent-gold);
}

/* โหมดตอบผิด (คำอธิบาย + ปุ่มลองใหม่) */
.wrong-box {
  background: rgba(70, 28, 35, 0.55);
  border-left: 4px solid var(--accent-danger);
  border-radius: 0 10px 10px 0;
  padding: 10px 14px;
  margin-bottom: 12px;
}

.wrong-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-danger);
  margin-bottom: 4px;
}

.wrong-reply {
  font-size: 17.5px;
  color: var(--text-main);
  line-height: 1.6;
  word-break: normal;
  line-break: strict;
}

/* โหมดการ์ดความรู้ (เมื่อชนะด่านแล้ว) */
.card-title {
  font-size: clamp(28px, 4.5vw, 32px);
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.3;
  margin-bottom: 8px;
  word-break: normal;
  line-break: strict;
}

.card-body {
  user-select: text;
  margin-bottom: 12px;
}

.card-meaning {
  font-size: 17.5px;
  color: var(--text-main);
  line-height: 1.6;
  margin-bottom: 8px;
  word-break: normal;
  line-break: strict;
}

.card-example-box {
  background: rgba(255, 255, 255, 0.06);
  border-left: 3px solid var(--accent-gold);
  padding: 7px 12px;
  border-radius: 0 8px 8px 0;
}

.card-example {
  font-size: 17.5px;
  color: var(--text-muted);
  line-height: 1.6;
  word-break: normal;
  line-break: strict;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
}

/* การ์ดฉากจบที่ยอดเขา */
.finale-card {
  border-color: var(--accent-gold);
  text-align: center;
}

.finale-title {
  font-size: clamp(28px, 4.5vw, 32px);
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.3;
  margin-bottom: 8px;
}

.finale-desc {
  font-size: 17.5px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 14px;
  word-break: normal;
  line-break: strict;
  user-select: text;
}

/* ปรับแต่งสำหรับจอมือถือ (390px) */
@media (max-width: 560px) {
  .ui-layer {
    padding: 8px 10px;
  }

  .top-bar {
    padding: 5px 8px;
    gap: 4px;
    max-width: 100%;
    box-sizing: border-box;
  }

  .progress-text {
    font-size: 13px;
  }

  .progress-track {
    display: none;
  }

  .verse-menu-toggle {
    display: none;
  }

  .hero-top-select {
    display: none;
  }

  .hero-mobile-btn {
    display: inline-flex;
  }

  .verse-select {
    padding: 4px 6px;
    font-size: 12px;
    max-width: 92px;
    min-height: 36px;
  }

  .reset-top-btn {
    padding: 0 8px;
    font-size: 11.5px;
    min-height: 36px;
  }

  .drawer-hero-row {
    grid-template-columns: repeat(3, 1fr);
  }

  .drawer-verse-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .intro-modal {
    padding: 12px 14px;
    margin-bottom: 4px;
  }

  .intro-title {
    font-size: 23px;
    margin-bottom: 4px;
  }

  .intro-desc {
    font-size: 14px;
    line-height: 1.42;
    margin-bottom: 8px;
  }

  .hero-picker-box {
    padding: 8px 8px;
    margin-bottom: 10px;
  }

  .hero-picker-header {
    margin-bottom: 6px;
  }

  .hero-card-btn {
    min-height: 46px;
    padding: 4px 2px;
  }

  .hero-card-dot {
    width: 14px;
    height: 14px;
  }

  .hero-card-title {
    font-size: 11.5px;
  }

  .hero-picker-desc {
    font-size: 12px;
  }

  .stage-panel {
    padding: 11px 13px;
  }

  .card-title,
  .finale-title {
    font-size: 25px;
    margin-bottom: 5px;
  }

  .quiz-situation,
  .wrong-reply,
  .card-meaning,
  .card-example,
  .finale-desc {
    font-size: 16px;
    line-height: 1.5;
  }

  .choice-btn {
    font-size: 15px;
    padding: 8px 11px;
    min-height: 40px;
  }

  .villain-bubble {
    font-size: 15px;
    padding: 6px 11px;
    max-width: calc(100vw - 24px);
  }
}
