/* ===========================================================
   PIXEL PET — 레트로 휴대용 게임기 UI
   레이아웃: 케이스 > 베젤 > 액정(LCD) > 물리 버튼 3개
   =========================================================== */

:root {
  --case: #d9576b;
  --case-dark: #b13c50;
  --case-light: #f08a99;
  --bezel: #2a2333;
  --lcd: #b7d3a0;
  --lcd-dark: #96b681;
  --ink: #23301f;
  --ink-soft: #4a5c43;
  --good: #3f7a3a;
  --warn: #a67c1f;
  --bad: #a8362f;
  --font: 'DungGeunMo', 'Galmuri11', ui-monospace, 'Apple SD Gothic Neo', 'Malgun Gothic', monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px 12px 40px;
  background: radial-gradient(circle at 50% 0%, #2e2740 0%, #16121f 70%);
  color: #e8e4f2;
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- 게임기 케이스 ---------- */

.device {
  /* 광고 층(.adslot)이 기기 전체를 덮을 기준점 */
  position: relative;
  width: min(340px, 100%);
  padding: 16px 16px 14px;
  border-radius: 46px 46px 60px 60px / 40px 40px 90px 90px;
  background: linear-gradient(160deg, var(--case-light) 0%, var(--case) 38%, var(--case-dark) 100%);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.45),
    inset 0 -6px 12px rgba(0, 0, 0, 0.28),
    0 18px 36px rgba(0, 0, 0, 0.45);
}

.device__top,
.device__bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.device__top {
  padding: 2px 8px 10px;
}

.device__brand {
  font-weight: 700;
  letter-spacing: 0.22em;
}

/* 칭호가 붙어 길어져도 두 줄로 접히지 않게 */
.device__gen {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device__bottom {
  padding: 10px 8px 0;
  font-size: 10px;
  /* 좁으면 버튼 묶음이 다음 줄로 내려간다 (.device__bottomBtns 주석 참고) */
  flex-wrap: wrap;
  row-gap: 6px;
}

/* 저장 상태는 한 덩어리로 둔다 — 접히면 "저장:" 과 값이 갈라져 읽기 나빠진다 */
#backend {
  white-space: nowrap;
}

.linkbtn {
  border: 0;
  background: none;
  color: rgba(255, 255, 255, 0.8);
  font: inherit;
  font-size: 10px;
  text-decoration: underline;
  cursor: pointer;
  padding: 2px;
  /* 라벨은 단어 안에서 접지 않는다. 자리가 모자라면 버튼째로 다음 줄에 간다 */
  white-space: nowrap;
}

.linkbtn:hover {
  color: #fff;
}

/* 알림이 차단됐거나 쓸 수 없는 브라우저 — 숨기지 않고 흐리게 둔다.
   숨기면 "알림 기능이 없는 게임"이 되어 설정을 풀 생각을 못 한다. */
.linkbtn:disabled {
  opacity: 0.45;
  cursor: default;
  text-decoration: none;
}

/* ---------- 베젤 + 액정 ---------- */

.bezel {
  padding: 12px;
  border-radius: 26px;
  background: linear-gradient(180deg, #3a3049 0%, var(--bezel) 100%);
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.6),
    0 2px 0 rgba(255, 255, 255, 0.25);
}

.lcd {
  position: relative;
  padding: 8px 9px 9px;
  border-radius: 6px;
  background: var(--lcd);
  color: var(--ink);
  /* LCD 격자 질감 */
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.05) 1px, transparent 1px);
  background-size: 4px 4px, 4px 4px;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35), inset 0 0 18px rgba(60, 90, 50, 0.5);
  transition: background-color 400ms;
}

.lcd[data-sleeping='true'] {
  background-color: #8fae86;
}

.lcd[data-phase='dead'] {
  background-color: #a8a99a;
}

.lcd__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 11px;
  padding-bottom: 4px;
  border-bottom: 2px dotted rgba(35, 48, 31, 0.35);
}

.lcd__name {
  font-weight: 700;
  font-size: 13px;
}

.lcd__stage {
  color: var(--ink-soft);
}

.lcd__body {
  position: relative;
  margin: 6px 0;
}

.lcd__canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 128 / 96;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ---------- 스탯 게이지 ---------- */

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 10px;
  padding: 4px 0 6px;
  border-top: 2px dotted rgba(35, 48, 31, 0.35);
}

.stat {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
}

.stat__label {
  width: 34px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.stat__gauge {
  display: flex;
  gap: 1px;
  flex: 1;
}

.stat__gauge i {
  flex: 1;
  height: 7px;
  background: rgba(35, 48, 31, 0.14);
}

.stat[data-level='good'] .stat__gauge i.is-on {
  background: var(--good);
}
.stat[data-level='warn'] .stat__gauge i.is-on {
  background: var(--warn);
}
.stat[data-level='bad'] .stat__gauge i.is-on {
  background: var(--bad);
  animation: blink 900ms steps(2, end) infinite;
}

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

/* ---------- 메시지 티커 ---------- */

.ticker {
  margin: 0 0 6px;
  min-height: 15px;
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--ink-soft);
}

.ticker[data-tone='good'] {
  color: var(--good);
}
.ticker[data-tone='warn'] {
  color: var(--warn);
}
.ticker[data-tone='bad'] {
  color: var(--bad);
  font-weight: 700;
}

/* ---------- 액정 안 메뉴 ---------- */

/* 칸 수를 고정하지 않는다 — ACTIONS 가 늘면 CSS 를 같이 고쳐야 하는 걸 피한다 */
.menu {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
}

.menu__item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 4px 2px;
  border: 2px solid rgba(35, 48, 31, 0.3);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.16);
  color: var(--ink);
  font: inherit;
  font-size: 10px;
  cursor: pointer;
}

.menu__cursor {
  visibility: hidden;
  font-size: 9px;
}

.menu__item.is-active {
  background: var(--ink);
  color: var(--lcd);
  border-color: var(--ink);
}

.menu__item.is-active .menu__cursor {
  visibility: visible;
}

.menu__item.is-blocked {
  opacity: 0.45;
}

/* 병은 게이지에 안 보이므로 해당 칸이 스스로 손을 들어야 한다 */
.menu__item.is-urgent {
  opacity: 1;
  border-color: var(--bad);
  animation: menu-urgent 1s steps(2, end) infinite;
}

@keyframes menu-urgent {
  0% {
    background: rgba(255, 255, 255, 0.16);
  }
  100% {
    background: var(--bad);
    color: var(--lcd);
  }
}

@media (prefers-reduced-motion: reduce) {
  .menu__item.is-urgent {
    animation: none;
    background: var(--bad);
    color: var(--lcd);
  }
}

/* ---------- 상태 패널 / 사망 오버레이 ---------- */

/* [hidden] 은 UA 스타일(display:none)이라 아래 .overlay 의 display:flex 에 밀린다.
   그대로 두면 빈 오버레이가 캔버스를 계속 덮어 펫이 안 보인다. */
.panel[hidden],
.overlay[hidden] {
  display: none;
}

.panel,
.overlay {
  position: absolute;
  inset: 0;
  padding: 8px 10px;
  background: var(--lcd);
  box-shadow: inset 0 0 0 2px rgba(35, 48, 31, 0.45);
  overflow: auto;
  font-size: 10px;
  line-height: 1.5;
}

.panel__title {
  margin: 0 0 4px;
  font-size: 11px;
  border-bottom: 2px dotted rgba(35, 48, 31, 0.4);
  padding-bottom: 3px;
}

.panel__list {
  margin: 0;
}

.panel__list > div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.panel__list dt {
  color: var(--ink-soft);
}

.panel__list dd {
  margin: 0;
  text-align: right;
}

.panel__chain {
  margin: 5px 0 0;
  color: var(--ink-soft);
  word-break: keep-all;
}

.panel__hint {
  margin: 6px 0 0;
  text-align: right;
  color: var(--ink-soft);
}

/* 보관 버튼 — 패널 안에서 유일하게 상태를 바꾸는 자리라 테두리로 구분한다 */
.panel__action {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 5px 10px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--lcd);
  color: var(--ink);
  font: inherit;
  font-size: 10px;
  cursor: pointer;
}

.panel__action:hover {
  background: var(--lcd-dark);
}

.panel__action:active {
  transform: translateY(1px);
}

.panel__actionSub {
  display: block;
  color: var(--ink-soft);
  font-size: 9px;
}

/* ---------- 놀아주기 미니게임 ---------- */

.mini {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
}

.mini__track {
  display: flex;
  gap: 2px;
}

.mini__cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 20px;
  border: 2px solid rgba(35, 48, 31, 0.3);
  border-radius: 2px;
  font-size: 11px;
  line-height: 1;
  color: var(--ink-soft);
}

/* 맞혀야 하는 칸 */
.mini__cell.is-target {
  border-color: var(--ink);
  background: rgba(35, 48, 31, 0.14);
}

.mini__cell.is-cursor {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--lcd);
}

.mini__status {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
}

.mini__status[data-hit='true'] {
  color: var(--good);
}

.mini__status[data-hit='false'] {
  color: var(--bad);
}

.mini__hint {
  margin: 0;
  font-size: 9px;
  color: var(--ink-soft);
}

/* ---------- 패널 탭 (A 로 이동) ---------- */

.tabs {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding-bottom: 4px;
  margin-bottom: 5px;
  border-bottom: 2px dotted rgba(35, 48, 31, 0.35);
  font-size: 10px;
}

.tabs__item {
  color: var(--ink-soft);
}

.tabs__item.is-active {
  color: var(--lcd);
  background: var(--ink);
  padding: 1px 4px;
  border-radius: 2px;
}

.tabs__hint {
  margin-left: auto;
  font-size: 9px;
  color: var(--ink-soft);
  opacity: 0.75;
  white-space: nowrap;
}

/* ---------- 도감 ---------- */

.dex__group + .dex__group {
  margin-top: 8px;
}

.dex__heading {
  margin: 0 0 4px;
  font-size: 10px;
  font-weight: 400;
  color: var(--ink-soft);
}

.dex {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px 2px;
}

.dex__cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.dex__sprite {
  /* 16px 도트를 정확히 2배로 — 소수배로 늘리면 픽셀 폭이 들쭉날쭉해진다 */
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.dex__name {
  font-size: 9px;
  line-height: 1.2;
  text-align: center;
  word-break: keep-all;
}

.dex__cell.is-locked .dex__name {
  color: var(--ink-soft);
  opacity: 0.7;
}

/* ---------- 도감 · 성격 (도트가 없어 칸 대신 글로) ---------- */

.trait__list {
  border-top: 2px dotted rgba(35, 48, 31, 0.35);
}

.trait {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 2px 0;
  border-bottom: 1px dotted rgba(35, 48, 31, 0.2);
}

.trait__name {
  flex: none;
  width: 58px;
  font-weight: 700;
}

.trait__desc {
  color: var(--ink-soft);
  font-size: 9px;
  word-break: keep-all;
}

.trait.is-locked {
  opacity: 0.55;
}

.trait.is-locked .trait__name {
  font-weight: 400;
}

/* ---------- 역대 기록 ---------- */

.rec__list {
  margin-top: 6px;
  border-top: 2px dotted rgba(35, 48, 31, 0.35);
}

.rec {
  display: grid;
  grid-template-columns: 30px 1fr auto auto;
  gap: 6px;
  padding: 2px 0;
  border-bottom: 1px dotted rgba(35, 48, 31, 0.2);
}

.rec__gen {
  color: var(--ink-soft);
}

.rec__age,
.rec__score {
  color: var(--ink-soft);
  white-space: nowrap;
}

/* 되살린 세대는 집계에서 빠졌다는 걸 이 줄에서만 알 수 있다 */
.rec__revived {
  margin-left: 4px;
  color: var(--warn);
  font-size: 9px;
  font-style: normal;
}

.rec.is-revived .rec__age,
.rec.is-revived .rec__score {
  opacity: 0.6;
}

/* 끝까지 키워서 보낸 세대. 방치해서 잃은 줄과 섞이면 안 된다 */
.rec__kept {
  margin-left: 4px;
  color: var(--ink-soft);
  font-size: 9px;
  font-style: normal;
}

/* ---------- 칭호 ---------- */

.title__list {
  margin-top: 6px;
  border-top: 2px dotted rgba(35, 48, 31, 0.35);
}

.title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 0;
  border-bottom: 1px dotted rgba(35, 48, 31, 0.2);
}

.title__name {
  font-weight: 700;
  white-space: nowrap;
}

.title__desc {
  color: var(--ink-soft);
  font-size: 9px;
  text-align: right;
  word-break: keep-all;
}

.title.is-locked {
  opacity: 0.55;
}

.title.is-locked .title__name {
  font-weight: 400;
}

.overlay__title {
  color: #3f4436;
}

.overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  background: #a8a99a;
}

.overlay h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.1em;
}

.overlay p {
  margin: 0;
}

.overlay__score {
  font-weight: 700;
}

.overlay__hint {
  margin-top: 6px !important;
  color: #3f4436;
  animation: blink 1400ms steps(2, end) infinite;
}

/* 되살리기 — 사망 화면에서 유일하게 눌러야 할 것처럼 보여야 한다 */
.overlay__revive {
  margin-top: 6px;
  padding: 5px 10px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--lcd);
  color: var(--ink);
  font: inherit;
  font-size: 10px;
  line-height: 1.4;
  cursor: pointer;
}

.overlay__revive:hover {
  background: var(--lcd-dark);
}

.overlay__revive:active {
  transform: translateY(1px);
}

.overlay__reviveLeft {
  display: block;
  color: var(--ink-soft);
  font-size: 9px;
}

/* 되살리기의 대가를 누르기 전에 알린다 — 누른 뒤에 알면 늦다 */
.overlay__warn {
  margin-top: 2px !important;
  padding: 0 6px;
  color: #3f4436;
  font-size: 9px;
  line-height: 1.4;
  word-break: keep-all;
}

/* ---------- 광고 층 ----------
   src/ads/rewarded.js 가 소유한다. 기기 전체를 덮는 건 의도한 것이다 —
   광고는 원래 페이지 위에 자기 레이어를 씌우는 물건이다.
   내용은 elcherlab 의 다른 게임 (src/ads/house.js). */

.adslot {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  border-radius: inherit;
  background: rgba(12, 9, 20, 0.88);
}

.adslot[hidden] {
  display: none;
}

.adslot__box {
  width: 100%;
  padding: 16px 12px;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  text-align: center;
}

.adslot__tag {
  margin: 0;
  color: rgba(255, 255, 255, 0.55);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.adslot__ad {
  margin: 10px 0 12px;
  padding: 12px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.adslot__icon {
  font-size: 30px;
  line-height: 1;
}

.adslot__title {
  margin: 6px 0 0;
  color: #fff;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.3;
  word-break: keep-all;
}

.adslot__body {
  margin: 6px 0 10px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 10px;
  line-height: 1.55;
  word-break: keep-all;
}

.adslot__link {
  display: inline-block;
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 4px;
  color: #fff;
  font-size: 10px;
  text-decoration: none;
}

.adslot__link:hover {
  background: rgba(255, 255, 255, 0.14);
}

.adslot__count {
  margin: 0 0 10px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 11px;
}

.adslot__skip {
  border: 0;
  background: none;
  color: rgba(255, 255, 255, 0.7);
  font: inherit;
  font-size: 10px;
  text-decoration: underline;
  cursor: pointer;
  padding: 2px 6px;
}

.adslot__skip:hover {
  color: #fff;
}

/* ---------- 물리 버튼 ---------- */

.pad {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 22px;
  padding: 18px 0 4px;
}

.pad__btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 58px;
  border: 0;
  background: none;
  color: rgba(255, 255, 255, 0.9);
  font: inherit;
  font-size: 9px;
  cursor: pointer;
}

.pad__key {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  color: #4a1520;
  background: linear-gradient(165deg, #fff1f3 0%, #e6b9c1 55%, #c78d98 100%);
  box-shadow:
    inset 0 2px 2px rgba(255, 255, 255, 0.9),
    inset 0 -3px 4px rgba(0, 0, 0, 0.25),
    0 4px 0 var(--case-dark),
    0 6px 8px rgba(0, 0, 0, 0.35);
  transition: transform 60ms, box-shadow 60ms;
}

.pad__btn--mid .pad__key {
  width: 48px;
  height: 48px;
}

.pad__btn:active .pad__key {
  transform: translateY(4px);
  box-shadow:
    inset 0 2px 3px rgba(0, 0, 0, 0.3),
    0 0 0 var(--case-dark),
    0 2px 4px rgba(0, 0, 0, 0.3);
}

.pad__label {
  letter-spacing: 0.06em;
}

/* ---------- 하단 안내 ---------- */

.hint {
  margin: 0;
  text-align: center;
  font-size: 11px;
  line-height: 1.7;
  color: rgba(232, 228, 242, 0.6);
}

@media (max-width: 380px) {
  .device {
    width: 100%;
  }
  .pad {
    gap: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stat[data-level='bad'] .stat__gauge i.is-on,
  .overlay__hint {
    animation: none;
  }
}

/* ---------- 통합 로그인 다이얼로그 ---------- */

/*
 * 기기 폭이 min(340px, 100%) 로 묶여 있어서, 하단 줄이 쓸 수 있는 폭은 화면이 아무리
 * 넓어도 300px 안쪽이다. 저장 상태 + 버튼 넷은 거기에 한 줄로 절대 안 들어간다.
 *
 * 예전에는 `flex-wrap` 이 없어 항목들이 내용 폭 아래로 짜부라졌고, 그러면 글자가
 * 항목 **안에서** 접혔다 — "로그/인", "알림/켜기", "데이터 초/기화" 처럼. 그래서
 * 항목별 줄바꿈은 막고(`nowrap`) 대신 줄 사이에서 접히게 둔다.
 */
.device__bottomBtns {
  display: flex;
  /* 한 줄에 남은 폭이 모자라면 통째로 다음 줄로 내려가 오른쪽에 붙는다 */
  flex: 1 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px 10px;
}

.account {
  border: 3px solid var(--bezel);
  border-radius: 12px;
  background: var(--lcd);
  color: var(--ink);
  font-family: var(--font);
  padding: 18px 20px;
  max-width: min(320px, calc(100vw - 32px));
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.account::backdrop {
  background: rgba(10, 8, 16, 0.65);
}

.account__title {
  margin: 0 0 6px;
  font-size: 16px;
}

.account__desc {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.5;
}

.account__field {
  display: block;
  font-size: 12px;
  margin-bottom: 10px;
}

.account__field input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 9px;
  border: 2px solid var(--ink-soft);
  border-radius: 6px;
  background: #f4f9ec;
  color: var(--ink);
  font: inherit;
}

.account__field input:focus {
  outline: 2px solid var(--case);
  outline-offset: 1px;
}

.account__error {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--bad);
}

.account__check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.5;
  cursor: pointer;
}

.account__check input {
  margin: 2px 0 0;
  flex: none;
  cursor: pointer;
}

.account__legal {
  margin: 10px 0 0;
  text-align: center;
  font-size: 11px;
}

.account__check a,
.account__legal a {
  color: inherit;
}

.account__actions {
  display: flex;
  gap: 8px;
}

.account__actions button {
  flex: 1;
  padding: 8px 0;
  border: 2px solid var(--bezel);
  border-radius: 8px;
  background: var(--case);
  color: #fff;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.account__actions .account__signup {
  background: var(--lcd-dark);
  color: var(--ink);
}

.account__actions #accountCancel {
  flex: 0 0 auto;
  padding: 8px 12px;
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--ink-soft);
}

.account__actions button:hover {
  filter: brightness(1.08);
}
