/* =========================================================
   체스 인 더 미스틱 — CHESS IN THE MYSTIC
   Palette: void black x white x gray (monochrome)
   Clean modern sans, angular HUD panel
   ========================================================= */

:root {
  --void: #050505;
  --device-bg: #0a0a0a;
  --screen-bg: #0d0d0d;
  --line: #2a2a2a;

  --ink: #141414;
  --gray: #8f8f95;
  --white: #f6f5f3;

  --text-main: #f0efed;
  --text-dim: #8a8a8a;

  --font-body: 'Noto Sans KR', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--void);
  font-family: var(--font-body);
  color: var(--text-main);
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* 로그인/계정 만들기 입력창은 정상적으로 선택/편집 가능해야 함 */
input, textarea {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}

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

/* ---------- 로딩 화면 ---------- */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--void);
  transition: opacity .4s ease;
}
.loading-screen.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-mark {
  font-size: 28px;
  color: var(--white);
  text-shadow: 0 0 16px rgba(255,255,255,0.7);
  animation: loading-pulse 1.6s ease-in-out infinite;
}
@keyframes loading-pulse {
  0%, 100% { opacity: 0.45; transform: scale(0.94); }
  50% { opacity: 1; transform: scale(1.06); }
}

.loading-bar {
  width: 150px;
  height: 3px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
  position: relative;
}
.loading-bar__fill {
  position: absolute;
  top: 0; left: -40%;
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, var(--ink), var(--white));
  animation: loading-slide 1.1s ease-in-out infinite;
}
@keyframes loading-slide {
  0% { left: -40%; }
  100% { left: 100%; }
}

.loading-text {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin: 0;
}

/* 로딩 끝나기 전까진 실제 화면을 투명하게 숨겨둠 */
.stage {
  opacity: 0;
  transition: opacity .5s ease;
}
.stage.is-visible {
  opacity: 1;
}

/* ---------- Outer stage: everything outside the "terminal" is black ---------- */
.stage {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(170,170,178,0.08), transparent 60%),
    var(--void);
  padding: 24px 0;
}

/* ---------- Device frame (mobile-size viewport) ---------- */
.device {
  position: relative;
  width: 100%;
  max-width: 400px;
  height: min(844px, 92vh);
  background: var(--device-bg);
  padding: 12px;
  clip-path: polygon(
    22px 0, 100% 0,
    100% calc(100% - 22px), calc(100% - 22px) 100%,
    0 100%, 0 22px
  );
  box-shadow:
    0 0 0 1px rgba(170,170,178,0.25),
    0 0 50px rgba(170,170,178,0.06),
    0 20px 60px rgba(0,0,0,0.7);
}

.screen {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--screen-bg);
  overflow: hidden;
  clip-path: polygon(
    16px 0, 100% 0,
    100% calc(100% - 16px), calc(100% - 16px) 100%,
    0 100%, 0 16px
  );
  box-shadow: inset 0 0 0 1px var(--line);
}

/* signature element: 상단 붉은 HUD 라인 */
.screen__hud-line {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--ink), var(--white), var(--ink));
  z-index: 4;
}

/* 은은한 스캔라인 텍스처 */
.screen::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(170,170,178,0.02) 0px,
    rgba(170,170,178,0.02) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 2;
}

/* ---------- Panels (login / signup / menu) ---------- */
.panel {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  justify-content: center;
}
.panel.is-active { display: flex; }

.panel__inner {
  padding: 30px 26px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- Brand / logo block ---------- */
.brand { text-align: center; margin-bottom: 4px; }
.brand__glyph {
  display: block;
  color: var(--white);
  font-size: 20px;
  margin-bottom: 10px;
  text-shadow: 0 0 14px rgba(255,255,255,0.6);
}
.brand__title {
  font-family: var(--font-body);
  font-weight: 900;
  font-size: 22px;
  line-height: 1.4;
  letter-spacing: 1px;
  margin: 0;
  background: linear-gradient(90deg, var(--gray), var(--white));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand__title-sub {
  font-size: 16px;
  letter-spacing: 4px;
  opacity: 0.85;
}
.brand__title--sm { font-size: 20px; letter-spacing: 2px; }
.brand__sub {
  font-family: var(--font-body);
  font-size: 12px;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin: 10px 0 0;
}

/* ---------- Form fields ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field__label {
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--text-dim);
  font-weight: 500;
}
.field__label em {
  font-style: normal;
  color: #4a4a4a;
  font-size: 10px;
}

.field__input {
  background: #0a0a0a;
  background: #0a0a0a;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 13px 14px;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text-main);
  letter-spacing: 1px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field__input::placeholder { color: #3a3a3a; }
.field__input:focus {
  border-color: var(--white);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.15);
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 7px;
  padding: 14px 16px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: transform .08s, filter .15s, box-shadow .15s;
}
.btn:active { transform: scale(0.98); }

.btn--primary {
  background: linear-gradient(90deg, var(--gray), var(--white));
  color: var(--ink);
  box-shadow: 0 0 24px rgba(170,170,178,0.35);
}
.btn--primary:hover { filter: brightness(1.08); }

.btn--link {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.3px;
  padding: 6px 4px;
}
.btn--link:hover { color: var(--white); }

.error {
  min-height: 14px;
  font-size: 11px;
  color: var(--white);
  text-align: center;
  margin: 0;
}

.link-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.guest-note {
  text-align: center;
  font-size: 10px;
  color: #4a4a4a;
  margin: -6px 0 0;
}
.ai-notice {
  text-align: center;
  font-size: 9px;
  color: #4a4a4a;
  margin: 4px 0 0;
  letter-spacing: 0.3px;
}

/* ---------- Menu screen (삽화 배경 + 우하단 소형 버튼) ---------- */
.panel--illustrated {
  padding: 0;
}

.menu-bg {
  position: absolute;
  inset: 0;
  background-image: url('main_menu.png');
  background-size: cover;
  background-position: center;
  z-index: 1;
}
/* 이미지 위/아래를 살짝 어둡게 해서 HUD·버튼 글자가 항상 잘 보이게 함 */
.menu-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(5,5,5,0.55) 0%,
    rgba(5,5,5,0) 28%,
    rgba(5,5,5,0) 55%,
    rgba(5,5,5,0.85) 100%
  );
}

.hud {
  position: absolute;
  top: 26px;
  left: 26px;
  right: 26px;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  letter-spacing: 1px;
}
.hud__badge {
  background: rgba(255,255,255,0.1);
  color: var(--white);
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 5px;
  padding: 4px 8px;
  font-weight: 700;
  backdrop-filter: blur(4px);
}
.hud__badge.is-member {
  color: var(--text-main);
  background: rgba(170,170,178,0.35);
  border-color: rgba(255,255,255,0.5);
}
.hud__name {
  color: var(--text-main);
  font-weight: 500;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

/* 우하단에 작게 모여있는 메뉴 버튼 */
.menu--compact {
  position: absolute;
  right: 18px;
  bottom: 22px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 148px;
}
.menu--compact .menu__item {
  padding: 10px 12px;
  font-size: 11px;
  border-radius: 6px;
  text-align: center;
}

.menu__item {
  background: rgba(10,10,10,0.55);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  color: var(--text-main);
  font-family: var(--font-body);
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.menu__item:disabled { opacity: 0.35; cursor: not-allowed; }
.menu__item:not(:disabled):hover { border-color: var(--white); }
.menu__item--main {
  color: var(--ink);
  background: linear-gradient(90deg, var(--gray), var(--white));
  border-color: transparent;
  box-shadow: 0 0 20px rgba(170,170,178,0.4);
}
.menu__item--danger { color: var(--white); border-color: #2a2a2a; }
.menu__item--danger:hover { border-color: var(--white); }

/* ---------- 전체 화면형 패널 (스테이지 선택 / 게임) ---------- */
.panel--full {
  padding: 22px 0 16px;
  justify-content: flex-start;
}

/* ---------- 스테이지 선택 화면 ---------- */
.stage-list__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 8px;
}
.stage-list__title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-main);
}

.stage-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-auto-rows: min-content;
  gap: 10px;
  padding: 10px 20px;
  align-content: start;
}

.stage-btn {
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #0a0a0a;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.stage-btn:not(:disabled):hover { border-color: var(--white); }
.stage-btn.is-cleared {
  background: linear-gradient(135deg, var(--gray), var(--white));
  color: var(--ink);
  border-color: transparent;
  box-shadow: 0 0 12px rgba(170,170,178,0.4);
}
.stage-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.stage-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding-top: 10px;
}
.pager-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-main);
  border-radius: 6px;
  width: 34px;
  height: 34px;
  cursor: pointer;
}
.pager-btn:hover { border-color: var(--white); }
.pager-label {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

/* ---------- 게임 화면 (체스 레인저 보드) ---------- */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px 10px;
}
.game-header__label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-main);
}

.board {
  position: relative;
  margin: 12px auto 0;
  width: min(320px, 88%);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: visible;
}
.board__cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.board__cell--dark  { background: #0d0d0d; }
.board__cell--light { background: #1c1c1c; }
.board__cell img {
  width: 76%;
  height: 76%;
  object-fit: contain;
  pointer-events: none; /* 클릭 판정은 항상 칸(.board__cell) 기준 */
  transform: scale(1.5); /* 투명 여백 때문에 작아 보이는 걸 보정 - 시각적으로만 확대 */
  position: relative;
  z-index: 2;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.7));
}
.board__cell.is-selected {
  box-shadow: inset 0 0 0 3px var(--white);
}
.board__cell.is-target {
  box-shadow: inset 0 0 0 3px rgba(61,220,120,0.9);
}

/* ---------- 클리어 / 막힘 모달 ---------- */
.game-modal {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5,5,5,0.72);
  backdrop-filter: blur(3px);
}
.game-modal.is-visible { display: flex; }
.game-modal__box {
  width: 82%;
  max-width: 280px;
  background: var(--device-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 26px 20px;
  text-align: center;
}
.game-modal__title {
  font-size: 18px;
  font-weight: 900;
  margin: 0 0 8px;
  background: linear-gradient(90deg, var(--gray), var(--white));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.game-modal__desc {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 20px;
}
.game-modal__actions {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

/* ---------- 튜토리얼 안내 말풍선 (보드 위) ---------- */
.tutorial-hint {
  display: none;
  margin: 4px 18px 0;
  background: rgba(10,10,10,0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
}
.tutorial-hint.is-visible { display: block; }
.tutorial-hint__text {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-main);
}
.tutorial-hint__tap {
  display: block;
  margin-top: 6px;
  font-size: 10px;
  color: var(--text-dim);
  text-align: right;
}

/* ---------- 스토리 모드: 에피소드 선택 ---------- */
.episode-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 20px;
}
.episode-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  background: #0a0a0a;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color .15s;
}
.episode-btn:hover { border-color: var(--white); }
.episode-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.episode-btn:disabled:hover { border-color: var(--line); }
.episode-btn__title {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
  color: var(--text-main);
}
.episode-btn__desc {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ---------- 스토리 플레이어 (미연시 화면) ---------- */
.story-player { padding: 0; overflow: hidden; }

.story-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity .6s ease;
  z-index: 1;
}
.story-bg.is-visible { opacity: 1; }

.story-standing {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  height: 100%;
  width: auto;
  max-width: none;
  object-fit: contain;
  object-position: bottom;
  opacity: 0;
  transition: opacity .5s ease;
  z-index: 2;
  pointer-events: none;
}
.story-standing.is-visible { opacity: 1; }

.story-exit-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 4;
  background: rgba(6,6,6,0.6);
  border-radius: 6px;
  padding: 6px 10px;
}

.dialogue-box {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 4;
  height: 168px;
  box-sizing: border-box;
  background: rgba(6,6,6,0.88);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px 20px;
  backdrop-filter: blur(4px);
  cursor: pointer;
  overflow-y: auto;
}
.dialogue-box__speaker {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--white);
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.dialogue-box__text {
  margin: 0;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-main);
  white-space: pre-wrap;
}
.dialogue-box__next {
  position: absolute;
  right: 16px;
  bottom: 12px;
  font-size: 12px;
  color: var(--text-dim);
  animation: dialogue-bounce 1.2s ease-in-out infinite;
}
@keyframes dialogue-bounce {
  0%, 100% { transform: translateY(0); opacity: 0.6; }
  50% { transform: translateY(3px); opacity: 1; }
}

/* 지휘관(주인공)이 말할 때 — 반투명 화이트/그레이로 구분 */
.dialogue-box--player {
  background: rgba(238,238,235,0.62);
  border-color: rgba(255,255,255,0.3);
}
.dialogue-box--player .dialogue-box__speaker { color: #161616; }
.dialogue-box--player .dialogue-box__text { color: #161616; }
.dialogue-box--player .dialogue-box__next { color: rgba(22,22,22,0.6); }

.choice-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5,5,5,0.55);
  backdrop-filter: blur(2px);
}
.choice-overlay.is-visible { display: flex; }
.choice-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 80%;
}
.choice-btn {
  background: rgba(10,10,10,0.92);
  border: 1px solid var(--line);
  color: var(--text-main);
  border-radius: 8px;
  padding: 13px 16px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s;
}
.choice-btn:hover { border-color: var(--white); }

/* ---------- 설정 화면 ---------- */
.settings-block {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.settings-row__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}
.settings-row__value {
  font-size: 12px;
  color: var(--text-main);
  min-width: 26px;
  text-align: right;
}

.settings-toggle {
  border: 1px solid var(--line);
  background: rgba(170,170,178,0.15);
  color: var(--white);
  border-radius: 20px;
  padding: 6px 16px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 1px;
  cursor: pointer;
}
.settings-toggle.is-off {
  background: transparent;
  color: var(--text-dim);
}

.settings-row--slider { gap: 10px; }
.settings-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  outline: none;
}
.settings-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gray), var(--white));
  box-shadow: 0 0 8px rgba(170,170,178,0.5);
  cursor: pointer;
}
.settings-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gray), var(--white));
  box-shadow: 0 0 8px rgba(170,170,178,0.5);
  cursor: pointer;
}
