@font-face {
  font-family: Galmuri11;
  src: url(assets/Galmuri11.woff2) format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: Galmuri11;
  src: url(assets/Galmuri11-Bold.woff2) format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --ink: #3b2b2b;
  --muted: #7a5a45;
  --orange: #f58a1f;
  --orange-d: #cf6410;
  --orange-l: #ffb35c;
  --paper: #fff7ea;
  --cream: #fbe3bf;
  --cream-d: #e9c48e;
  --red: #b3301f;
  --edge: 3px solid var(--ink);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  overscroll-behavior: none;
}
body {
  font: 16.5px/1.35 Galmuri11, system-ui, sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button, input, textarea { font: inherit; color: inherit; border-radius: 0; }
button { cursor: pointer; }
input, textarea { -webkit-user-select: text; user-select: text; }
h1, h2, h3, p { margin: 0; }
small { font-size: 14px; }
.px { image-rendering: pixelated; }
:focus-visible { outline: 3px solid #1e5fc2; outline-offset: 2px; }

#app {
  position: relative;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--cream);
  overflow: hidden;
}

/* ── 위쪽 정보 ── */
#hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px;
  background: var(--orange);
  border-bottom: var(--edge);
}
#shopBtn, #lvBox, #coinBox {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 4px 8px;
  background: var(--paper);
  border: var(--edge);
}
#shopBtn { flex: 1 1 0; min-width: 0; box-shadow: inset 0 -3px 0 var(--cream-d); }
#shopBtn img { width: 28px; height: 28px; flex: none; }
#shopName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
#lvBox { flex-direction: column; align-items: stretch; gap: 2px; width: 76px; justify-content: center; }
#lvNum { font-size: 14px; line-height: 1.1; }
.xpbar { height: 8px; border: 2px solid var(--ink); background: var(--cream); }
.xpbar i { display: block; height: 100%; background: var(--orange); }
#coinBox img { width: 22px; height: 22px; }
#coinBox { min-width: 84px; justify-content: flex-end; }

#hint {
  padding: 6px 10px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  text-align: center;
  text-wrap: balance;
  word-break: keep-all;
}

/* ── 가게 화면 ── */
#stage {
  flex: 1;
  min-height: 0;
  background: conic-gradient(var(--cream) 25%, #f8d9ac 0 50%, var(--cream) 0 75%, #f8d9ac 0) 0 0 / 32px 32px;
  display: grid;
  place-items: center;
}
#cv {
  display: block;
  image-rendering: pixelated;
  touch-action: none;
  outline: var(--edge);
}

/* ── 아래 버튼 ── */
#bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--orange);
  border-top: var(--edge);
}
#bar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 64px;
  padding: 4px 2px 8px;
  background: var(--paper);
  border: var(--edge);
  box-shadow: inset 0 -4px 0 var(--cream-d);
}
#bar button img { width: 32px; height: 32px; object-fit: contain; }
#bar button span { font-size: 14px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#bar button:active, .btn:active, .card:active, .row:active, #shopBtn:active { transform: translateY(2px); box-shadow: none; }
#shopBtn:disabled { color: inherit; cursor: default; }

/* ── 구경 중 표시 ── */
#visitBar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--orange);
  border-top: var(--edge);
}
#visitText {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--paper);
  border: var(--edge);
}
#visitBar .btn { background: var(--paper); box-shadow: inset 0 -3px 0 var(--cream-d); min-height: 52px; }

.btn {
  min-height: 44px;
  padding: 6px 14px 9px;
  background: var(--paper);
  border: var(--edge);
  box-shadow: inset 0 -3px 0 var(--cream-d);
  white-space: nowrap;
}
.btn.primary { background: var(--orange); box-shadow: inset 0 -3px 0 var(--orange-d); font-weight: 700; }
.btn.danger { color: var(--red); }
.btn.big { min-height: 52px; width: 100%; font-size: 22px; }
.coin { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.coin img { width: 18px; height: 18px; }
.muted { color: var(--muted); font-size: 14px; word-break: keep-all; }

/* ── 꾸미기 패널 ── */
#editPanel {
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: var(--edge);
}
.edit-top { display: flex; gap: 8px; align-items: center; }
.tabs { display: flex; flex: 1; min-width: 0; }
.tabs button {
  flex: 1;
  min-height: 44px;
  padding: 4px 2px;
  background: var(--cream);
  border: var(--edge);
  margin-right: -3px;
}
.tabs button[aria-selected="true"] { background: var(--orange); font-weight: 700; }
#editInfo {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 4px 0;
  font-size: 14px;
  word-break: keep-all;
}
#editInfo .grow { flex: 1; min-width: 0; }
#editGroups { padding-bottom: 8px; }
.card.try { background: var(--orange); }
.hscroll { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.card {
  flex: 0 0 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 96px;
  padding: 6px 2px;
  background: var(--cream);
  border: var(--edge);
  box-shadow: inset 0 -3px 0 var(--cream-d);
  font-size: 14px;
  line-height: 1.2;
}
.card img:not(.coin img) { height: 40px; width: 40px; object-fit: contain; }
.card b { font-weight: 400; word-break: keep-all; text-align: center; }
.card.on { background: var(--orange-l); box-shadow: inset 0 0 0 3px var(--paper); }
.card.wide { flex: 1 0 100%; flex-direction: row; justify-content: center; gap: 10px; min-height: 64px; }
.card:disabled, .row:disabled { opacity: 0.5; }

/* ── 아래에서 올라오는 창 ── */
#sheetWrap {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  background: rgba(59, 43, 43, 0.5);
}
#sheet {
  width: 100%;
  max-height: 88%;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-top: var(--edge);
}
/* 꼭 읽어야 하는 창이 뜬 직후: 잠깐 누르기가 안 먹고 단추가 흐리다(ui.js의 hold) */
#sheet.arming { pointer-events: none; }
#sheet.arming .btn { opacity: 0.5; }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--orange);
  border-bottom: var(--edge);
}
.sheet-head h2 { font-size: 22px; line-height: 1.2; }
#sheetBody {
  overflow-y: auto;
  padding: 10px 10px calc(14px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}
#sheetBody > * + * { margin-top: 8px; }
.row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 64px;
  padding: 6px 8px 9px;
  text-align: left;
  background: var(--cream);
  border: var(--edge);
  box-shadow: inset 0 -3px 0 var(--cream-d);
}
.row > img { width: 44px; height: 44px; }
.row .meta { min-width: 0; }
.row .meta b, .row .meta small { display: block; }
.row .meta small { color: var(--muted); }
.row .right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.row.poor .coin { color: var(--red); }
.row.locked { opacity: 0.6; }
.stove-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 2px 0;
  font-size: 14px;
}
.center { text-align: center; }
.center img.hero { width: 96px; height: 96px; object-fit: contain; }
.center img.photo { width: 176px; height: 144px; }
.stack > * + * { margin-top: 8px; }
.pair { display: flex; gap: 8px; }
.pair > * { flex: 1; }
.field { display: block; font-size: 14px; }
.field input, textarea, #intro input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px;
  font-size: 16.5px;
  background: #fff;
  border: var(--edge);
}
textarea { resize: none; }
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-top: 2px dashed var(--cream-d);
}
.list li span { flex: 1; min-width: 0; word-break: break-word; -webkit-user-select: text; user-select: text; }
.list li img { width: 32px; height: 32px; flex: none; object-fit: contain; }
/* 오늘의 주문: 끝낸 주문에만 도장이 또렷하게 찍힌다 */
.goals li img { opacity: 0.25; }
.goals li.done img { opacity: 1; }
.goals li.done span { color: var(--muted); text-decoration: line-through; }
hr { border: 0; border-top: var(--edge); margin: 12px 0; }
.license {
  margin: 0;
  padding: 8px;
  font: 12px/1.5 ui-monospace, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  background: #fff;
  border: var(--edge);
  -webkit-user-select: text;
  user-select: text;
}

#toast {
  position: absolute;
  left: 50%;
  top: calc(112px + env(safe-area-inset-top));
  z-index: 40;
  max-width: 90%;
  padding: 8px 14px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  border: 3px solid var(--paper);
  font-size: 14px;
  text-align: center;
  word-break: keep-all;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
#toast.show { opacity: 1; }

/* ── 요리 창의 나만의 메뉴 ── */
.row-pair { display: flex; gap: 8px; align-items: stretch; }
.row-pair .row { flex: 1; min-width: 0; }
.row-pair .btn { flex: none; }

/* ── 친구 창 ── */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.chip {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 4px 10px 7px;
  background: var(--cream);
  border: var(--edge);
  box-shadow: inset 0 -3px 0 var(--cream-d);
}
.chip img { width: 28px; height: 28px; object-fit: contain; }
.chip.on { background: var(--orange-l); box-shadow: inset 0 0 0 3px var(--paper); }
.wrap { display: flex; flex-wrap: wrap; gap: 8px; }
#sheetBody .card img:not(.coin img) { width: 56px; height: 56px; }

/* ── 아이콘 그리기 ── */
.tiers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tiers .card { min-height: 80px; }
.draw { display: flex; gap: 10px; align-items: flex-start; }
.paper {
  position: relative;
  flex: 1 1 auto;
  max-width: 272px;
  aspect-ratio: 1;
  border: var(--edge);
  background: conic-gradient(#fff 25%, #eee0cc 0 50%, #fff 0 75%, #eee0cc 0) 0 0 / 12.5% 12.5%;
}
.paper canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; touch-action: none; }
.paper::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(59, 43, 43, 0.16) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(59, 43, 43, 0.16) 1px, transparent 1px);
  background-size: calc(100% / 16) calc(100% / 16);
}
.draw-side { flex: 0 0 88px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.draw-side img { width: 64px; height: 64px; background: #d9a56c; border: var(--edge); }
.swatches { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.swatch { aspect-ratio: 1; min-height: 32px; padding: 0; border: var(--edge); }
.swatch.eraser { background: conic-gradient(#fff 25%, #d8c8b0 0 50%, #fff 0 75%, #d8c8b0 0) 0 0 / 50% 50%; }
.swatch.on { outline: 3px solid var(--orange-d); outline-offset: 1px; box-shadow: inset 0 0 0 2px var(--paper); }

/* ── 첫 화면 ── */
#intro {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 24px calc(16px + env(safe-area-inset-bottom));
  background: var(--orange-l);
  text-align: center;
  overflow-y: auto;
}
/* 화면이 넉넉하면 가운데에, 모자라면 위에서부터 스크롤 */
#intro::before, #intro::after { content: ''; flex: 1; }
#intro > * { flex: none; }
#intro > img { width: 96px; height: 96px; object-fit: contain; }
#intro h1 { font-size: 33px; line-height: 1.2; }
#intro p { word-break: keep-all; }
#intro label, #intro .intro-label, #intro .hscroll { width: 100%; max-width: 300px; }
#intro label, #intro .intro-label { display: block; font-size: 14px; text-align: left; }
#intro .intro-label { margin-bottom: -6px; }
#intro .card { background: var(--paper); }
#intro .card.on { background: var(--orange); }
#intro .btn { max-width: 300px; margin-top: 8px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
