/* ═══════════════════════════════════════════════════════════════
   Pocket Valley DX — console.css
   휴대용 게임기 쉘: 레이아웃 · 테마 · 스캔라인 · 조작 버튼
   ═══════════════════════════════════════════════════════════════ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR",
    "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 800px at 50% -10%, #3d4a3f 0%, transparent 60%),
    radial-gradient(900px 700px at 85% 110%, #2c3a34 0%, transparent 55%),
    #1e2620;
  color: #f3efe4;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* 숨김 유틸리티 (계약: display:none !important) */
.is-hidden {
  display: none !important;
}

/* 숨긴 오버레이는 터치를 가로채지 않는다. 보이는 것만 auto. */
#modal-root.is-hidden,
#dialogue.is-hidden,
#fishing-ui.is-hidden,
#toast.is-hidden {
  pointer-events: none !important;
}
#modal-root:not(.is-hidden),
#dialogue:not(.is-hidden),
#fishing-ui:not(.is-hidden) {
  pointer-events: auto;
}

/* ─────────────────────── 게임기 쉘 ─────────────────────── */

#console-shell {
  /* 기본 테마: sage (data-theme가 없을 때의 폴백) */
  --shell-bg: #a8c3a0;
  --shell-bg-2: #8fb088;
  --shell-edge: #6f8f68;
  --shell-highlight: rgba(255, 255, 255, 0.35);
  --shell-shadow: rgba(20, 40, 20, 0.45);
  --bezel: #2b3a2e;
  --bezel-2: #1e2b21;
  --btn-face: #3a4a3d;
  --btn-face-2: #2b3a2e;
  --btn-a: #c0392b;
  --btn-a-2: #96281b;
  --btn-b: #d9a441;
  --btn-b-2: #b07f24;
  --accent: #4e7a45;
  --text-on-shell: #243528;
  --text-on-shell-dim: rgba(36, 53, 40, 0.62);
  --led-on: #7dff8a;
  --led-glow: rgba(125, 255, 138, 0.85);
  --top-btn-bg: rgba(255, 255, 255, 0.28);
  --top-btn-border: rgba(36, 53, 40, 0.25);

  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding:
    max(8px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  background:
    linear-gradient(165deg, var(--shell-highlight) 0%, transparent 38%),
    linear-gradient(180deg, var(--shell-bg) 0%, var(--shell-bg-2) 100%);
  color: var(--text-on-shell);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  overflow: hidden;
  transition: background 0.35s ease, color 0.35s ease;
}

/* ─── 테마 4종 ─── */
#console-shell[data-theme="sage"] {
  --shell-bg: #a8c3a0; --shell-bg-2: #8fb088; --shell-edge: #6f8f68;
  --bezel: #2b3a2e; --bezel-2: #1e2b21;
  --btn-face: #3a4a3d; --btn-face-2: #2b3a2e;
  --btn-a: #c0392b; --btn-a-2: #96281b;
  --btn-b: #d9a441; --btn-b-2: #b07f24;
  --accent: #4e7a45; --text-on-shell: #243528;
  --text-on-shell-dim: rgba(36, 53, 40, 0.62);
  --led-on: #7dff8a; --led-glow: rgba(125, 255, 138, 0.85);
  --top-btn-bg: rgba(255, 255, 255, 0.28); --top-btn-border: rgba(36, 53, 40, 0.25);
}
#console-shell[data-theme="cream"] {
  --shell-bg: #f0e3c8; --shell-bg-2: #e0cda3; --shell-edge: #b89b6a;
  --bezel: #4a3a28; --bezel-2: #33271a;
  --btn-face: #5a4632; --btn-face-2: #423322;
  --btn-a: #c0392b; --btn-a-2: #96281b;
  --btn-b: #7a9e7e; --btn-b-2: #5c7f60;
  --accent: #a07a3f; --text-on-shell: #4a3a28;
  --text-on-shell-dim: rgba(74, 58, 40, 0.6);
  --led-on: #ffb340; --led-glow: rgba(255, 179, 64, 0.85);
  --top-btn-bg: rgba(255, 255, 255, 0.4); --top-btn-border: rgba(74, 58, 40, 0.25);
}
#console-shell[data-theme="berry"] {
  --shell-bg: #e3a7b8; --shell-bg-2: #cf8299; --shell-edge: #a85a72;
  --bezel: #43242f; --bezel-2: #2e1821;
  --btn-face: #55303d; --btn-face-2: #3f222d;
  --btn-a: #8e44ad; --btn-a-2: #6c2f87;
  --btn-b: #e67e9a; --btn-b-2: #c45474;
  --accent: #a83e5f; --text-on-shell: #43242f;
  --text-on-shell-dim: rgba(67, 36, 47, 0.62);
  --led-on: #ff8fb3; --led-glow: rgba(255, 143, 179, 0.85);
  --top-btn-bg: rgba(255, 255, 255, 0.32); --top-btn-border: rgba(67, 36, 47, 0.25);
}
#console-shell[data-theme="indigo"] {
  --shell-bg: #7d8fc9; --shell-bg-2: #5f71ad; --shell-edge: #46548c;
  --bezel: #232a47; --bezel-2: #171d33;
  --btn-face: #323c63; --btn-face-2: #242c4a;
  --btn-a: #e05252; --btn-a-2: #b23a3a;
  --btn-b: #4fc3c9; --btn-b-2: #33959c;
  --accent: #33478f; --text-on-shell: #1d2440;
  --text-on-shell-dim: rgba(29, 36, 64, 0.62);
  --led-on: #7dd8ff; --led-glow: rgba(125, 216, 255, 0.85);
  --top-btn-bg: rgba(255, 255, 255, 0.3); --top-btn-border: rgba(29, 36, 64, 0.28);
}

/* 데스크톱: 중앙에 떠 있는 게임기 */
@media (min-width: 560px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
  }
  #console-shell {
    max-width: 500px;
    height: min(100dvh - 28px, 940px);
    max-height: calc(100dvh - 28px);
    border-radius: 30px;
    border: 2px solid var(--shell-edge);
    box-shadow:
      0 30px 70px rgba(0, 0, 0, 0.55),
      0 6px 18px rgba(0, 0, 0, 0.4),
      inset 0 2px 0 var(--shell-highlight),
      inset 0 -6px 14px rgba(0, 0, 0, 0.12);
    padding: 14px 16px 12px;
  }
}

/* 아주 낮은 화면(가로 모드 폰 등): 상하 여백 축소 */
@media (max-height: 540px) {
  #console-shell { padding-top: 4px; padding-bottom: 4px; }
  .brand small, .system-hint, .ab-hint, .bottom-hint { display: none; }
}

/* ─────────────────────── 상단 바 ─────────────────────── */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 2px 8px;
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(160deg, var(--btn-face), var(--btn-face-2));
  color: #f5f1de;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.25);
  flex: 0 0 auto;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
  white-space: nowrap;
}
.brand-text strong {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.6px;
}
.brand-text strong em {
  font-style: normal;
  color: var(--btn-a);
}
.brand-text small {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-on-shell-dim);
  letter-spacing: 1.5px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.power-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-right: 2px;
}
.power-led {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #5a6a5c;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.power-led.is-on {
  background: var(--led-on);
  box-shadow: 0 0 8px var(--led-glow), 0 0 2px var(--led-glow), inset 0 -1px 2px rgba(0,0,0,0.25);
  animation: led-pulse 2.6s ease-in-out infinite;
}
@keyframes led-pulse {
  0%, 100% { box-shadow: 0 0 8px var(--led-glow), 0 0 2px var(--led-glow), inset 0 -1px 2px rgba(0,0,0,0.25); }
  50% { box-shadow: 0 0 4px var(--led-glow), 0 0 1px var(--led-glow), inset 0 -1px 2px rgba(0,0,0,0.25); }
}
.power-label {
  font-size: 7px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--text-on-shell-dim);
}

.top-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1.5px solid var(--top-btn-border);
  background: var(--top-btn-bg);
  color: var(--text-on-shell);
  font: inherit;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0,0,0,0.18);
  transition: transform 0.06s ease, box-shadow 0.06s ease, background 0.2s ease;
  touch-action: manipulation;
}
.top-btn:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 rgba(0,0,0,0);
}
.top-btn.is-active {
  background: rgba(255, 255, 255, 0.55);
  border-color: var(--accent);
}
.top-btn-icon { font-size: 12px; line-height: 1; }
.top-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 400px) {
  .top-btn-label { display: none; }
  .top-btn { padding: 5px 8px; }
  .brand-text strong { font-size: 12px; }
}

/* ─────────────────────── 화면 영역 ─────────────────────── */

#screen-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;              /* 남은 세로 공간을 전부 차지 (4:3 고정 금지) */
  border-radius: 16px;
  border: 3px solid var(--bezel);
  background: var(--bezel-2);
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,0.06),
    inset 0 10px 28px rgba(0,0,0,0.5),
    0 3px 8px rgba(0,0,0,0.25);
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #7fb069;
  touch-action: none;
}

/* 스캔라인 오버레이 */
#scanlines {
  position: absolute;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.14) 0px,
      rgba(0, 0, 0, 0.14) 1px,
      transparent 1px,
      transparent 3px
    );
  mix-blend-mode: multiply;
  opacity: 0.55;
}
#scanlines.is-hidden { display: none !important; }

/* 화면 유리 반사 */
.screen-glare {
  position: absolute;
  inset: 0;
  z-index: 31;
  pointer-events: none;
  background: linear-gradient(115deg, rgba(255,255,255,0.10) 0%, transparent 34%);
}

/* ─────────────────────── 조작부 ─────────────────────── */

.controls {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  column-gap: 4px;
  width: 100%;
  padding: clamp(8px, 2dvh, 16px) 2px 2px;
}

/* 십자키 */
.dpad {
  --dpad-size: clamp(104px, 31vw, 138px);
  --dpad-btn: calc(var(--dpad-size) / 3);
  display: grid;
  grid-template-columns: repeat(3, var(--dpad-btn));
  grid-template-rows: repeat(3, var(--dpad-btn));
  width: var(--dpad-size);
  height: var(--dpad-size);
  filter: drop-shadow(0 4px 4px rgba(0,0,0,0.35));
  justify-self: start;
  touch-action: none;
  -webkit-touch-callout: none;
}
.dpad-btn {
  appearance: none;
  border: none;
  background: linear-gradient(180deg, var(--btn-face) 0%, var(--btn-face-2) 100%);
  color: rgba(245, 241, 222, 0.85);
  font-size: clamp(13px, 3.6vw, 17px);
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  transition: filter 0.05s ease, transform 0.05s ease;
}
.dpad-up    { border-radius: 10px 10px 0 0; box-shadow: inset 0 2px 0 rgba(255,255,255,0.18); }
.dpad-down  { border-radius: 0 0 10px 10px; box-shadow: inset 0 -3px 0 rgba(0,0,0,0.35); }
.dpad-left  { border-radius: 10px 0 0 10px; box-shadow: inset 2px 0 0 rgba(255,255,255,0.12); }
.dpad-right { border-radius: 0 10px 10px 0; box-shadow: inset -3px 0 0 rgba(0,0,0,0.3); }
.dpad-btn:active,
.dpad-btn.is-pressed {
  filter: brightness(1.35);
  transform: scale(0.96);
}
.dpad-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  z-index: 1;
}
.dpad-center {
  background: linear-gradient(180deg, var(--btn-face) 0%, var(--btn-face-2) 100%);
  display: grid;
  place-items: center;
}
.dpad-dot {
  width: 38%; height: 38%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.22), rgba(0,0,0,0.35) 75%);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.45);
}
.dpad-empty { background: transparent; }

/* SELECT / START */
.system-btns {
  display: flex;
  gap: clamp(8px, 3vw, 16px);
  justify-self: center;
  align-self: end;
  padding-bottom: clamp(8px, 2.5vw, 14px);
}
.system-btn-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.system-btn {
  appearance: none;
  position: relative;
  width: clamp(38px, 10.5vw, 50px);
  height: 19px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--btn-face) 0%, var(--btn-face-2) 100%);
  box-shadow: 0 3px 0 rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.2);
  cursor: pointer;
  transform: rotate(-14deg);
  touch-action: none;
  transition: transform 0.05s ease, box-shadow 0.05s ease, filter 0.05s ease;
}
.system-btn::after {
  content: "";
  position: absolute;
  inset: -13px -6px;
}
.system-btn:active,
.system-btn.is-pressed {
  transform: rotate(-14deg) translateY(2px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.2);
  filter: brightness(1.3);
}
.system-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
.system-label {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1.2px;
  color: var(--text-on-shell-dim);
}
.system-hint {
  font-size: 8.5px;
  font-weight: 700;
  color: var(--text-on-shell-dim);
  opacity: 0.85;
  white-space: normal;
  text-align: center;
  line-height: 1.25;
  min-height: 21px;
  max-width: 64px;
}

/* A / B 버튼 */
.ab-btns {
  display: flex;
  align-items: flex-end;
  gap: clamp(6px, 2.4vw, 12px);
  justify-self: end;
}
.ab-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: clamp(54px, 14.5vw, 68px);
}
.ab-wrap-a { margin-bottom: clamp(18px, 5vw, 28px); }
.ab-btn {
  appearance: none;
  border: none;
  width: clamp(52px, 13.8vw, 62px);
  height: clamp(52px, 13.8vw, 62px);
  border-radius: 50%;
  color: #fff8ec;
  font: inherit;
  font-size: clamp(19px, 5.4vw, 24px);
  font-weight: 900;
  letter-spacing: 0.5px;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
  transition: transform 0.05s ease, box-shadow 0.05s ease, filter 0.05s ease;
}
.ab-a {
  background: radial-gradient(circle at 32% 28%, rgba(255,255,255,0.35), transparent 45%),
    linear-gradient(180deg, var(--btn-a) 0%, var(--btn-a-2) 100%);
  box-shadow: 0 5px 0 var(--btn-a-2), 0 8px 12px rgba(0,0,0,0.35), inset 0 -3px 6px rgba(0,0,0,0.25);
}
.ab-b {
  background: radial-gradient(circle at 32% 28%, rgba(255,255,255,0.35), transparent 45%),
    linear-gradient(180deg, var(--btn-b) 0%, var(--btn-b-2) 100%);
  box-shadow: 0 5px 0 var(--btn-b-2), 0 8px 12px rgba(0,0,0,0.35), inset 0 -3px 6px rgba(0,0,0,0.25);
}
.ab-btn:active,
.ab-btn.is-pressed {
  transform: translateY(4px);
  filter: brightness(1.12);
}
.ab-a:active, .ab-a.is-pressed { box-shadow: 0 1px 0 var(--btn-a-2), 0 3px 6px rgba(0,0,0,0.3), inset 0 -2px 5px rgba(0,0,0,0.3); }
.ab-b:active, .ab-b.is-pressed { box-shadow: 0 1px 0 var(--btn-b-2), 0 3px 6px rgba(0,0,0,0.3), inset 0 -2px 5px rgba(0,0,0,0.3); }
.ab-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
.ab-hint {
  font-size: 8.5px;
  font-weight: 700;
  color: var(--text-on-shell-dim);
  white-space: normal;
  text-align: center;
  line-height: 1.25;
  min-height: 21px;
  max-width: 74px;
}

/* ─────────────────────── 하단 바 ─────────────────────── */

.bottom-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 2px 0;
}
.speaker-grille {
  display: flex;
  flex-direction: column;
  gap: 3.5px;
  transform: rotate(-8deg);
  flex: 0 0 auto;
}
.speaker-grille span {
  display: block;
  width: clamp(30px, 9vw, 44px);
  height: 3.5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  box-shadow: inset 0 1px 1px rgba(0,0,0,0.4), 0 1px 0 rgba(255,255,255,0.18);
}
.bottom-hint {
  font-size: 9px;
  font-weight: 600;
  line-height: 1.45;
  text-align: center;
  color: var(--text-on-shell-dim);
  flex: 1 1 auto;
}

/* 가로가 아주 좁은 기기 */
@media (max-width: 350px) {
  .system-hint, .ab-hint { display: none; }
  .dpad { --dpad-size: 100px; }
  .ab-wrap { width: 50px; }
  .ab-btn { width: 46px; height: 46px; }
  .ab-wrap-a { margin-bottom: 14px; }
  .system-btn { width: 34px; }
  .system-btns { gap: 8px; padding-bottom: 6px; }
}

/* 터치 기기: 키보드 안내 숨김 */
@media (pointer: coarse) {
  .bottom-hint { display: none; }
}

/* 모션 감소 선호 */
@media (prefers-reduced-motion: reduce) {
  .power-led.is-on { animation: none; }
  #console-shell { transition: none; }
}

/* ═══════════ v5.1 콘솔 디자인 업그레이드 ═══════════ */
#console-shell {
  background-image:
    radial-gradient(120% 60% at 50% -10%, rgba(255,255,255,0.28) 0%, transparent 55%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.015) 0 2px, transparent 2px 4px);
}
#screen-wrap {
  box-shadow:
    inset 0 2px 10px rgba(0,0,0,0.55),
    inset 0 -1px 3px rgba(255,255,255,0.12),
    0 6px 18px rgba(0,0,0,0.3);
  position: relative;
}
#screen-wrap::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  background: linear-gradient(115deg, rgba(255,255,255,0.14) 0%, transparent 32%);
  pointer-events: none;
}
.ab-btn {
  box-shadow: 0 5px 0 rgba(0,0,0,0.4), 0 9px 16px rgba(0,0,0,0.3), inset 0 2px 3px rgba(255,255,255,0.45), inset 0 -3px 5px rgba(0,0,0,0.18);
}
.ab-btn:active, .ab-btn.is-pressed {
  box-shadow: 0 1px 0 rgba(0,0,0,0.4), 0 3px 6px rgba(0,0,0,0.25), inset 0 2px 4px rgba(0,0,0,0.25);
}
.power-led { filter: drop-shadow(0 0 5px rgba(120,255,150,0.8)); }

/* ═══════════ v5.2 콘솔 심화 ═══════════ */
.brand-mark {
  background: linear-gradient(160deg, #ffe9a8, var(--gold, #c99327) 60%, #8a5f10);
  box-shadow: 0 3px 8px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.7);
  text-shadow: 0 1px 1px rgba(0,0,0,0.35);
}
.brand-text strong { text-shadow: 0 1px 0 rgba(255,255,255,0.25), 0 2px 4px rgba(0,0,0,0.25); }
.dpad { filter: drop-shadow(0 6px 8px rgba(0,0,0,0.35)); }
.dpad-btn {
  background-image: radial-gradient(circle at 50% 38%, rgba(255,255,255,0.16), transparent 62%);
}
.dpad-center, .dpad::after {
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.5), inset 0 -1px 2px rgba(255,255,255,0.15);
}
.top-btn {
  background: linear-gradient(180deg, rgba(255,255,255,0.22), rgba(255,255,255,0.06));
  border: 1.5px solid rgba(255,255,255,0.28);
  box-shadow: 0 3px 7px rgba(0,0,0,0.22), inset 0 1px 0 rgba(255,255,255,0.35);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.system-btn {
  box-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 7px 12px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.4);
}
.speaker-grille, .speaker {
  background-image: radial-gradient(circle, rgba(0,0,0,0.42) 1.6px, transparent 1.7px);
  background-size: 8px 8px;
}
