:root {
  --ink: #2b1a1d;
  --ink-soft: #6e484f;
  --paper-outer: #dfb7b6;
  --paper-card: #fcf0f2;
  --paper-sub: #f3dce0;
  --plaque-red: #b54e5e;
  --plaque-wood: #683540;
  --accent-gold: #f2bac4;
  --accent-rose: #b54e5e;
  --font-main: "DOSMyungjo", "Batang", "AppleMyungjo", Georgia, serif;
  --font-pixel: "Galmuri11Bold", "DOSMyungjo", monospace;
  font-family: var(--font-main);
  -webkit-font-smoothing: none;
  font-smooth: never;
}

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

[hidden] {
  display: none !important;
}

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(38, 27, 24, 0.38) transparent;
}
*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: rgba(38, 27, 24, 0.38);
  border-radius: 0;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background-color: var(--paper-outer);
  background-image:
    radial-gradient(rgba(38, 27, 24, 0.08) 1px, transparent 0),
    radial-gradient(rgba(255, 250, 240, 0.22) 1px, transparent 0);
  background-size: 6px 6px;
  background-position: 0 0, 3px 3px;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

input {
  user-select: text;
  -webkit-user-select: text;
}

.app-wrap {
  width: 100%;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.game-box {
  position: relative;
  height: min(820px, calc(100dvh - 28px));
  aspect-ratio: 9 / 16;
  background: #f2d6d6 url("assets/bg_stage.webp") no-repeat 0 100% / 100% 93%;
  border: 3px solid var(--ink);
  border-radius: 0;
  overflow: hidden;
  box-shadow:
    inset 0 0 0 1px #ddaeb2,
    -7px 7px 0 rgba(36, 16, 20, 0.34);
  touch-action: none;
  container-type: size;
}

#stage-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* =========================================================================
   상단 통합 무대 헤더 바 (앤틱 도트 프레임 몰딩 바)
   ========================================================================= */
.top-stage-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 25;
  height: 12.6cqw;
  min-height: 40px;
  padding: 0 3cqw;
  background-color: #f3d8da;
  background-image: repeating-linear-gradient(
    180deg,
    rgba(255, 248, 249, 0.5) 0px,
    rgba(255, 248, 249, 0.5) 2px,
    transparent 2px,
    transparent 4px
  );
  border-bottom: 2.5px solid var(--ink);
  box-shadow: inset 0 -2px 0 #d6abaf, inset 0 2px 0 #fef5f6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2cqw;
}

.top-stage-bar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -4.5px;
  height: 2px;
  background: rgba(36, 15, 19, 0.24);
  pointer-events: none;
}

.top-left-slot {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1 1 auto;
}

.user-chip-btn {
  max-width: 100%;
  padding: 1.1cqw 2.8cqw;
  border-radius: 0;
  border: 2px solid var(--ink);
  background: #fef5f6;
  box-shadow: inset 0 0 0 1px #e2bcc0, -2px 2px 0 rgba(36, 16, 20, 0.34);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: clamp(10px, 2.75cqw, 12.5px);
  font-weight: 700;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: transform 0.08s steps(2, end), background-color 0.1s ease, box-shadow 0.08s steps(2, end);
}

.user-chip-btn:hover {
  background: #fffafb;
  transform: translate(1px, -1px);
  box-shadow: inset 0 0 0 1px #eac6ca, -3px 3px 0 rgba(36, 16, 20, 0.38);
}

.user-chip-btn:active {
  transform: translate(-1.5px, 1.5px);
  box-shadow: inset 0 0 0 1px #e2bcc0, 0 0 0 rgba(36, 16, 20, 0.3);
}

.hud-lives-row {
  display: flex;
  align-items: center;
  gap: 0.8cqw;
}

.hud-life-icon {
  width: 6.8cqw;
  height: 6.8cqw;
  min-width: 20px;
  min-height: 20px;
  object-fit: contain;
  transition: opacity 0.15s steps(2, end), transform 0.15s steps(2, end);
}

.hud-life-icon.lost {
  opacity: 0.2;
  transform: scale(0.86);
}

.hud-stats-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2cqw;
  padding: 0.9cqw 2.8cqw;
  border-radius: 0;
  background: #fef5f6;
  border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 1px #e2bcc0, -2px 2px 0 rgba(36, 16, 20, 0.3);
  flex-shrink: 0;
}

.hud-time {
  font-family: var(--font-pixel);
  font-size: clamp(10px, 2.9cqw, 12.5px);
  font-weight: 700;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.hud-divider {
  width: 2px;
  height: 3cqw;
  min-height: 10px;
  background: #d5abaf;
}

.hud-score {
  font-family: var(--font-pixel);
  font-size: clamp(11.5px, 3.4cqw, 15px);
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  min-width: 7cqw;
  text-align: right;
}

.hud-buttons {
  display: flex;
  align-items: center;
  gap: 1.4cqw;
  flex-shrink: 0;
}

.circle-icon-btn {
  position: relative;
  width: 7.4cqw;
  height: 7.4cqw;
  min-width: 24px;
  min-height: 24px;
  border-radius: 0;
  border: 2px solid var(--ink);
  background: #fef5f6;
  box-shadow: inset 0 0 0 1px #e2bcc0, -2px 2px 0 rgba(36, 16, 20, 0.34);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: clamp(11px, 3.2cqw, 14px);
  font-weight: 700;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s steps(2, end), background-color 0.1s ease, box-shadow 0.08s steps(2, end);
}

.circle-icon-btn:hover {
  background: #fffafb;
  transform: translate(1px, -1px);
  box-shadow: inset 0 0 0 1px #eac6ca, -3px 3px 0 rgba(36, 16, 20, 0.38);
}

.circle-icon-btn:active {
  transform: translate(-1.5px, 1.5px);
  box-shadow: inset 0 0 0 1px #e2bcc0, 0 0 0 rgba(36, 16, 20, 0.3);
}

#btn-sound[aria-pressed="false"] {
  background: var(--paper-sub);
  color: var(--ink-soft);
}
#btn-sound[aria-pressed="false"]::after {
  content: "";
  position: absolute;
  width: 66%;
  height: 2px;
  background: var(--accent-rose);
  transform: rotate(-42deg);
}

/* =========================================================================
   1. 오픈형 시작 화면 (픽셀 + 고풍 무대 타이틀)
   ========================================================================= */
.title-screen {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 15.2cqh 6cqw 5.8cqh;
}

.title-center-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin: auto 0;
  width: 100%;
}

.logo-placeholder {
  width: 74%;
  height: 11.5cqh;
  min-height: 56px;
  max-height: 96px;
  margin-bottom: 2cqh;
  border: 2px dashed #8f7e6e;
  border-radius: 0;
  background: rgba(245, 237, 225, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6e5c4e;
  font-size: clamp(12px, 3.3cqw, 14.5px);
}

.logo-placeholder.has-logo {
  width: 84%;
  height: auto;
  min-height: 0;
  max-height: 21cqh;
  margin-bottom: 1.2cqh;
  border: 0;
  background: transparent;
}

.brand-logo-img {
  width: 100%;
  max-width: 100%;
  max-height: 21cqh;
  object-fit: contain;
}

.title-hero-img {
  width: clamp(102px, 33cqw, 148px);
  height: clamp(102px, 33cqw, 148px);
  object-fit: contain;
  margin-bottom: 1.2cqh;
  filter: drop-shadow(-3px 4px 0 rgba(28, 17, 14, 0.2));
  animation: heroFloat 1.8s steps(4, end) infinite;
}

@keyframes heroFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.main-desc {
  margin: 0;
  padding: 1.2cqw 3.2cqw;
  background: rgba(254, 242, 244, 0.9);
  border: 1.5px solid rgba(110, 56, 66, 0.5);
  box-shadow: inset 0 0 0 1px rgba(255, 250, 251, 0.82);
  font-size: clamp(12px, 3.25cqw, 14.5px);
  line-height: 1.54;
  color: var(--ink);
  word-break: keep-all;
}

.title-bottom-dock {
  width: 100%;
  background: transparent;
  border: 0;
  padding: 0;
  box-shadow: none;
  text-align: center;
}

.simple-rules {
  display: inline-block;
  margin: 0 auto 2cqw;
  padding: 0.7cqw 2.8cqw;
  background: rgba(88, 39, 48, 0.88);
  border: 1.5px solid #f2c8ce;
  color: #fff5f6;
  font-family: var(--font-pixel);
  font-size: clamp(10px, 2.65cqw, 11.8px);
  letter-spacing: 0.02em;
  box-shadow: -2px 2px 0 rgba(28, 10, 14, 0.44);
}

#btn-start-game.has-play-img {
  width: 92%;
  margin: 0 auto;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(-4px 4px 0 rgba(18, 10, 9, 0.52));
  transition: transform 0.08s steps(2, end), filter 0.1s ease;
}

#btn-start-game.has-play-img:hover {
  transform: translate(1px, -2px);
  filter: brightness(1.09) saturate(1.04) drop-shadow(-5px 6px 0 rgba(18, 10, 9, 0.58));
}

#btn-start-game.has-play-img:active {
  transform: translate(-2.5px, 2.5px);
  box-shadow: none;
  filter: brightness(0.95) drop-shadow(-1px 1px 0 rgba(18, 10, 9, 0.52));
}

.start-btn-img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  image-rendering: pixelated;
}

.title-bottom-dock .btn-pair {
  width: 92%;
  margin: 2.3cqw auto 0;
  gap: 2.4cqw;
}

.title-bottom-dock .btn-line {
  border: 2px solid #2b1a1d;
  border-radius: 0;
  padding: clamp(8.5px, 2.45cqw, 11px) 6px;
  background-color: var(--plaque-wood);
  background-image: repeating-linear-gradient(
    180deg,
    rgba(32, 12, 16, 0.28) 0px,
    rgba(32, 12, 16, 0.28) 2px,
    transparent 2px,
    transparent 4px
  );
  color: #fff5f6;
  font-family: var(--font-pixel);
  font-size: clamp(11.5px, 3.1cqw, 13.5px);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-shadow: 0 1px 0 rgba(26, 8, 12, 0.8);
  box-shadow:
    inset 0 2px 0 #f4cfd4,
    inset 0 -2px 0 #a9889e,
    inset 2px 0 0 #ebd5d8,
    inset -2px 0 0 #a9889e,
    inset 0 0 0 3.5px #381e24,
    -4px 4px 0 rgba(28, 10, 14, 0.52);
  transition: transform 0.08s steps(2, end), background-color 0.1s ease, box-shadow 0.08s steps(2, end);
}

.title-bottom-dock .btn-line:hover {
  background-color: #7d414e;
  transform: translate(1px, -2px);
  box-shadow:
    inset 0 2px 0 #fae0e4,
    inset 0 -2px 0 #b896ad,
    inset 2px 0 0 #f3dfe2,
    inset -2px 0 0 #b896ad,
    inset 0 0 0 3.5px #381e24,
    -5px 6px 0 rgba(28, 10, 14, 0.58);
}

.title-bottom-dock .btn-line:active {
  transform: translate(-2.5px, 2.5px);
  background-color: #582b35;
  box-shadow:
    inset 0 2px 0 #f4cfd4,
    inset 0 -2px 0 #a9889e,
    inset 2px 0 0 #ebd5d8,
    inset -2px 0 0 #a9889e,
    inset 0 0 0 3.5px #381e24,
    -1px 1px 0 rgba(28, 10, 14, 0.52);
}

/* =========================================================================
   2. 오버레이 공통 (일시정지 & 결과 화면 — 고풍 도트 창 프레임)
   ========================================================================= */
.overlay-layer {
  position: absolute;
  inset: 0;
  z-index: 28;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3.5cqw;
  background: rgba(32, 14, 18, 0.58);
}

.panel-card {
  width: 92%;
  max-height: 94%;
  overflow-y: auto;
  background-color: var(--paper-card);
  background-image: radial-gradient(rgba(110, 56, 66, 0.05) 1px, transparent 0);
  background-size: 4px 4px;
  border: 2.5px solid var(--ink);
  border-radius: 0;
  padding: 4.6cqw 4.4cqw;
  text-align: center;
  box-shadow:
    inset 0 0 0 2px #fff8f9,
    inset 0 0 0 4px #d8a9b0,
    -5px 5px 0 rgba(28, 10, 14, 0.54);
}

.sub-title {
  margin: 0 0 1.5cqw;
  font-size: clamp(18px, 5.2cqw, 22px);
  font-weight: 700;
}

.pause-desc {
  margin: 0 0 4cqw;
  font-size: clamp(12px, 3.2cqw, 14px);
  color: var(--ink-soft);
}

.btn-solid {
  width: 100%;
  border: 2px solid #2b1a1d;
  border-radius: 0;
  padding: clamp(9px, 2.6cqw, 11.5px) 12px;
  background-color: var(--plaque-red);
  background-image: repeating-linear-gradient(
    180deg,
    rgba(64, 20, 28, 0.24) 0px,
    rgba(64, 20, 28, 0.24) 2px,
    transparent 2px,
    transparent 4px
  );
  color: #fff7f8;
  font-family: var(--font-pixel);
  font-size: clamp(12.5px, 3.4cqw, 14.5px);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 0 rgba(44, 12, 18, 0.7);
  box-shadow:
    inset 0 2px 0 #f7d6db,
    inset 0 -2px 0 #a9889e,
    inset 2px 0 0 #efd0d5,
    inset -2px 0 0 #a9889e,
    inset 0 0 0 3.5px #422027,
    -4px 4px 0 rgba(32, 12, 16, 0.48);
  transition: transform 0.08s steps(2, end), background-color 0.1s ease, box-shadow 0.08s steps(2, end);
}

.btn-solid:hover {
  background-color: #c45b6c;
  transform: translate(1px, -1.5px);
  box-shadow:
    inset 0 2px 0 #fce4e8,
    inset 0 -2px 0 #b896ad,
    inset 2px 0 0 #f5dce0,
    inset -2px 0 0 #b896ad,
    inset 0 0 0 3.5px #422027,
    -5px 5.5px 0 rgba(32, 12, 16, 0.54);
}

.btn-solid:active {
  transform: translate(-2px, 2px);
  background-color: #9e4150;
  box-shadow:
    inset 0 2px 0 #f7d6db,
    inset 0 -2px 0 #a9889e,
    inset 2px 0 0 #efd0d5,
    inset -2px 0 0 #a9889e,
    inset 0 0 0 3.5px #422027,
    -1px 1px 0 rgba(32, 12, 16, 0.48);
}

.btn-pair {
  display: flex;
  gap: 2cqw;
  margin-top: 2cqw;
}

.btn-pair > button {
  flex: 1 1 0;
  min-width: 0;
}

.btn-line {
  border: 2px solid var(--ink);
  border-radius: 0;
  padding: clamp(7.5px, 2.1cqw, 9.5px) 6px;
  background: linear-gradient(180deg, #fff9fa 0%, #f3dce0 100%);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: clamp(11px, 2.95cqw, 13px);
  font-weight: 700;
  box-shadow: inset 0 1.5px 0 #ffffff, inset 0 -1.5px 0 #dcaeb5, -3px 3px 0 rgba(32, 12, 16, 0.34);
  transition: transform 0.08s steps(2, end), background 0.1s ease, box-shadow 0.08s steps(2, end);
}

.btn-line:hover {
  background: linear-gradient(180deg, #ffffff 0%, #f8e6e9 100%);
  transform: translate(1px, -1px);
  box-shadow: inset 0 1.5px 0 #ffffff, inset 0 -1.5px 0 #dcaeb5, -4px 4px 0 rgba(32, 12, 16, 0.4);
}

.btn-line:active {
  transform: translate(-1.5px, 1.5px);
  box-shadow: inset 0 1.5px 0 #ffffff, inset 0 -1.5px 0 #dcaeb5, -1px 1px 0 rgba(32, 12, 16, 0.34);
}

/* =========================================================================
   3. 결과 화면
   ========================================================================= */
.result-card {
  padding: 4.8cqw 4.4cqw 4.2cqw;
}

.result-top-tags {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5cqw;
  margin-bottom: 1.8cqw;
}

.record-label {
  display: inline-block;
  font-family: var(--font-pixel);
  font-size: clamp(10px, 2.55cqw, 11.5px);
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 0;
  background: var(--accent-gold);
  border: 2px solid var(--ink);
  box-shadow: -2px 2px 0 rgba(24, 15, 13, 0.32);
  color: var(--ink);
}

.unlock-label {
  display: inline-block;
  font-family: var(--font-pixel);
  font-size: clamp(10px, 2.55cqw, 11.5px);
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 0;
  background: var(--plaque-red);
  border: 2px solid var(--ink);
  box-shadow: -2px 2px 0 rgba(24, 15, 13, 0.32);
  color: #fff7f8;
  animation: pulseUnlock 1.4s infinite alternate ease-in-out;
}

@keyframes pulseUnlock {
  0% { transform: scale(1); }
  100% { transform: scale(1.06); }
}

.result-char-frame {
  width: clamp(86px, 27.5cqw, 122px);
  height: clamp(86px, 27.5cqw, 122px);
  margin: 0.4cqw auto 2.2cqw;
  border-radius: 0;
  background: var(--role-tint, #ece2d4);
  border: 2px solid #26201f;
  box-shadow:
    inset 0 2px 0 #dfd9cf,
    inset 0 -2px 0 #95a0bc,
    inset 2px 0 0 #d5cec4,
    inset -2px 0 0 #95a0bc,
    inset 0 0 0 3.5px #362523,
    -3.5px 3.5px 0 rgba(22, 13, 11, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-char-img {
  width: 88%;
  height: 88%;
  object-fit: contain;
}

.result-name {
  margin: 0 0 1.4cqw;
  font-size: clamp(17.5px, 5cqw, 22px);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.result-copy {
  margin: 0 0 2.4cqw;
  padding: 2cqw 2.4cqw;
  background: rgba(255, 248, 249, 0.86);
  border: 1px dashed #d49fa7;
  font-size: clamp(11px, 2.85cqw, 12.8px);
  line-height: 1.54;
  color: var(--ink);
  white-space: pre-line;
  word-break: keep-all;
}

.score-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: #fff8f9;
  border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 1px #eac6cc;
  border-radius: 0;
  padding: 1.5cqw 2cqw;
  margin-bottom: 1.6cqw;
}

.score-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.score-cell span {
  font-size: clamp(10px, 2.45cqw, 11px);
  color: var(--ink-soft);
}

.score-cell strong {
  font-family: var(--font-pixel);
  font-size: clamp(14px, 3.9cqw, 17px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-sep {
  width: 2px;
  height: 22px;
  background: #dfb2b9;
}

.tally-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.2cqw;
  margin-bottom: 1.8cqw;
}

.tally-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1cqw 2px;
  border-radius: 0;
  background: var(--paper-sub);
  border: 1.5px solid #d7a6ae;
}

.tally-item.top-role {
  background: #fff8f9;
  border: 2px solid var(--ink);
  box-shadow: -2px 2px 0 rgba(32, 12, 16, 0.28);
}

.tally-item span {
  font-size: clamp(9.5px, 2.35cqw, 10.5px);
  color: var(--ink-soft);
}

.tally-item strong {
  font-family: var(--font-pixel);
  font-size: clamp(10.5px, 2.75cqw, 12px);
  color: var(--ink);
}

.rank-notice-box {
  background: var(--paper-sub);
  border: 1.5px solid #d49fa7;
  border-radius: 0;
  padding: 1.6cqw 2.2cqw;
  margin-bottom: 2cqw;
  font-size: clamp(10.5px, 2.7cqw, 11.8px);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 1.3cqw;
}

.save-score-btn {
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--accent-gold);
  box-shadow: inset 0 1.5px 0 #fde4e8, -2px 2px 0 rgba(32, 12, 16, 0.34);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: clamp(10.5px, 2.7cqw, 11.8px);
  font-weight: 700;
  padding: 5px 8px;
  width: 100%;
  transition: transform 0.08s steps(2, end), background-color 0.1s ease, box-shadow 0.08s steps(2, end);
}

.save-score-btn:hover {
  background: #f7c7d0;
  transform: translate(1px, -1px);
  box-shadow: inset 0 1.5px 0 #fff0f3, -3px 3px 0 rgba(32, 12, 16, 0.38);
}

.save-score-btn:active {
  transform: translate(-1.5px, 1.5px);
  box-shadow: inset 0 1.5px 0 #fde4e8, 0 0 0 rgba(32, 12, 16, 0.32);
}

/* =========================================================================
   4. 모달 공통 (인증 / 랭킹 / 게임 방법)
   ========================================================================= */
.modal-dim {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(32, 14, 18, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3.5cqw;
}

.modal-box {
  position: relative;
  width: 93%;
  max-height: 92%;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: var(--paper-card);
  background-image: radial-gradient(rgba(110, 56, 66, 0.05) 1px, transparent 0);
  background-size: 4px 4px;
  border: 2.5px solid var(--ink);
  border-radius: 0;
  padding: 4.4cqw 4cqw 4cqw;
  box-shadow:
    inset 0 0 0 2px #fff8f9,
    inset 0 0 0 4px #d8a9b0,
    -5px 5px 0 rgba(28, 10, 14, 0.54);
}

.close-x {
  position: absolute;
  top: 4cqw;
  right: 4cqw;
  width: 28px;
  height: 28px;
  border-radius: 0;
  border: 2px solid var(--ink);
  background: #fff8f9;
  box-shadow: inset 0 0 0 1px #e5bfc5, -2px 2px 0 rgba(32, 12, 16, 0.32);
  font-family: var(--font-pixel);
  font-size: 16px;
  line-height: 1;
  font-weight: 700;
  color: var(--ink);
  transition: transform 0.08s steps(2, end), background-color 0.1s ease, box-shadow 0.08s steps(2, end);
}

.close-x:hover {
  background: #ffffff;
  transform: translate(1px, -1px);
  box-shadow: inset 0 0 0 1px #eed0d5, -3px 3px 0 rgba(32, 12, 16, 0.38);
}

.close-x:active {
  transform: translate(-1.5px, 1.5px);
  box-shadow: inset 0 0 0 1px #e5bfc5, 0 0 0 rgba(32, 12, 16, 0.28);
}

.modal-heading {
  margin: 0 0 1.4cqw;
  font-size: clamp(16.5px, 4.5cqw, 19.5px);
  font-weight: 700;
}

.modal-subcopy {
  margin: 0 0 2.6cqw;
  font-size: clamp(11px, 2.85cqw, 12.4px);
  line-height: 1.52;
  color: var(--ink-soft);
  word-break: keep-all;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 2.4cqw;
}

.input-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  font-size: 12px;
}

.input-label input {
  width: 100%;
  padding: 9px 10px;
  border-radius: 0;
  border: 2px solid var(--ink);
  background: #fff8f9;
  font-size: 14.5px;
  color: var(--ink);
}

.input-label input:focus {
  outline: none;
  background: #ffffff;
  box-shadow: inset 0 0 0 2px rgba(181, 78, 94, 0.32);
}

.error-text {
  margin: 0;
  padding: 7px 9px;
  border-radius: 0;
  background: #fbe4e8;
  border: 1.5px solid var(--accent-rose);
  color: #84232c;
  font-size: 12px;
  text-align: center;
}

.logged-bar {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1.5px dashed #d49fa7;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.logout-btn {
  border: 0;
  background: none;
  color: var(--accent-rose);
  font-family: var(--font-pixel);
  font-size: 11.5px;
  font-weight: 700;
  text-decoration: underline;
}

/* 랭킹 보드 */
.ranking-modal-box {
  display: flex;
  flex-direction: column;
  height: 84%;
  max-height: 660px;
  overflow: hidden;
}

.ranking-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 38px;
}

.refresh-btn {
  border: 2px solid var(--ink);
  background: linear-gradient(180deg, #fff9fa 0%, #f3dce0 100%);
  box-shadow: inset 0 1px 0 #ffffff, -2px 2px 0 rgba(32, 12, 16, 0.32);
  border-radius: 0;
  padding: 3px 8px;
  font-family: var(--font-pixel);
  font-size: 10.5px;
  font-weight: 700;
  transition: transform 0.08s steps(2, end), background 0.1s ease, box-shadow 0.08s steps(2, end);
}

.refresh-btn:hover {
  background: linear-gradient(180deg, #ffffff 0%, #f8e6e9 100%);
  transform: translate(1px, -1px);
  box-shadow: inset 0 1px 0 #ffffff, -3px 3px 0 rgba(32, 12, 16, 0.36);
}

.refresh-btn:active {
  transform: translate(-1.5px, 1.5px);
  box-shadow: inset 0 1px 0 #ffffff, 0 0 0 rgba(32, 12, 16, 0.28);
}

.ranking-count {
  margin: 3px 0 8px;
  font-size: 11.5px;
  color: var(--ink-soft);
}

.ranking-scroll {
  flex: 1;
  overflow-y: auto;
  background: #ebd0d5;
  border: 2px solid var(--ink);
  box-shadow: inset 0 2px 0 rgba(36, 16, 20, 0.14);
  border-radius: 0;
  padding: 7px;
}

.ranking-ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rank-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border-radius: 0;
  background: #fff8f9;
  border: 1.5px solid #d6a4ac;
  box-shadow: -2px 2px 0 rgba(36, 16, 20, 0.18);
}

.rank-row.rank-1 {
  background: linear-gradient(90deg, #fbdbe1 0%, #fff8f9 100%);
  border-color: #b54e5e;
  box-shadow: inset 0 0 0 1px #fef0f3, -2px 2px 0 rgba(36, 16, 20, 0.26);
}

.rank-row.is-me {
  border: 2px solid var(--plaque-red);
}

.rank-no {
  width: 24px;
  text-align: center;
  font-family: var(--font-pixel);
  font-size: 12.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.rank-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.rank-name-line {
  display: flex;
  align-items: center;
  gap: 5px;
}

.rank-nick {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.my-tag {
  font-family: var(--font-pixel);
  font-size: 9.5px;
  font-weight: 700;
  background: var(--plaque-red);
  color: #fff;
  padding: 1px 4px;
  border-radius: 0;
  flex-shrink: 0;
}

/* 닉네임과 점수 사이 엔딩 캐릭터 아이콘 슬롯 */
.rank-char-badge {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  background: var(--role-tint, #f3dce0);
  border: 1.5px solid var(--ink);
  box-shadow: inset 0 0 0 1px rgba(255, 250, 251, 0.65), -1.5px 1.5px 0 rgba(36, 16, 20, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
}

.rank-char-icon {
  width: 25px;
  height: 25px;
  object-fit: contain;
  display: block;
}

.rank-pt {
  min-width: 62px;
  text-align: right;
  font-family: var(--font-pixel);
  font-size: 12.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.rank-empty {
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
  padding: 20px 0;
}

.my-rank-footer {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 0;
  background-color: var(--plaque-wood);
  background-image: repeating-linear-gradient(
    180deg,
    rgba(32, 10, 14, 0.26) 0px,
    rgba(32, 10, 14, 0.26) 2px,
    transparent 2px,
    transparent 4px
  );
  border: 2px solid #2b1a1d;
  box-shadow: inset 0 1.5px 0 #e8bec5, inset 0 -1.5px 0 #9e7f93;
  color: #fff5f6;
  font-size: 11.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.footer-reg-btn {
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--accent-gold);
  box-shadow: inset 0 1px 0 #fde4e8, -1.5px 1.5px 0 rgba(24, 8, 12, 0.48);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: 10.5px;
  font-weight: 700;
  padding: 4px 9px;
  transition: transform 0.08s steps(2, end), background-color 0.1s ease, box-shadow 0.08s steps(2, end);
}

.footer-reg-btn:hover {
  background: #f7c7d0;
  transform: translate(1px, -1px);
}

.footer-reg-btn:active {
  transform: translate(-1px, 1px);
  box-shadow: inset 0 1px 0 #fde4e8, 0 0 0 rgba(24, 8, 12, 0.45);
}

/* 게임 방법 도감 */
.guide-modal-box {
  overflow-y: auto;
}

.guide-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.6cqw;
  margin-bottom: 1.8cqw;
}

.guide-card {
  background: #fff8f9;
  border: 1.5px solid #d6a4ac;
  box-shadow: -2px 2px 0 rgba(32, 12, 16, 0.14);
  border-radius: 0;
  padding: 1.6cqw;
  text-align: center;
}

.guide-card-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-bottom: 1.2cqw;
}

.guide-sd {
  width: clamp(26px, 7.8cqw, 34px);
  height: clamp(26px, 7.8cqw, 34px);
  object-fit: contain;
}

.guide-role-title {
  font-size: clamp(12px, 3.1cqw, 13.5px);
  font-weight: 700;
}

.guide-props {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  background: var(--paper-sub);
  border: 1px solid #e0b6bd;
  border-radius: 0;
  padding: 1.1cqw 3px;
}

.guide-prop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: clamp(9px, 2.25cqw, 10px);
  line-height: 1.25;
  word-break: keep-all;
}

.guide-prop img {
  width: clamp(22px, 6cqw, 27px);
  height: clamp(22px, 6cqw, 27px);
  object-fit: contain;
}

.danger-guide-row {
  display: flex;
  align-items: center;
  gap: 2.4cqw;
  background: #fae2e6;
  border: 1.5px solid #cf8b96;
  box-shadow: -2px 2px 0 rgba(32, 12, 16, 0.14);
  border-radius: 0;
  padding: 1.8cqw 2.2cqw;
  text-align: left;
}

.danger-thumb {
  width: clamp(32px, 9cqw, 40px);
  height: clamp(32px, 9cqw, 40px);
  object-fit: contain;
  flex-shrink: 0;
  background: #fff8f9;
  border-radius: 0;
  padding: 3px;
  border: 1.5px solid #cf8b96;
}

.danger-text strong {
  display: block;
  font-size: clamp(11.5px, 3cqw, 13px);
  color: #84232c;
  margin-bottom: 2px;
}

.danger-text p {
  margin: 0;
  font-size: clamp(10px, 2.6cqw, 11.2px);
  line-height: 1.44;
  color: var(--ink);
  word-break: keep-all;
}
/* =========================================================================
   8. 엔딩 도감 모달 & 카드 상세 뷰어
   ========================================================================= */
.gallery-modal-box {
  max-width: 92%;
  width: 92%;
  max-height: 86cqh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 4.4cqw 3.6cqw 3.6cqw;
}

.gallery-header-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  margin-bottom: 2.2cqw;
  gap: 2.2cqw;
  padding-right: 34px;
  flex-shrink: 0;
}

.gallery-header-row .modal-heading {
  margin: 0;
  text-align: left;
}

.gallery-count-badge {
  display: inline-block;
  font-family: var(--font-pixel);
  font-size: clamp(10.5px, 2.8cqw, 12.5px);
  font-weight: 700;
  color: var(--ink);
  background: var(--paper-sub);
  border: 1.5px solid #d49fa7;
  padding: 2px 9px;
}

.gallery-guest-banner {
  background: var(--paper-sub);
  border: 1.5px dashed #c48b94;
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: clamp(10.5px, 2.7cqw, 12px);
  line-height: 1.5;
  text-align: center;
  padding: 1.8cqw 2.4cqw;
  margin-top: 1.2cqw;
  margin-bottom: 2.2cqw;
  word-break: keep-all;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.gallery-guest-banner:hover {
  background: #fce4e8;
  border-color: var(--plaque-red);
}

.gallery-guest-banner:active {
  transform: translate(0, 1px);
}

.gallery-complete-banner {
  background-color: var(--plaque-red);
  color: #fff7f8;
  border: 2px solid var(--ink);
  box-shadow: -2px 2px 0 rgba(32, 12, 16, 0.3);
  font-family: var(--font-pixel);
  font-size: clamp(12px, 3.4cqw, 14.5px);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: center;
  padding: 1cqw 2cqw;
  margin-top: 2.2cqw;
  margin-bottom: 2.2cqw;
  text-shadow: 0 1px 0 rgba(44, 12, 18, 0.7);
  flex-shrink: 0;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2.2cqw;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 3px 4px 6px;
  width: 100%;
  flex: 1 1 auto;
}

.gallery-card {
  position: relative;
  width: 100%;
  min-width: 0;
  aspect-ratio: 1 / 1.12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 2.2cqw 1.6cqw 1.8cqw;
  border-radius: 0;
  box-sizing: border-box;
  text-align: center;
  overflow: hidden;
}

.gallery-card.locked {
  background: #2b2022;
  border: 1.5px dashed #6b4d52;
  cursor: default;
}

.gallery-card.locked .gallery-card-thumb {
  width: auto;
  max-width: 80%;
  height: 62%;
  max-height: 62%;
  object-fit: contain;
  filter: brightness(0) opacity(0.24);
  user-select: none;
  pointer-events: none;
  margin: auto 0 0;
}

.gallery-card.locked .locked-secret {
  margin: auto 0;
  font-family: var(--font-pixel);
  font-size: clamp(11px, 3cqw, 13px);
  font-weight: 700;
  color: #c99da3;
  letter-spacing: 0.15em;
}

.gallery-card.unlocked {
  background: #fff8f9;
  border: 2px solid var(--ink);
  box-shadow: -2px 2px 0 rgba(32, 12, 16, 0.28);
  cursor: pointer;
  transition: transform 0.08s steps(2, end), box-shadow 0.08s steps(2, end), background-color 0.1s ease;
}

.gallery-card.unlocked:hover {
  background: #ffffff;
  transform: translate(1px, -1.5px);
  box-shadow: -3px 3px 0 rgba(32, 12, 16, 0.35);
}

.gallery-card.unlocked:active {
  transform: translate(-1.5px, 1.5px);
  box-shadow: 0 0 0 rgba(32, 12, 16, 0.28);
}

.gallery-card.unlocked .gallery-card-thumb {
  width: auto;
  max-width: 82%;
  height: 64%;
  max-height: 64%;
  object-fit: contain;
  margin: auto 0 0;
  filter: drop-shadow(-1px 2px 0 rgba(28, 17, 14, 0.18));
}

.gallery-card.unlocked .gallery-card-label {
  margin: auto 0 0;
  font-family: var(--font-pixel);
  font-size: clamp(10.5px, 2.85cqw, 12.5px);
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 96%;
  display: block;
}

.card-detail-box {
  max-width: 86%;
  width: 86%;
  padding: 4.5cqw 4cqw;
  text-align: center;
  overflow-x: hidden;
}

.card-detail-frame {
  width: clamp(96px, 32cqw, 140px);
  height: clamp(96px, 32cqw, 140px);
  margin: 0 auto 2cqw;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff8f9;
  border: 2px solid var(--ink);
  box-shadow: -3px 3px 0 rgba(32, 12, 16, 0.3);
}

.card-detail-img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
}

.card-detail-title {
  margin: 0 0 1.8cqw;
  font-family: var(--font-pixel);
  font-size: clamp(14px, 4cqw, 17px);
  font-weight: 700;
  color: var(--ink);
}

.card-detail-comment {
  margin: 0;
  padding: 2.2cqw 2.4cqw;
  background: rgba(255, 248, 249, 0.86);
  border: 1px dashed #d49fa7;
  font-size: clamp(11px, 2.85cqw, 12.6px);
  line-height: 1.56;
  color: var(--ink);
  white-space: pre-line;
  word-break: keep-all;
  text-align: center;
}

@media (max-width: 600px) {
  .app-wrap {
    padding: 0;
  }
  .game-box {
    width: min(100vw, calc(100dvh * 9 / 16));
    height: min(100dvh, calc(100vw * 16 / 9));
    max-height: 100dvh;
    border-radius: 0;
    border: 0;
    box-shadow: none;
  }
}
