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

html {
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  hanging-punctuation: first last;
  scroll-padding-top: var(--space-16);
  touch-action: pan-x pan-y;
}

body {
  min-height: 100dvh;
  line-height: 1.6;
  font-family: var(--font-body, sans-serif);
  font-size: var(--text-base);
  color: var(--color-text);
  background-color: var(--color-bg);
}

img, picture, video, canvas, svg { display: block; max-width: 100%; height: auto; }
ul[role="list"], ol[role="list"] { list-style: none; }
input, button, textarea, select { font: inherit; color: inherit; }

h1, h2, h3, h4, h5, h6 { text-wrap: balance; line-height: 1.15; }
p, li, figcaption { text-wrap: pretty; max-width: 72ch; }

::selection {
  background: rgba(139, 105, 20, 0.25);
  color: var(--color-text);
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

button { cursor: pointer; background: none; border: none; }
table { border-collapse: collapse; width: 100%; }

a, button, [role="button"], [role="link"], input, textarea, select {
  transition: color var(--transition-interactive),
              background var(--transition-interactive),
              border-color var(--transition-interactive),
              box-shadow var(--transition-interactive);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0;
}

/* ===== 우클릭 · 선택 차단 ===== */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea { -webkit-user-select: text; user-select: text; }

/* ===== App Shell — 모바일: flex 앱 셸 / 데스크탑: 일반 스크롤 ===== */
@media (max-width: 768px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
  }
  .header { flex-shrink: 0; transition: transform .3s, opacity .3s; }
  .header-hidden { transform: translateY(-100%); opacity: 0; pointer-events: none; position: absolute; width: 100%; z-index: 100; }
  .app-content {
    flex: 1 1 0;
    min-height: 0;
    position: relative;
    overflow: hidden;
  }

  /* Section Pages — 모바일 탭 전환 */
  .section-page {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    opacity: 0;
    visibility: hidden;
    transform: translateX(8px);
    transition: opacity .3s, visibility .3s, transform .3s;
    will-change: transform, opacity;
  }
  .section-page.section-active {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    z-index: 1;
  }
}

/* 데스크탑: 일반 스크롤 레이아웃, 모든 섹션 표시 */
@media (min-width: 769px) {
  .section-page { opacity: 1; visibility: visible; transform: none; }
  .header-hidden { transform: none; opacity: 1; pointer-events: auto; position: static; }
}

/* ===== Bottom Tab Bar — 모바일 전용 ===== */
.tab-bar {
  flex-shrink: 0;
  display: none;
  justify-content: space-around;
  align-items: center;
  background: var(--color-surface, #1a1a2e);
  border-top: 1px solid var(--color-border, rgba(255,255,255,0.08));
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px));
  z-index: 1000;
}
@media (max-width: 768px) {
  .tab-bar { display: flex; }
}
.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  border-radius: 12px;
  color: var(--color-text-muted, #666);
  transition: color .2s, background .2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.tab-item span { font-size: 0.65rem; font-weight: 500; }
.tab-item svg { width: 22px; height: 22px; transition: transform .2s; }
.tab-item.active { color: var(--color-primary, #c8a84e); }
.tab-item.active svg { transform: scale(1.1); }
.tab-item:active { background: rgba(255,255,255,0.06); transform: scale(0.95); }

/* ===== Lightbox ===== */
.lightbox-overlay {
  position: fixed; inset: 0; z-index: 10001;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden;
  transition: opacity .3s, visibility .3s;
}
.lightbox-overlay.open { opacity: 1; visibility: visible; }
.lightbox-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.92); }
.lightbox-content {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  touch-action: pan-x pan-y pinch-zoom;
  overflow: hidden;
}
.lightbox-img {
  max-width: 95vw; max-height: 90vh;
  object-fit: contain;
  transition: opacity .3s, transform .1s;
  will-change: transform;
}
.lightbox-close {
  position: absolute; top: max(12px, env(safe-area-inset-top, 12px)); right: 12px; z-index: 2;
  background: rgba(0,0,0,0.5); border: none; color: #fff;
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
}
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  background: rgba(0,0,0,0.4); border: none; color: #fff;
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
}
.lightbox-prev { left: 8px; }
.lightbox-next { right: 8px; }

/* ===== Region Map Overlay ===== */
#regionOverlay polygon {
  pointer-events: all;
  cursor: pointer;
  fill: rgba(0,0,0,0.001);
  stroke: none;
  stroke-width: 0;
  transition: fill .25s, stroke .25s, stroke-width .25s;
}
#regionOverlay polygon:hover {
  fill: rgba(255, 255, 255, 0.15);
  stroke: rgba(255, 255, 255, 0.4);
  stroke-width: 3;
}

/* ===== Region Modal ===== */
.region-modal-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden;
  transition: opacity .3s, visibility .3s;
}
.region-modal-overlay.open { opacity: 1; visibility: visible; }

.region-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.region-modal {
  position: relative;
  background: var(--color-surface, #1a1a2e);
  border: 1px solid var(--color-border, rgba(255, 255, 255, 0.1));
  border-radius: 16px;
  max-width: 520px; width: 92%; max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  animation: regionModalIn .35s ease;
}
@keyframes regionModalIn {
  from { transform: translateY(24px) scale(0.96); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

.region-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--color-border, rgba(255, 255, 255, 0.08));
}
.region-modal-title {
  font-family: 'Noto Serif KR', serif;
  font-size: 1.35rem; font-weight: 700; margin: 0;
  color: var(--color-text, #e0e0e0);
}
.region-modal-close {
  background: none; border: none;
  color: var(--color-text-muted, #888);
  cursor: pointer; padding: 4px; border-radius: 8px;
  transition: color .2s, background .2s;
}
.region-modal-close:hover {
  color: var(--color-text, #e0e0e0);
  background: rgba(255, 255, 255, 0.08);
}

.region-modal-body {
  padding: 20px 24px 24px;
  color: var(--color-text-muted, #aaa);
  font-size: 0.95rem; line-height: 1.7;
}
.region-modal-body .region-faction {
  display: inline-block;
  font-size: 0.78rem; font-weight: 600;
  padding: 3px 10px; border-radius: 20px;
  margin-bottom: 12px; letter-spacing: 0.02em;
}
.region-modal-body .faction-demon   { background: rgba(180, 40, 40, 0.15);  color: #e06060; }
.region-modal-body .faction-human   { background: rgba(60, 100, 200, 0.15); color: #6090e0; }
.region-modal-body .faction-neutral { background: rgba(128, 128, 128, 0.15); color: #a0a0a0; }
.region-modal-body .faction-dragon  { background: rgba(80, 160, 180, 0.15); color: #60b0c0; }
.region-modal-body .faction-mixed   { background: rgba(140, 120, 60, 0.15); color: #c0a860; }
.region-modal-body p { margin: 0 0 10px; }

.region-modal-body .region-traits {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px;
}
.region-modal-body .region-trait {
  font-size: 0.8rem; padding: 4px 10px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text-muted, #999);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
