/* ── 기본 변수와 공통 요소 ── */
:root {
  --bg: #0e0f12;
  --panel: rgba(20, 21, 25, 0.94);
  --panel-2: rgba(32, 33, 38, 0.92);
  --line: #4a4234;
  --line-soft: rgba(232, 163, 58, 0.18);
  --accent: #e8a33a;
  --accent-2: #f6c66a;
  --sky: #6ac8ff;
  --danger: #e2513e;
  --good: #6fdc84;
  --text: #ece6d8;
  --muted: #a39b8c;
  --r0: #d8d8d8;
  --r1: #4aa0ff;
  --r2: #ffd23a;
  --r3: #b45cff;
  --r4: #ff8a1e;
  --r5: #d9b26a;
  --radius: 10px;
  --font: 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --font-title: 'Black Han Sans', 'Noto Sans KR', sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --cur-default: url('../assets/img/cursor/default.png') 4 4, default;
  --cur-point: url('../assets/img/cursor/point.png') 10 2, pointer;
  --cur-attack: url('../assets/img/cursor/attack.png') 16 16, crosshair;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  cursor: var(--cur-default);
}

.app { position: fixed; inset: 0; }

.hidden { display: none !important; }

.game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: var(--cur-default);
}
.game-canvas.cur-attack { cursor: var(--cur-attack); }

button { font-family: inherit; color: inherit; cursor: var(--cur-point); }
button:disabled { cursor: var(--cur-default); }
.btn:disabled { opacity: 0.45; filter: grayscale(0.7); }

img { -webkit-user-drag: none; }

/* ── 스크롤바(직접 꾸밈) ── */
.scroll { overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; touch-action: pan-y; }
.scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll::-webkit-scrollbar-track { background: transparent; }
.scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
.scroll::-webkit-scrollbar-thumb:hover { background-color: var(--accent); }

/* ── 버튼 ── */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #2b2a28, #1c1b1a);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  padding: 12px 22px;
  border-radius: var(--radius);
  letter-spacing: 0.02em;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease, filter 0.08s ease;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}
.btn:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--line-soft), 0 2px 0 rgba(0, 0, 0, 0.4); }
/* 누름: 자리는 그대로 두고 안으로 눌린 듯 어둡게(위치가 바뀌면 스크롤 상자가 흔들린다) */
.btn:active:not(:disabled) { filter: brightness(0.82); box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.55); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: linear-gradient(180deg, #e8a33a, #b8741c); border-color: #f6c66a; color: #1a1208; }
.btn-primary:hover { background: linear-gradient(180deg, #f6b84e, #c98424); }
.btn-ghost { background: transparent; box-shadow: none; }
.btn-danger { background: linear-gradient(180deg, #a83a2c, #7a2418); border-color: #e2513e; }
.btn-small { font-size: 15px; padding: 10px 16px; }

/* ── 입력칸 ── */
.input {
  appearance: none;
  width: 100%;
  border: 1px solid var(--line);
  background: #121214;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  padding: 11px 14px;
  border-radius: var(--radius);
  outline: none;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--line-soft); }
.input::placeholder { color: #6a645a; }

/* ── 막대 ── */
.bar { position: relative; height: 8px; background: rgba(0, 0, 0, 0.55); border-radius: 4px; overflow: hidden; border: 1px solid rgba(0, 0, 0, 0.6); }
.bar-fill { position: absolute; inset: 0; transform-origin: left center; transform: scaleX(var(--hp, 1)); background: linear-gradient(180deg, #e8574a, #a82a1e); transition: transform 0.15s linear; }

/* ── 불러오기 ── */
.loading {
  position: absolute; inset: 0; z-index: 90;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(ellipse at center, #1d1a14, #0b0b0d 70%);
  transition: opacity 0.45s ease;
}
.loading-done { opacity: 0; pointer-events: none; }
.loading-title { font-family: var(--font-title); font-size: 54px; color: var(--accent-2); text-shadow: 0 3px 0 #3a2410; }
.loading-bar { width: min(320px, 70vw); height: 6px; border-radius: 3px; background: #26231e; overflow: hidden; }
.loading-fill { height: 100%; background: var(--accent); transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform 0.2s ease; }
.loading-text { color: var(--muted); font-size: 14px; }

/* ── 알림 ── */
.toasts {
  position: absolute; z-index: 58; left: 50%; top: calc(86px + var(--safe-t));
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; width: min(560px, 92vw);
}
.toast {
  background: rgba(16, 16, 18, 0.9);
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
  animation: toast-in 0.25s ease;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.toast-out { opacity: 0; transform: translateY(-6px); }
.toast-good { border-left-color: var(--good); }
.toast-warn { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--sky); }
.toast-gear0 { border-left-color: var(--r0); }
.toast-gear1 { border-left-color: var(--r1); color: #cfe6ff; }
.toast-gear2 { border-left-color: var(--r2); color: #fff2b8; }
.toast-gear3 { border-left-color: var(--r3); color: #ead2ff; }
.toast-gear4 { border-left-color: var(--r4); color: #ffe0c0; }
.toast-gear5 { border-left-color: var(--r5); color: #f6e6c4; }
.toast-mat { border-left-color: #e8d8b0; }
.toast-boss { border-left-color: var(--accent); font-size: 16px; font-weight: 700; color: var(--accent-2); padding: 12px 22px; }
.toast-area {
  border: none; background: none; font-family: var(--font-title); font-size: 34px; color: var(--accent-2);
  text-shadow: 0 2px 0 #000, 0 0 18px rgba(0, 0, 0, 0.8);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ── 말풍선 ── */
.tooltip {
  position: fixed; z-index: 95; left: var(--tx); top: var(--ty);
  transform: translate(-50%, -100%);
  max-width: 280px; padding: 8px 12px;
  background: rgba(14, 14, 16, 0.96); border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; line-height: 1.5; color: var(--text);
  pointer-events: none;
}
.tooltip-below { transform: translate(-50%, 0); }

/* ── 대화 상자 ── */
.dialog-root {
  position: absolute; inset: 0; z-index: 85;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}
.dialog {
  width: min(420px, 90vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: toast-in 0.2s ease;
}
.dialog-title { margin: 0 0 8px; font-size: 19px; color: var(--accent-2); }
.dialog-text { margin: 0 0 16px; color: var(--muted); line-height: 1.6; font-size: 14px; white-space: pre-line; }
.dialog-input { margin-bottom: 16px; text-transform: uppercase; letter-spacing: 0.3em; text-align: center; font-size: 22px; font-weight: 700; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 10px; }

/* ── 슬라이더 ── */
.slider { position: relative; height: 28px; flex: 1; cursor: var(--cur-point); touch-action: none; }
.slider-track { position: absolute; left: 10px; right: 10px; top: 12px; height: 4px; border-radius: 2px; background: #2c2a26; }
.slider-fill { position: absolute; left: 0; top: 0; bottom: 0; width: calc(var(--v, 0) * 100%); background: var(--accent); border-radius: 2px; }
.slider-knob {
  position: absolute; top: -7px; left: calc(var(--v, 0) * 100% - 9px);
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent-2); border: 2px solid #3a2410; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

/* 희귀도 색 */
.r0 { color: var(--r0); }
.r1 { color: var(--r1); }
.r2 { color: var(--r2); }
.r3 { color: var(--r3); }
.r4 { color: var(--r4); }
.r5 { color: var(--r5); }
