:root {
  --bg: #0f1720;
  --panel: #17222e;
  --panel-2: #1e2c3a;
  --line: #2b3d50;
  --text: #e9f1f7;
  --muted: #93a7b8;
  --accent: #5ec8f2;
  --warn: #f2a65e;
  --error: #f2777a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  padding: 20px 16px 32px;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2b3b, var(--bg));
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  line-height: 1.5;
}

.app {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

h1 {
  margin: 0 0 4px;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}

.sub {
  margin: 0 0 18px;
  font-size: 0.9rem;
  color: var(--muted);
}

.search {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.label { font-size: 0.75rem; color: var(--muted); }

input {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 0.95rem;
}

input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
}

.primary {
  padding: 10px 20px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #06121b;
  font-weight: 700;
}

.primary:hover { background: #7ad4f6; }
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: 0.55; cursor: progress; }

.status { min-height: 0; margin: 12px 0 0; font-size: 0.88rem; }
.status:empty { display: none; }
.status.loading { color: var(--muted); }
.status.error { color: var(--error); }
.status.warn { color: var(--warn); }

.retry {
  margin-left: 8px;
  padding: 4px 12px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
  font-size: 0.85rem;
}

.result {
  margin-top: 14px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.result-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.result-head h2 { margin: 0; font-size: 1.1rem; }

.result-date { margin: 2px 0 0; font-size: 0.82rem; color: var(--muted); }
.result-point { margin: 2px 0 0; font-size: 0.72rem; color: var(--muted); }

.cond {
  margin: 0;
  padding: 6px 12px;
  background: var(--panel-2);
  border-radius: 999px;
  font-size: 0.85rem;
  white-space: nowrap;
}

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

.item {
  padding: 10px 12px;
  background: var(--panel-2);
  border-radius: 10px;
}

.item dt { font-size: 0.75rem; color: var(--muted); }
.item dd { margin: 2px 0 0; font-size: 1.05rem; font-weight: 600; }

.source {
  margin: 16px 0 0;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--muted);
}

.screen { display: block; }

/* hidden 속성이 켜진 화면은 확실히 감춥니다. (지도 → 게임 화면 전환) */
.screen[hidden] { display: none; }

.map-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 6;
  max-height: 64vh;
  background: radial-gradient(120% 90% at 50% 0%, #16242f, #0e1922);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

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

#map-canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.map-readout {
  min-height: 1.2em;
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.market-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 12px;
}

.market-titles { min-width: 0; flex: 1 1 auto; }
.market-head h2 { margin: 0; font-size: 1.15rem; }

.ghost {
  padding: 6px 12px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
  font-size: 0.85rem;
  white-space: nowrap;
}
.ghost:hover { background: var(--panel-2); }
.ghost:active { transform: translateY(1px); }

.wallet {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  padding: 6px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.wallet-label { font-size: 0.72rem; color: var(--muted); }
.wallet strong { font-size: 1rem; color: #ffd166; }
.wallet-unit { color: var(--muted); }

/* 저장이 되는지 안 되는지 화면에서 바로 알 수 있게 표시합니다. */
.save-status { font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.save-status.ok { color: var(--accent); }
.save-status.warn { color: var(--warn); }

/* 잡화점 안: 내 건물(흰색 실내) 한가운데에 선반 하나가 있습니다. */
.shop-view {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 52vh;
  padding: 14px;
  background:
    linear-gradient(180deg, #ffffff, #f1f3f1 64%, #e4e8e6);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: #1d2a33;
}

.shop-view[hidden] { display: none; }

.shop-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  margin-bottom: 10px;
}

.shop-head h2 { margin: 0; flex: 1 1 auto; font-size: 1.1rem; color: #16222b; }

/* 흰 실내 위에서도 잘 읽히도록 나가기 버튼 색을 바꿉니다. */
.shop-head .ghost {
  color: #2b4a5e;
  background: #ffffff;
  border-color: #c3ccd1;
}
.shop-head .ghost:hover { background: #eef2f4; }

.shop-wall {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 4px 2px 6px;
}

/* 선반 하나: 물건은 이 선반 위에 나란히 놓입니다. */
.shelf-unit {
  width: min(100%, 520px);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.shop-list {
  list-style: none;
  margin: 0;
  padding: 12px 12px 0;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 10px;
}

.shop-item {
  width: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 8px;
  background: #ffffff;
  color: #1d2a33;
  border: 1px solid #c9d2d6;
  border-radius: 10px;
  box-shadow: 0 2px 0 rgba(120, 132, 140, 0.3);
  text-align: center;
  font: inherit;
  cursor: pointer;
}

.shop-item:hover:not(:disabled) { border-color: #5ec8f2; }
.shop-item:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 0 0 rgba(120, 132, 140, 0.3); }
.shop-item:disabled { cursor: not-allowed; opacity: 0.5; }

.shop-item-icon { font-size: 1.2rem; line-height: 1.1; }
.shop-item-name { font-weight: 600; font-size: 0.9rem; }
.shop-item-price { font-size: 0.8rem; color: #a9761a; }
.shop-item-owned { font-size: 0.72rem; color: #6b7a85; }

/* 기다리는 손님: 손님을 누르면 그 물건이 팔립니다. */
.customer-unit {
  width: min(100%, 520px);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.customer-unit[hidden] { display: none; }

.customer-title {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: #8a5a12;
  text-align: center;
}

.customer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.customer-card {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: #fff8e8;
  color: #1d2a33;
  border: 1px solid #e0c58a;
  border-radius: 10px;
  text-align: left;
  font: inherit;
}

.customer-card:hover:not(:disabled) { border-color: #e09b2a; background: #fff2d6; }
.customer-card:active:not(:disabled) { transform: translateY(1px); }
.customer-card:disabled { opacity: 0.55; cursor: not-allowed; }

.customer-face { font-size: 1.2rem; line-height: 1; }
.customer-text { display: flex; flex-direction: column; min-width: 0; }
.customer-name { font-size: 0.72rem; color: #8a7a5c; }
.customer-want { font-weight: 600; font-size: 0.88rem; }
/* 물건을 눌러 판매가를 정하는 입력줄 */
.price-editor {
  width: min(100%, 420px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  background: #ffffff;
  border: 1px solid #c3ccd1;
  border-radius: 12px;
}

.price-editor[hidden] { display: none; }

.price-label { font-size: 0.84rem; font-weight: 700; color: #16222b; }

.price-input {
  width: 96px;
  padding: 6px 8px;
  background: #f4f7f8;
  color: #16222b;
  border: 1px solid #c3ccd1;
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  text-align: right;
}

.price-unit { font-size: 0.84rem; color: #5b6b77; }
.price-save { padding: 6px 14px; font-size: 0.85rem; }
.price-cancel {
  padding: 6px 12px;
  font-size: 0.85rem;
  color: #2b4a5e;
  background: #ffffff;
  border-color: #c3ccd1;
}
.price-cancel:hover { background: #eef2f4; }

.shop-item.editing { border-color: #e09b2a; box-shadow: 0 0 0 2px rgba(224, 155, 42, 0.35); }

.shelf-plank {
  width: 100%;
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(180deg, #c9a675, #a07f52);
  box-shadow: 0 5px 0 rgba(120, 100, 70, 0.28);
}

.shop-msg { min-height: 1.2em; margin: 0; font-size: 0.82rem; text-align: center; }
.shop-msg:empty { min-height: 0; }
.shop-msg.warn { color: #b36a1c; }
.shop-msg.ok { color: #2a6f8e; }

/* 상점: 물건을 사는 화면입니다. 잡화점 안(흰 실내)과 구분되는 어두운 매대입니다. */
.buy-view {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 52vh;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.buy-view[hidden] { display: none; }

.buy-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  margin-bottom: 10px;
}

.buy-head h2 { margin: 0; flex: 1 1 auto; font-size: 1.1rem; }

.buy-list {
  list-style: none;
  margin: 0;
  padding: 0;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  gap: 8px;
}

.buy-item {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: left;
  font: inherit;
}

.buy-item:hover:not(:disabled) { border-color: var(--accent); }
.buy-item:active:not(:disabled) { transform: translateY(1px); }
.buy-item:disabled { opacity: 0.5; cursor: not-allowed; }

.buy-item-icon { font-size: 1.15rem; line-height: 1.1; }
.buy-item-text { display: flex; flex-direction: column; min-width: 0; }
.buy-item-name { font-weight: 600; font-size: 0.92rem; }
.buy-item-owned { font-size: 0.72rem; color: var(--muted); }
.buy-item-price { font-size: 0.85rem; color: #ffd166; white-space: nowrap; }

.buy-msg { margin: 8px 0 0; font-size: 0.82rem; }
.buy-msg:empty { margin: 0; }
.buy-msg.warn { color: var(--warn); }
.buy-msg.ok { color: var(--accent); }

/* 잡화점 선반이 비어 있을 때 */
.shelf-empty {
  width: 100%;
  padding: 10px 0;
  list-style: none;
  text-align: center;
  font-size: 0.82rem;
  color: #6b7a85;
}

.scene-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: 58vh;
  background: #101c26;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

#scene-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.loading-mask {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 20px;
  background: rgba(9, 17, 24, 0.84);
  text-align: center;
}

.loading-mask[hidden] { display: none; }

.loading-text { margin: 0; font-size: 0.9rem; }

.loading-track {
  width: min(240px, 70vw);
  height: 8px;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
}

.loading-bar {
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #ffd166);
  border-radius: 999px;
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

.more {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.more > summary {
  padding: 12px 14px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}

.more > summary::-webkit-details-marker { display: none; }
.more > summary::before { content: "▸ "; color: var(--accent); }
.more[open] > summary::before { content: "▾ "; }

.more .search {
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0 0 13px 13px;
}

/* 지역을 고르면 지도가 사라지고 게임 화면만 화면 가득 차지합니다. */
body.playing {
  padding: 0;
  overflow: hidden;
}

body.playing .app {
  max-width: none;
  margin: 0;
}

body.playing .app > h1,
body.playing .app > .sub,
body.playing .app > .source {
  display: none;
}

body.playing #market-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  overflow-y: auto;
  background: radial-gradient(1200px 600px at 50% 0%, #1b2b3b, var(--bg));
}

body.playing .market-head { margin-bottom: 0; }

body.playing .scene-wrap {
  flex: 1 1 auto;
  min-height: 52vh;
  max-height: none;
  aspect-ratio: auto;
}

/* 가게 안에 들어가 있는 동안에는 길거리 장면을 감춥니다. */
.scene-wrap[hidden] { display: none; }

body.playing .more,
body.playing .result { flex: 0 0 auto; }

/* 지역 확정 경고창: 확인해야 시장으로 넘어가고, 확인 후에는 지역을 바꿀 수 없습니다. */
.confirm-mask {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(6, 12, 18, 0.72);
}

.confirm-mask[hidden] { display: none; }

.confirm-box {
  width: min(360px, 100%);
  padding: 18px;
  background: linear-gradient(180deg, #21313f, #16222d);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.confirm-box h2 { margin: 0 0 8px; font-size: 1.05rem; }
.confirm-text { margin: 0; font-size: 0.95rem; }
.confirm-note { margin: 8px 0 0; font-size: 0.82rem; color: var(--warn); }

.confirm-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

.confirm-actions .primary { padding: 8px 22px; }

@media (max-width: 460px) {
  .search { grid-template-columns: 1fr 1fr; }
  .search .primary { grid-column: 1 / -1; }
}
