/* ==============================================================================
   삼국지 영걸전 RED: 박지훈 편 - 메인 스타일시트
   ============================================================================== */

:root {
  --bg-dark: #0f141c;
  --panel-bg: #18202c;
  --panel-border: #2c3a4f;
  --panel-hover: #222d3d;
  --gold: #d4af37;
  --gold-bright: #f6e05e;
  --gold-dark: #975a16;
  --hero-blue: #3182ce;
  --hero-teal: #319795;
  --danger-red: #e53e3e;
  --text-primary: #edf2f7;
  --text-secondary: #a0aec0;
  --text-muted: #718096;
  --font-base: 'Malgun Gothic', 'Noto Sans KR', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

body {
  font-family: var(--font-base);
  background-color: var(--bg-dark);
  color: var(--text-primary);
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   헤더 툴바
   ========================================================================== */
.game-header {
  height: 54px;
  background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
  border-bottom: 2px solid var(--gold-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  z-index: 50;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.game-badge {
  background: linear-gradient(135deg, #c53030, #9b2c2c);
  color: #fff;
  font-size: 11px;
  font-weight: bold;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid #feb2b2;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.game-title {
  font-size: 16px;
  font-weight: bold;
  letter-spacing: -0.3px;
  color: #f7fafc;
}

.hero-name-highlight {
  color: var(--gold-bright);
  text-shadow: 0 0 8px rgba(246, 224, 94, 0.4);
}

.stage-selector-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.4);
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--gold-dark);
}

.stage-select-dropdown {
  background: transparent;
  color: var(--gold-bright);
  border: none;
  font-size: 12px;
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  max-width: 200px;
}

.stage-select-dropdown option {
  background: #18202c;
  color: #edf2f7;
}

.stage-tag {
  background: rgba(212, 175, 55, 0.15);
  color: var(--gold-bright);
  border: 1px solid var(--gold-dark);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.turn-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: bold;
}

.turn-indicator.player-turn {
  background: rgba(49, 130, 206, 0.2);
  border: 1px solid #3182ce;
  color: #63b3ed;
}

.turn-indicator.enemy-turn {
  background: rgba(229, 62, 62, 0.2);
  border: 1px solid #e53e3e;
  color: #fc8181;
}

.turn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
  box-shadow: 0 0 6px currentColor;
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.header-btn {
  background: #2d3748;
  border: 1px solid #4a5568;
  color: #e2e8f0;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.header-btn:hover {
  background: #4a5568;
  color: #fff;
  border-color: #718096;
}

.header-btn.stat-editor-trigger {
  background: linear-gradient(135deg, #d69e2e, #b7791f);
  color: #fff;
  border: 1px solid #ecc94b;
  box-shadow: 0 0 10px rgba(236, 201, 75, 0.3);
}

.header-btn.stat-editor-trigger:hover {
  background: linear-gradient(135deg, #ecc94b, #d69e2e);
  box-shadow: 0 0 14px rgba(236, 201, 75, 0.6);
  transform: translateY(-1px);
}

.header-btn.btn-end-turn {
  background: linear-gradient(135deg, #c53030, #9b2c2c);
  border: 1px solid #feb2b2;
  color: #fff;
  box-shadow: 0 0 8px rgba(197, 48, 48, 0.4);
}

.header-btn.btn-end-turn:hover {
  background: linear-gradient(135deg, #e53e3e, #c53030);
  box-shadow: 0 0 12px rgba(229, 62, 62, 0.6);
  transform: translateY(-1px);
}

.header-btn.icon-only {
  padding: 6px 10px;
}

/* ==========================================================================
   메인 게임 컨테이너 & 뷰포트
   ========================================================================== */
.game-container {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.canvas-viewport {
  flex: 1;
  background-color: #0a0d14;
  position: relative;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

#battleCanvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
  cursor: crosshair;
}

/* 액션 팝업 메뉴 */
.action-menu {
  position: absolute;
  background: rgba(24, 32, 44, 0.95);
  border: 2px solid var(--gold);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  padding: 4px;
  gap: 2px;
  z-index: 40;
  backdrop-filter: blur(4px);
}

.action-btn {
  background: transparent;
  border: none;
  color: #e2e8f0;
  font-size: 13px;
  font-weight: bold;
  padding: 7px 16px;
  text-align: left;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}

.action-btn:hover {
  background: var(--hero-blue);
  color: #fff;
}

.action-btn.highlight {
  color: var(--gold-bright);
}

.action-btn.highlight:hover {
  background: var(--gold-dark);
  color: #fff;
}

/* 턴 체인지 배너 */
.turn-banner {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: linear-gradient(90deg, transparent, rgba(0,0,0,0.85) 20%, rgba(0,0,0,0.85) 80%, transparent);
  border-top: 2px solid var(--gold);
  border-bottom: 2px solid var(--gold);
  padding: 16px 80px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 60;
}

.turn-banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.turn-banner h2 {
  font-size: 28px;
  letter-spacing: 4px;
  color: var(--gold-bright);
  text-shadow: 0 0 12px rgba(246, 224, 94, 0.6);
}

/* 대화 상자 */
.dialogue-box {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 820px;
  background: rgba(15, 23, 42, 0.95);
  border: 2px solid var(--gold);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  gap: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.8);
  z-index: 70;
  cursor: pointer;
}

.dialogue-avatar-wrap img {
  width: 64px;
  height: 80px;
  border: 1px solid var(--gold);
  border-radius: 4px;
  object-fit: cover;
  image-rendering: pixelated;
  background: #000;
}

.dialogue-content {
  flex: 1;
}

.dialogue-speaker {
  font-size: 15px;
  font-weight: bold;
  color: var(--gold-bright);
  margin-bottom: 6px;
}

.dialogue-text {
  font-size: 14px;
  line-height: 1.5;
  color: #f7fafc;
}

.dialogue-next-hint {
  position: absolute;
  bottom: 8px;
  right: 14px;
  font-size: 11px;
  color: var(--text-muted);
  animation: pulse-dot 1s infinite;
}

/* ==========================================================================
   우측 패널
   ========================================================================== */
.sidebar-panel {
  width: 320px;
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.unit-card {
  padding: 14px;
  background: #151c27;
  border-bottom: 1px solid var(--panel-border);
}

.unit-card-header {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.portrait-box {
  position: relative;
  width: 64px;
  height: 80px;
}

.portrait-box img {
  width: 100%;
  height: 100%;
  border: 1px solid var(--gold-dark);
  border-radius: 4px;
  object-fit: cover;
  image-rendering: pixelated;
  background: #000;
}

.unit-class-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  background: #2b6cb0;
  color: #fff;
  font-size: 10px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid #63b3ed;
}

.unit-main-info {
  flex: 1;
}

.name-mount-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.mount-badge {
  background: rgba(214, 158, 46, 0.2);
  border: 1px solid var(--gold-bright);
  color: var(--gold-bright);
  font-size: 10px;
  font-weight: bold;
  padding: 1px 6px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.unit-name {
  font-size: 17px;
  font-weight: bold;
  color: #fff;
}

.unit-level-info {
  display: flex;
  gap: 6px;
  margin-bottom: 4px;
}

.badge-lv {
  background: #319795;
  color: #fff;
  font-size: 11px;
  font-weight: bold;
  padding: 1px 6px;
  border-radius: 3px;
}

.badge-exp {
  background: #2d3748;
  color: #cbd5e0;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 3px;
}

.unit-camp-tag {
  font-size: 11px;
  font-weight: bold;
}

.unit-camp-tag.player { color: #63b3ed; }
.unit-camp-tag.enemy { color: #fc8181; }

.unit-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.bar-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: bold;
  color: var(--text-secondary);
}

.bar-track {
  height: 8px;
  background: #2d3748;
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  transition: width 0.3s ease;
}

.hp-fill { background: linear-gradient(90deg, #e53e3e, #f56565); }
.mp-fill { background: linear-gradient(90deg, #3182ce, #63b3ed); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.stat-cell {
  background: #1a2332;
  border: 1px solid #2d3748;
  border-radius: 4px;
  padding: 4px 6px;
  text-align: center;
}

.stat-cell.wide {
  grid-column: span 3;
}

.stat-name {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
}

.stat-val {
  font-size: 13px;
  font-weight: bold;
  color: #e2e8f0;
}

.stat-val.highlight {
  color: var(--gold-bright);
}

.unit-edit-btn {
  width: 100%;
  background: linear-gradient(135deg, #2b6cb0, #2c5282);
  border: 1px solid #63b3ed;
  color: #fff;
  padding: 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s;
}

.unit-edit-btn:hover {
  background: linear-gradient(135deg, #3182ce, #2b6cb0);
}

/* 로스터 패널 */
.roster-panel {
  padding: 12px;
  border-bottom: 1px solid var(--panel-border);
}

.section-title {
  font-size: 12px;
  font-weight: bold;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.roster-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.roster-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1a2332;
  border: 1px solid #2d3748;
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.roster-item:hover, .roster-item.active {
  background: #243144;
  border-color: var(--gold-dark);
}

.roster-thumb {
  width: 28px;
  height: 36px;
  border-radius: 3px;
  object-fit: cover;
  image-rendering: pixelated;
  background: #000;
}

.roster-info {
  flex: 1;
}

.roster-name-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: bold;
  color: #fff;
}

.roster-hp-bar {
  height: 4px;
  background: #2d3748;
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}

.roster-hp-fill {
  height: 100%;
  background: #48bb78;
}

/* 전투 로그 */
.battle-log-panel {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.log-stream {
  flex: 1;
  background: #0f141c;
  border: 1px solid #2d3748;
  border-radius: 4px;
  padding: 8px;
  font-size: 11px;
  line-height: 1.6;
  overflow-y: auto;
  max-height: 200px;
}

.log-item {
  color: #cbd5e0;
  border-bottom: 1px solid #1a202c;
  padding: 2px 0;
}

.log-item.info { color: #63b3ed; }
.log-item.damage { color: #fc8181; }
.log-item.crit { color: #ecc94b; font-weight: bold; }
.log-item.heal { color: #68d391; }

/* ==========================================================================
   모달 공통 스타일
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-window {
  width: 90%;
  max-width: 680px;
  background: #18202c;
  border: 2px solid var(--gold);
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  max-height: 85vh;
  overflow: hidden;
  animation: modal-pop 0.25s ease-out;
}

@keyframes modal-pop {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 14px 18px;
  background: #131a24;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 16px;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #f7fafc;
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-close-btn:hover { color: #fff; }

.modal-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 18px;
  background: #131a24;
  border-top: 1px solid var(--panel-border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-btn {
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  border: none;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.modal-btn.primary {
  background: linear-gradient(135deg, #d69e2e, #b7791f);
  color: #fff;
}

.modal-btn.primary:hover {
  background: linear-gradient(135deg, #ecc94b, #d69e2e);
}

.modal-btn.secondary {
  background: #4a5568;
  color: #e2e8f0;
}

.modal-btn.secondary:hover {
  background: #718096;
}

/* 실시간 에디터 내부 그리드 */
.char-tab-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
}

.char-tab {
  background: #243144;
  border: 1px solid #37475d;
  color: #cbd5e0;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.char-tab.active {
  background: var(--hero-blue);
  border-color: #63b3ed;
  color: #fff;
}

.quick-preset-bar {
  background: #131a24;
  border: 1px solid #2d3748;
  border-radius: 6px;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 16px;
}

.preset-label {
  font-size: 12px;
  font-weight: bold;
  color: var(--text-muted);
  margin-right: 4px;
}

.preset-btn {
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  border: none;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: transform 0.1s;
}

.preset-btn:hover { transform: translateY(-1px); }

.preset-btn.btn-fire { background: #9b2c2c; color: #fff; }
.preset-btn.btn-shield { background: #2b6cb0; color: #fff; }
.preset-btn.btn-heart { background: #7b341e; color: #fff; }
.preset-btn.btn-skull { background: #553c9a; color: #fff; }
.preset-btn.btn-gold { background: #975a16; color: #fff; }

.editor-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.editor-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #1e2838;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #2d3a4d;
}

.row-label {
  width: 140px;
  font-size: 12px;
  font-weight: bold;
  color: #e2e8f0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.editor-slider {
  flex: 1;
  accent-color: var(--gold-bright);
  cursor: pointer;
}

.editor-num {
  width: 65px;
  background: #111827;
  border: 1px solid #4a5568;
  border-radius: 4px;
  color: var(--gold-bright);
  font-size: 13px;
  font-weight: bold;
  padding: 4px 6px;
  text-align: center;
}

.editor-num.wide { width: 85px; }

.row-hint {
  width: 130px;
  font-size: 10px;
  color: var(--text-muted);
}

/* PC 세이브 파일 연동 모달 */
.sync-desc {
  font-size: 13px;
  line-height: 1.6;
  color: #cbd5e0;
  margin-bottom: 14px;
}

.drop-zone {
  border: 2px dashed #4a5568;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  background: #141c27;
  cursor: pointer;
  margin-bottom: 14px;
  transition: all 0.2s;
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--gold);
  background: #192332;
}

.drop-icon {
  font-size: 32px;
  color: #63b3ed;
  margin-bottom: 8px;
}

.drop-text {
  font-size: 13px;
  color: #a0aec0;
  margin-bottom: 10px;
}

.drop-btn {
  display: inline-block;
  background: #2b6cb0;
  color: #fff;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
}

.save-status-box {
  background: #111827;
  border: 1px solid #2d3748;
  border-radius: 6px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.status-row {
  display: flex;
  justify-content: space-between;
}
