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

:root {
  --ink: #1a1423;
  --paper: #fbf7ee;
  --paper2: #efe6d2;
  --line: #3a2f4a;
  --accent: #e8402c;
  --blue: #3b6fd8;
  --hp-g: #3ccf5a; --hp-y: #f2c230; --hp-r: #e8402c;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0e0b16; color: var(--ink); font-family: Galmuri11, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; }
button { font: inherit; color: inherit; }
#app { position: fixed; inset: 0; overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: none; }
#field { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; display: block; }

.back-btn {
  position: absolute; top: 8px; left: 8px; z-index: 30; display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 10px; background: rgba(20, 16, 32, 0.78); color: #fff; text-decoration: none; font-size: 12px;
  border: 2px solid #fff; border-radius: 4px; box-shadow: 0 2px 0 rgba(0,0,0,0.4);
}
.px-btn {
  background: var(--paper); border: 3px solid var(--line); border-radius: 6px; padding: 8px 14px; cursor: pointer;
  box-shadow: 0 3px 0 var(--line); font-weight: 700; font-size: 14px; color: var(--ink);
}
.px-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.px-btn:disabled { opacity: 0.45; cursor: default; }
.px-btn.primary { background: #ffd23f; }
.px-btn.danger { background: #ffb4a8; }
.menu-btn { position: absolute; top: 8px; right: 8px; z-index: 30; padding: 6px 10px; font-size: 13px; }
#hud[hidden] { display: none; }

.map-name {
  position: absolute; top: 46px; left: 8px; z-index: 25; background: var(--paper); border: 3px solid var(--line);
  padding: 6px 12px; font-weight: 700; border-radius: 4px; opacity: 0; transform: translateY(-6px); transition: 0.25s; pointer-events: none;
}
.map-name.show { opacity: 1; transform: none; }

/* 모바일 패드 */
.pad { position: absolute; left: 0; right: 0; bottom: calc(10px + var(--safe-b)); z-index: 20; display: flex; justify-content: space-between; align-items: flex-end; padding: 0 14px; pointer-events: none; }
.pad[hidden] { display: none; }
.dpad { position: relative; width: 138px; height: 138px; pointer-events: auto; }
.dpad .d { position: absolute; width: 46px; height: 46px; background: rgba(26, 20, 35, 0.6); color: #fff; border: 2px solid rgba(255,255,255,0.7); border-radius: 8px; font-size: 16px; touch-action: none; }
.dpad .d.on { background: rgba(255, 210, 63, 0.75); color: var(--ink); }
.dpad .u { left: 46px; top: 0; } .dpad .dn { left: 46px; bottom: 0; } .dpad .l { left: 0; top: 46px; } .dpad .r { right: 0; top: 46px; }
.ab { display: flex; gap: 12px; align-items: flex-end; pointer-events: auto; }
.ab button { width: 60px; height: 60px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.8); font-weight: 700; font-size: 20px; color: #fff; touch-action: none; }
.a-btn { background: rgba(232, 64, 44, 0.75); margin-bottom: 26px; }
.b-btn { background: rgba(59, 111, 216, 0.75); }
.ab button.on { filter: brightness(1.35); }

/* 대화창 */
.dialog {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(12px + var(--safe-b)); z-index: 40;
  width: min(640px, calc(100% - 16px)); min-height: 86px; background: var(--paper); border: 4px solid var(--line); border-radius: 8px;
  padding: 12px 16px 14px; box-shadow: 0 0 0 3px var(--paper) inset, 0 4px 0 rgba(0,0,0,0.35); font-size: 16px; line-height: 1.6; cursor: pointer;
}
.dialog[hidden] { display: none; }
.dialog p { margin: 0; white-space: pre-wrap; word-break: keep-all; }
.dialog .more { position: absolute; right: 12px; bottom: 6px; font-size: 12px; animation: bob 0.7s infinite; visibility: hidden; }
.dialog.done .more { visibility: visible; }
@keyframes bob { 50% { transform: translateY(3px); } }
.choices {
  position: absolute; right: max(8px, calc(50% - 320px)); bottom: calc(118px + var(--safe-b)); z-index: 41; display: flex; flex-direction: column;
  background: var(--paper); border: 4px solid var(--line); border-radius: 8px; padding: 6px; min-width: 140px; box-shadow: 0 4px 0 rgba(0,0,0,0.35);
}
.choices[hidden] { display: none; }
.choices button { background: none; border: 0; text-align: left; padding: 9px 12px 9px 22px; font-size: 15px; cursor: pointer; position: relative; border-radius: 4px; }
.choices button.sel, .choices button:hover { background: var(--paper2); }
.choices button.sel::before { content: '▶'; position: absolute; left: 6px; font-size: 11px; top: 12px; }

/* 전투 */
.battle { position: absolute; inset: 0; z-index: 35; background: #000; display: flex; flex-direction: column; }
.battle[hidden] { display: none; }
#bcv { flex: 1; width: 100%; min-height: 0; image-rendering: pixelated; display: block; }
.info {
  position: absolute; z-index: 2; background: var(--paper); border: 3px solid var(--line); border-radius: 6px; padding: 6px 10px 7px;
  width: min(260px, 46vw); box-shadow: 0 3px 0 rgba(0,0,0,0.35); font-size: 13px;
}
.info.foe { top: 50px; left: 10px; }
.info.me { right: 10px; }
.info .row { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.info .nm { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info .lv { font-size: 12px; white-space: nowrap; }
.hpbar { display: flex; align-items: center; gap: 4px; margin-top: 4px; font-size: 10px; font-weight: 700; }
.hpbar .track { flex: 1; height: 8px; background: #4a3a4a; border: 2px solid var(--line); border-radius: 4px; overflow: hidden; }
.hpbar .fill { height: 100%; background: var(--hp-g); transition: width 0.45s ease-out, background-color 0.2s; }
.hpnum { text-align: right; font-size: 12px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.expbar { height: 4px; background: #c8c0d8; margin-top: 3px; border-radius: 2px; overflow: hidden; }
.expbar i { display: block; height: 100%; background: #3bb8f0; transition: width 0.5s; }
.st { display: inline-block; font-size: 10px; padding: 1px 4px; border-radius: 3px; color: #fff; margin-left: 4px; vertical-align: 1px; }
.st.brn { background: #e8602c; } .st.par { background: #d8a81c; } .st.psn { background: #9a4ad8; } .st.slp { background: #7a7a8a; } .st.fnt { background: #4a4a4a; }
.shiny { color: #e8a020; }
.balls { margin-top: 3px; font-size: 9px; letter-spacing: 1px; }
/* 아래 칸 높이는 늘 같게(메시지 + 명령 2줄) — 바뀌면 위 전투 화면 크기가 달라져 도트링이 커졌다 작아졌다 한다 */
.b-bottom { position: relative; flex: none; box-sizing: border-box; background: var(--paper); border-top: 4px solid var(--line); padding: 10px 12px calc(10px + var(--safe-b)); height: calc(196px + var(--safe-b)); overflow: hidden; }
.b-msg { font-size: 16px; line-height: 1.6; min-height: 52px; white-space: pre-wrap; word-break: keep-all; cursor: pointer; }
.b-cmd { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.b-cmd[hidden] { display: none; }
.b-cmd .px-btn { padding: 10px 8px; font-size: 15px; text-align: center; min-height: 48px; }
.b-cmd .mv { text-align: left; padding: 7px 10px; display: flex; flex-direction: column; gap: 2px; }
.b-cmd .mv small { font-size: 11px; font-weight: 400; display: flex; justify-content: space-between; }
.b-cmd .mv .tp { color: #fff; padding: 0 5px; border-radius: 3px; }
.b-cmd .wide { grid-column: span 2; }
/* 기술 고르기의 '뒤로': 줄을 늘리지 않게 오른쪽 위 작은 버튼으로 */
.b-cmd .back { position: absolute; top: 8px; right: 10px; min-height: 0; padding: 4px 10px; font-size: 12px; }
.b-cmd .sel { outline: 3px solid var(--accent); outline-offset: 1px; }

/* 패널 (메뉴·도감 등) */
.panel { position: absolute; inset: 0; z-index: 45; background: rgba(14, 11, 22, 0.55); display: flex; align-items: center; justify-content: center; padding: 10px; }
.panel[hidden] { display: none; }
.sheet {
  width: min(560px, 100%); max-height: 100%; display: flex; flex-direction: column; background: var(--paper); border: 4px solid var(--line);
  border-radius: 10px; box-shadow: 0 6px 0 rgba(0,0,0,0.4); overflow: hidden;
}
.sheet > header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; background: var(--paper2); border-bottom: 3px solid var(--line); }
.sheet > header h2 { margin: 0; font-size: 17px; }
.sheet .body { overflow-y: auto; padding: 12px; flex: 1; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.sheet .foot { display: flex; gap: 8px; padding: 10px 12px; border-top: 3px solid var(--line); background: var(--paper2); flex-wrap: wrap; }
.close-x { background: var(--paper); border: 3px solid var(--line); border-radius: 6px; width: 36px; height: 36px; font-weight: 700; cursor: pointer; }

.menu-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.menu-grid .px-btn { padding: 14px 8px; font-size: 15px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.menu-grid .px-btn span { font-size: 22px; }
.trainer-card { display: flex; gap: 10px; flex-wrap: wrap; justify-content: space-between; font-size: 13px; background: var(--paper2); border: 3px solid var(--line); border-radius: 6px; padding: 8px 10px; margin-bottom: 10px; }
.badges { display: grid; grid-template-columns: repeat(5, 26px); gap: 4px; }
.badges b { width: 26px; height: 26px; display: grid; place-items: center; border: 2px solid var(--line); border-radius: 50%; background: #d8d0c0; filter: grayscale(1); opacity: 0.4; }
.badges b.on { filter: none; opacity: 1; background: #ffe58a; }

.mon-list { display: flex; flex-direction: column; gap: 8px; }
.mon-row {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 8px; align-items: center; background: #fff; border: 3px solid var(--line); border-radius: 8px;
  padding: 6px 10px 6px 6px; cursor: pointer; text-align: left; width: 100%;
}
.mon-row.lead { background: #fff6d0; }
.mon-row.fainted { background: #e8dede; }
.mon-row.pick { outline: 3px dashed var(--accent); }
.mon-row img { width: 48px; height: 48px; image-rendering: pixelated; }
.mon-row .nm { font-weight: 700; }
.mon-row .sub { font-size: 12px; color: #5a4a6a; }
.mon-row .hpbar { margin-top: 2px; }
.mon-row .right { font-size: 12px; text-align: right; }
.box-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 6px; }
.box-grid button { background: #fff; border: 3px solid var(--line); border-radius: 6px; padding: 2px; cursor: pointer; font-size: 10px; display: flex; flex-direction: column; align-items: center; }
.box-grid img { width: 48px; height: 48px; image-rendering: pixelated; }
.section-t { font-weight: 700; margin: 12px 0 6px; font-size: 14px; }
.section-t:first-child { margin-top: 0; }

.sum-top { display: grid; grid-template-columns: 102px 1fr; gap: 12px; align-items: center; }
.sum-top img { width: 102px; height: 102px; image-rendering: pixelated; background: radial-gradient(circle, #fff 30%, #efe6d2 70%); border: 3px solid var(--line); border-radius: 8px; } /* 그림 96px + 테두리 */
.types { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0; }
.tp { display: inline-block; color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 4px; font-weight: 700; text-shadow: 0 1px 0 rgba(0,0,0,0.35); }
.kv { font-size: 13px; line-height: 1.7; }
.kv small { color: #5a4a6a; }
table.stats { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
table.stats th, table.stats td { padding: 4px 4px; border-bottom: 2px dotted #d8ccb4; text-align: left; }
table.stats td.n { text-align: right; font-variant-numeric: tabular-nums; }
table.stats .bar { height: 6px; background: #e8dfcc; border-radius: 3px; overflow: hidden; min-width: 40px; }
table.stats .bar i { display: block; height: 100%; background: var(--blue); }
.up { color: #d8402c; } .down { color: #3b6fd8; }
.moves { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.move-card { background: #fff; border: 3px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 12px; text-align: left; }
.move-card b { display: block; font-size: 14px; }
.move-card.btn { cursor: pointer; }
.move-card.btn:hover { background: var(--paper2); }

.bag-list, .shop-list { display: flex; flex-direction: column; gap: 6px; }
.item-row { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center; background: #fff; border: 3px solid var(--line); border-radius: 6px; padding: 8px 10px; cursor: pointer; text-align: left; width: 100%; }
.item-row .ic { font-size: 22px; text-align: center; }
.item-row small { display: block; color: #5a4a6a; font-size: 11px; }
.money { font-weight: 700; }

.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.dex-grid button { background: #fff; border: 3px solid var(--line); border-radius: 6px; padding: 3px; font-size: 11px; cursor: pointer; display: flex; flex-direction: column; align-items: center; }
.dex-grid button.none { background: #ddd6c8; }
.dex-grid img { width: 48px; height: 48px; image-rendering: pixelated; }
.dex-grid .no { font-size: 10px; color: #6a5a7a; }

.starters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.starters button { background: #fff; border: 3px solid var(--line); border-radius: 8px; padding: 6px 4px 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; }
.starters button.sel { background: #fff3c0; outline: 3px solid var(--accent); }
.starters img { width: 96px; height: 96px; image-rendering: pixelated; }
.desc { font-size: 13px; line-height: 1.6; background: var(--paper2); border-radius: 6px; padding: 8px 10px; margin-top: 10px; min-height: 56px; }

textarea.code { width: 100%; min-height: 84px; font: 12px/1.4 ui-monospace, Menlo, monospace; border: 3px solid var(--line); border-radius: 6px; padding: 8px; resize: vertical; background: #fff; word-break: break-all; touch-action: auto; user-select: text; -webkit-user-select: text; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.note { font-size: 12px; color: #5a4a6a; line-height: 1.6; }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; margin-top: 8px; }
input.name { font: inherit; font-size: 16px; padding: 8px 10px; border: 3px solid var(--line); border-radius: 6px; width: 100%; user-select: text; -webkit-user-select: text; }
.qty { display: flex; align-items: center; gap: 10px; justify-content: center; margin: 12px 0; font-size: 18px; font-weight: 700; }
.qty button { width: 44px; height: 44px; }

/* 타이틀 */
.title { position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background:
  radial-gradient(circle at 50% 30%, #3a7a4a 0%, #1f4a2c 55%, #0e2416 100%); }
.title[hidden] { display: none; }
.title-card { text-align: center; color: #fff; width: min(420px, 100%); }
.title-card canvas { width: 100%; max-width: 288px; image-rendering: pixelated; }
.title h1 { font-size: 34px; margin: 6px 0 4px; letter-spacing: 2px; text-shadow: 3px 3px 0 #1a1423, 0 0 18px rgba(255, 210, 63, 0.5); color: #ffe58a; }
.title .sub { margin: 0 0 18px; font-size: 13px; opacity: 0.9; }
.title-btns { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.title-btns .px-btn { font-size: 16px; padding: 12px; }
.title .hint { font-size: 11px; opacity: 0.7; margin-top: 16px; line-height: 1.6; }

.toast { position: absolute; top: 54px; left: 50%; transform: translate(-50%, -10px); z-index: 60; background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 6px; font-size: 13px; opacity: 0; transition: 0.25s; pointer-events: none; border: 2px solid #fff; width: max-content; max-width: calc(100% - 24px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.fade { position: absolute; inset: 0; background: #000; z-index: 55; opacity: 0; pointer-events: none; transition: opacity 0.22s; }
.fade.on { opacity: 1; pointer-events: auto; }
.fade.white { background: #fff; }
.error { position: absolute; inset: 0; z-index: 100; background: rgba(14, 11, 22, 0.92); color: #fff; display: grid; place-items: center; text-align: center; padding: 20px; }
.error[hidden] { display: none; }

@media (max-width: 480px) {
  .info { width: 52vw; font-size: 12px; }
  .info.foe { top: 46px; }
  .b-msg { font-size: 15px; }
  .dialog { font-size: 15px; }
  .moves { grid-template-columns: 1fr; }
}
@media (hover: hover) and (pointer: fine) { .pad { display: none !important; } }

/* 희귀도 */
.rar { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; border: 2px solid var(--line); background: #fff; vertical-align: 1px; }
.rar.r-rare { background: #e8f4ff; } .rar.r-starter { background: #e8ffe0; } .rar.r-legend { background: #fff0b8; } .rar.r-myth { background: linear-gradient(90deg, #ffd8f0, #d8f0ff, #e8ffd8); }
.dex-grid button.r-legend:not(.none), .dex-grid button.r-myth:not(.none) { background: #fff6d0; border-color: #c89a1a; }
.dex-grid button.r-starter:not(.none) { background: #eefbe8; }

/* 배속 */
.fast-tag { position: absolute; top: 46px; right: 8px; z-index: 31; background: #ffd23f; color: #1a1423; border: 3px solid var(--line, #3a2f4a); border-radius: 6px; padding: 3px 8px; font-weight: 700; font-size: 12px; pointer-events: none; animation: fastBlink 0.8s infinite; }
.fast-tag[hidden] { display: none; }
@keyframes fastBlink { 50% { opacity: 0.6; } }
.ab .fast-btn { width: 44px; height: 44px; font-size: 16px; background: rgba(40, 32, 56, 0.7); margin-bottom: 70px; }
.ab .fast-btn.lock { background: #ffd23f; color: #1a1423; filter: none; }
