* {
  box-sizing: border-box;
}

:root {
  --ink: #efe7d1;
  --paper: #e8ddc3;
  --blood: #7b1d25;
  --gold: #c6a45d;
  --panel: rgba(16, 13, 16, 0.94);
  --panel2: rgba(25, 22, 28, 0.94);
  --line: #c8b783;
  --shadow: 0 22px 58px rgba(0, 0, 0, 0.62);
}

html,
body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 36%, rgba(104, 24, 30, 0.22), transparent 28%),
    radial-gradient(circle at 15% 10%, rgba(198, 164, 93, 0.08), transparent 24%),
    linear-gradient(180deg, #111015, #050506 72%);
  color: var(--ink);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", monospace;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 4px),
    radial-gradient(circle at center, transparent 42%, rgba(0, 0, 0, 0.58));
  mix-blend-mode: screen;
  opacity: 0.55;
}

#game {
  position: relative;
  width: 960px;
  height: 540px;
  overflow: hidden;
  background: #08080a;
  border: 6px solid #0b090b;
  box-shadow:
    0 0 0 3px #32252a,
    0 0 0 6px #090709,
    var(--shadow);
  image-rendering: pixelated;
  transform-origin: center center;
}

@media (orientation: landscape) and (max-height: 600px) {
  html, body { width: 100%; height: 100%; min-height: 0; overflow: hidden; }
  #help { display: none; }
}

#game::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 48%, transparent 36%, rgba(0, 0, 0, 0.46) 72%, rgba(0, 0, 0, 0.78)),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03), transparent 8%, transparent 92%, rgba(0, 0, 0, 0.32));
}

#game::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 3px);
  opacity: 0.28;
}

#gameCanvas {
  width: 960px;
  height: 540px;
  display: block;
  background: #050506;
  image-rendering: pixelated;
}

#momCallSequence {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  display: none;
  width: 100dvw;
  height: 100dvh;
  overflow: hidden;
  background: #000;
  place-items: center;
  overscroll-behavior: none;
}

#momCallSequence.show { display: grid; }

body.mom-call-active {
  overflow: hidden;
  background: #000;
}

#miniGameOverlay {
  position: fixed;
  inset: 0;
  z-index: 2147483600;
  display: none;
  width: 100dvw;
  height: 100dvh;
  overflow: hidden;
  background: #050506;
}

#miniGameOverlay.show { display: block; }

#miniGameFrame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #050506;
}

#miniGameCloseBtn {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  z-index: 2;
  min-height: 46px;
  padding: 10px 16px;
  border: 2px solid rgba(255,255,255,.8);
  border-radius: 999px;
  background: rgba(5, 5, 6, .86);
  color: #fff;
  font: 800 15px/1 "Malgun Gothic", sans-serif;
  box-shadow: 0 4px 18px rgba(0,0,0,.45);
}

#momMissingText {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.92);
  color: #fff;
  font-size: clamp(34px, 7vw, 70px);
  font-weight: 900;
  letter-spacing: 8px;
  text-shadow: 0 0 14px #b30000;
  transition: opacity .25s ease;
}

#momMissingText.hide { opacity: 0; pointer-events: none; }

#momCallScreen {
  position: relative;
  width: min(100dvw, calc(100dvh * 0.46));
  height: 100dvh;
  max-width: 100dvw;
  max-height: 100dvh;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: #000;
  cursor: pointer;
}

#momCallImage {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}

@media (orientation: portrait) {
  #momCallScreen {
    width: 100dvw;
    height: 100dvh;
  }
}

#momCallHint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 20px;
  color: white;
  background: rgba(0, 0, 0, .72);
  font: 700 14px "Malgun Gothic", sans-serif;
  white-space: nowrap;
  animation: blinkNext .9s steps(2, end) infinite;
}

#momCallSequence.call-connected #momCallHint { display: none; }
#momCallSequence.ringing { animation: phoneShake .14s linear infinite; }

@keyframes phoneShake {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-4px, 2px); }
  50% { transform: translate(4px, -2px); }
  75% { transform: translate(-2px, -3px); }
}

#fade {
  position: absolute;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  background: #000;
  opacity: 0;
  transition: opacity 0.25s ease;
}

#fade.show {
  opacity: 0.82;
}

#roomName,
#progress,
#help,
#systemMessage,
#inventory,
#missionPopup,
#pauseMenu,
#endingScreen {
  background: var(--panel);
  border: 3px solid #090909;
  box-shadow:
    inset 0 0 0 2px var(--line),
    0 8px 0 rgba(0, 0, 0, 0.36);
  color: var(--ink);
  text-shadow: 2px 2px 0 #000;
}

#roomName,
#progress,
#help,
#systemMessage {
  position: absolute;
  z-index: 8;
  padding: 8px 12px;
}

#roomName {
  top: 14px;
  left: 14px;
  min-width: 150px;
  color: #f0d48a;
  font-size: 15px;
  font-weight: 900;
}

#roomName::before {
  content: "ROOM  ";
  color: #a34a4f;
  font-size: 11px;
}

#progress {
  top: 14px;
  right: 14px;
  min-width: 188px;
}

#progress span {
  display: block;
  margin-bottom: 4px;
  color: #b8a98f;
  font-size: 11px;
  font-weight: 900;
}

#keys {
  color: #f0d48a;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1px;
}

#help {
  left: 14px;
  bottom: 14px;
  font-size: 12px;
  color: #cfc5ad;
}

#dialogBox {
  position: absolute;
  left: 42px;
  right: 42px;
  bottom: 28px;
  z-index: 30;
  pointer-events: auto;
  touch-action: manipulation;
  user-select: none;
  cursor: pointer;
  min-height: 136px;
  padding: 18px 22px 26px;
  color: var(--paper);
  background: rgba(10, 9, 11, 0.96);
  border: 4px solid #050505;
  box-shadow:
    inset 0 0 0 2px #e0cf9c,
    inset 0 0 0 6px #201920,
    0 8px 0 rgba(0, 0, 0, 0.45);
}

#dialogBox::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 14px;
  bottom: 14px;
  width: 4px;
  background: linear-gradient(#7b1d25, #c6a45d, #7b1d25);
}

#speaker {
  display: inline-block;
  margin: 0 0 10px 10px;
  padding: 4px 12px;
  color: #0b090b;
  background: #d8c082;
  border: 2px solid #100d10;
  font-size: 13px;
  font-weight: 900;
}

#dialogText {
  min-height: 44px;
  padding-left: 10px;
  line-height: 1.58;
  font-size: 18px;
  word-break: keep-all;
}

#next {
  position: absolute;
  right: 22px;
  bottom: 12px;
  color: #e2c777;
  font-size: 12px;
  font-weight: 900;
  animation: blinkNext 0.9s steps(2, end) infinite;
}

@keyframes blinkNext {
  50% { opacity: 0.25; }
}

#choiceBox {
  display: none;
}

#missionPopup,
#inventory,
#pauseMenu,
#titleScreen,
#endingScreen {
  position: absolute;
  z-index: 40;
}

#missionPopup {
  top: 76px;
  left: 50%;
  transform: translateX(-50%) translateY(-16px);
  width: 440px;
  padding: 18px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}

#missionPopup.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#missionPopup h2 {
  margin: 0 0 8px;
  color: #d8c082;
  font-size: 18px;
  letter-spacing: 4px;
}

#missionText {
  margin: 0;
  color: #eee2c6;
  line-height: 1.5;
}

#inventory {
  right: 14px;
  top: 92px;
  width: 220px;
  max-height: 296px;
  padding: 13px;
  display: none;
}

#inventory.show {
  display: block;
}

#inventory h2 {
  margin: 0 0 8px;
  color: #d8c082;
  font-size: 17px;
}

#itemList {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.65;
}

#systemMessage {
  left: 50%;
  top: 22px;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, top 0.2s ease;
}

#systemMessage.show {
  top: 56px;
  opacity: 1;
}

#titleScreen,
#pauseMenu,
#endingScreen {
  inset: 0;
  display: none;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
}

#titleScreen {
  display: grid;
  background:
    linear-gradient(rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0.72)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0 2px, transparent 2px 8px),
    radial-gradient(circle at 50% 38%, #302228, #09080a 70%);
}

#titleScreen::before {
  content: "";
  width: 86px;
  height: 92px;
  margin-bottom: 2px;
  background:
    linear-gradient(#0c0a0b, #1a1115);
  border: 5px solid #0a0709;
  box-shadow:
    inset 0 0 0 3px #6e5536,
    inset 0 -32px 0 #2b1916,
    0 14px 0 rgba(0, 0, 0, 0.38);
}

#titleScreen h1,
#endingScreen h1 {
  margin: 0;
  color: #e9d49a;
  font-size: 38px;
  letter-spacing: 2px;
  text-shadow: 4px 4px 0 #000, 0 0 18px rgba(123, 29, 37, 0.5);
}

#titleScreen h3 {
  margin: 0 0 4px;
  color: #b96c72;
  font-size: 17px;
  letter-spacing: 1px;
}

#characterSelect {
  width: min(560px, calc(100% - 44px));
  display: grid;
  gap: 8px;
}

#characterSelect h2 {
  margin: 0;
  color: #eadcb9;
  font-size: 16px;
  letter-spacing: 1px;
  text-shadow: 3px 3px 0 #000;
}

.character-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.character-card {
  min-width: 0;
  min-height: 118px;
  padding: 10px;
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 10px;
  align-items: center;
  text-align: left;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.character-preview {
  width: 54px;
  height: 72px;
  justify-self: center;
  image-rendering: pixelated;
  background: #09080a;
  border: 2px solid #3d3027;
  box-shadow: inset 0 0 0 3px #050505;
}

.boy-preview,
.girl-preview {
  background-repeat: no-repeat;
  background-size: 162px 288px;
  background-position: 0 0;
}

.boy-preview {
  background-image: url("assets/characters/boy/hyo_boy_walk.png");
}

.girl-preview {
  background-image: url("assets/characters/girl/hyo_girl_walk.png");
}

.character-card strong,
.character-card span {
  display: block;
}

.character-card strong {
  margin-bottom: 6px;
  color: #eadcb9;
  font-size: 18px;
}

.character-card span {
  color: #b8a98f;
  font-size: 15px;
  line-height: 1.45;
}

.character-card.selected {
  transform: scale(1.035);
  color: #fff4c4;
  background: #29191e;
  box-shadow:
    inset 0 0 0 2px #f0d48a,
    0 0 20px rgba(198, 164, 93, 0.28),
    0 5px 0 rgba(0, 0, 0, 0.38);
}

.character-card.selected::after {
  content: "선택됨";
  grid-column: 1 / -1;
  justify-self: end;
  color: #f0d48a;
  font-size: 12px;
}

#characterHint {
  margin: 0;
  min-height: 16px;
  color: #b8a98f;
  font-size: 12px;
}

button {
  min-width: 150px;
  padding: 10px 16px;
  color: #eadcb9;
  background: #171217;
  border: 3px solid #050505;
  box-shadow: inset 0 0 0 2px #c6a45d, 0 5px 0 rgba(0, 0, 0, 0.38);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

button:hover {
  color: #fff4c4;
  background: #28161b;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.7);
}

.mobile-controls {
  position: absolute;
  inset: 0;
  z-index: 24;
  display: none;
  pointer-events: none;
  touch-action: none;
}

#game.mobile-playing .mobile-controls { display: block; }

.move-joystick {
  position: absolute;
  left: 24px;
  bottom: 24px;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
  background: rgba(7, 7, 9, 0.68);
  border: 4px solid rgba(240, 212, 138, 0.78);
  box-shadow: inset 0 0 22px #000, 0 5px 14px #0009;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: #7b1d25;
  border: 4px solid #eadcb9;
  box-shadow: 0 4px 10px #000b;
  pointer-events: none;
}

.mobile-action {
  position: absolute;
  right: 28px;
  bottom: 36px;
  width: 132px;
  min-width: 0;
  height: 72px;
  padding: 6px;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: manipulation;
  color: #fff4c4;
  background: rgba(123, 29, 37, 0.9);
  font-size: 18px;
  box-shadow: inset 0 0 0 3px #eadcb9, 0 6px 14px #000b;
}

@media (hover: hover) and (pointer: fine) and (min-width: 981px) {
  .mobile-controls { display: none !important; }
}

#pauseMenu.show,
#endingScreen.show {
  display: grid;
}

#endingScreen {
  background: radial-gradient(circle, rgba(232, 221, 195, 0.12), rgba(0, 0, 0, 0.94) 62%);
}

#endingScreen p {
  max-width: 520px;
  margin: 0;
  color: #e6dcc8;
  font-size: 18px;
  line-height: 1.7;
}

#endingVisual {
  display: none;
  width: min(780px, 88vw);
  max-height: 62vh;
  object-fit: contain;
  image-rendering: pixelated;
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.65);
}

#endingVisual.show {
  display: block;
  animation: endingFade 0.8s ease both;
}

#endingVisual.crying-hold {
  animation: cryingHold 1.1s ease-in-out infinite;
}

@keyframes cryingHold {
  0%, 100% { filter: brightness(0.92) saturate(0.95); }
  50% { filter: brightness(1.08) saturate(1.12); }
}

@keyframes endingFade {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.ending-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 22px;
}

.ending-actions .secondary {
  color: #f5e9d2;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.35);
}

@media (max-width: 980px) {
  #game {
    width: 960px;
    height: 540px;
    max-width: none;
    max-height: none;
    border-width: 6px;
  }

  #gameCanvas {
    width: 960px;
    height: 540px;
  }

  #dialogBox {
    left: 18px;
    right: 18px;
    bottom: 16px;
    min-height: 118px;
  }

  #titleScreen h1 {
    font-size: 28px;
  }

  #characterSelect {
    width: min(560px, calc(100% - 24px));
  }

  .character-options {
    gap: 8px;
  }

  .character-card {
    min-height: 104px;
    grid-template-columns: 48px 1fr;
    gap: 8px;
    padding: 9px;
  }

  .character-preview {
    width: 42px;
    height: 56px;
  }

  .boy-preview,
  .girl-preview {
    background-size: 126px 224px;
  }

  .character-card strong {
    font-size: 18px;
  }

  .character-card span {
    font-size: 15px;
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  #titleScreen { gap: 7px; }
  #titleScreen::before { width: 70px; height: 72px; margin-bottom: 0; }
  #titleScreen h1 { font-size: 30px; }
  #titleScreen h3 { font-size: 15px; margin-bottom: 0; }
  #characterSelect { gap: 6px; }
  .character-card { min-height: 96px; }
  #startBtn { margin-top: 0; }
}
