/* DOT MATGO — base.css (foundation): fonts, tokens, stage, pixel widgets */

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

:root {
  /* palette (mirrors DH.PAL) */
  --rust: #be4a2f; --clay: #d77643; --sand: #ead4aa; --tan: #e4a672; --brownL: #b86f50; --brown: #733e39; --brownD: #3e2731;
  --redD: #a22633; --red: #e43b44; --orange: #f77622; --yellow: #feae34; --yellowL: #fee761;
  --green: #63c74d; --greenD: #3e8948; --felt: #265c42; --feltD: #193c3e;
  --blueD: #124e89; --blue: #0099db; --cyan: #2ce8f5;
  --white: #ffffff; --grayL: #c0cbdc; --gray: #8b9bb4; --grayD: #5a6988; --slate: #3a4466; --navy: #262b44; --ink: #181425;
  --hot: #ff0044; --plum: #68386c; --magenta: #b55088; --pink: #f6757a; --skin: #e8b796; --skinD: #c28569;
  --cream: #fff4dc; --gold: #ffd541; --goldD: #c7902a; --skinL: #ffe0c4;
  /* 화투 / 전통 색 (mirrors DG.PAL extras) */
  --hanji: #f4e8cf; --hanjiD: #d9c49b; --hwaRed: #d2232a; --hwaRedD: #8c1220; --hwaBlue: #2b4fa8; --hwaBlueD: #1a2f6b;
  --blanket: #2f6b3f; --blanketD: #1f4a2c; --blanketL: #3f8550; --dokFire: #6cf2ff; --dokFireD: #2a9fd6;
  --jade: #3fb59e; --ochre: #c98f2b; --lilac: #a68bd8; --night: #10162e;

  --paper: var(--hanji);
  --font: 'Galmuri11', 'Galmuri9', ui-monospace, monospace;
  --font-small: 'Galmuri9', 'Galmuri11', monospace;
  --font-title: 'Galmuri14', 'Galmuri11', monospace;
  --font-num: 'GalmuriMono11', 'Galmuri11', monospace;

  /* notched pixel border (2px) */
  --px-border: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink);
  --stage-h: 640px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0b0910;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  overscroll-behavior: none;
}
#app {
  position: fixed; inset: 0; overflow: hidden;
  background-color: #0b0910;
  background-image: radial-gradient(#1c1726 1px, transparent 1px);
  background-size: 8px 8px;
}
#stage {
  position: absolute; left: 0; top: 0; width: 360px; height: var(--stage-h);
  transform-origin: 0 0; overflow: hidden;
  background: var(--navy); color: var(--ink);
  font-family: var(--font); font-size: 12px; line-height: 1.5;
  -webkit-font-smoothing: none; font-smooth: never;
}
#screen-root, #fx-layer, #overlay-root { position: absolute; inset: 0; }
#fx-layer { pointer-events: none; z-index: 50; overflow: hidden; }
#overlay-root { z-index: 100; pointer-events: none; }
#overlay-root > * { pointer-events: auto; }
#screen-fade { position: absolute; inset: 0; background: var(--ink); opacity: 0; pointer-events: none; transition: opacity .18s steps(4); z-index: 90; }
#screen-fade.on { opacity: 1; pointer-events: auto; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; }

canvas.px-art, img.px-art { image-rendering: pixelated; image-rendering: crisp-edges; display: block; flex: none; }

/* ---------- text ---------- */
.t-title { font-family: var(--font-title); font-size: 18px; line-height: 1.3; }
.t-big { font-family: var(--font-title); font-size: 24px; line-height: 1.2; }
.t-small { font-family: var(--font-small); font-size: 10px; line-height: 1.4; }
.t-num { font-family: var(--font-num); }
.t-bold { font-weight: 700; }
.t-center { text-align: center; }
.t-white { color: var(--white); } .t-yellow { color: var(--yellowL); } .t-red { color: var(--red); } .t-green { color: var(--green); }
.t-gray { color: var(--gray); } .t-ink { color: var(--ink); } .t-cyan { color: var(--cyan); }
.t-outline { text-shadow: 1px 0 0 var(--ink), -1px 0 0 var(--ink), 0 1px 0 var(--ink), 0 -1px 0 var(--ink), 1px 1px 0 var(--ink), -1px 1px 0 var(--ink), 1px -1px 0 var(--ink), -1px -1px 0 var(--ink), 0 2px 0 var(--ink); }

/* ---------- panels ---------- */
.px-panel {
  position: relative; background: var(--paper); color: var(--ink);
  margin: 4px; padding: 8px 10px;
  box-shadow: var(--px-border), inset 0 -3px 0 0 rgba(0,0,0,.12), inset 0 2px 0 0 rgba(255,255,255,.6);
}
.px-panel.dark { background: var(--navy); color: var(--white); box-shadow: var(--px-border), inset 0 -3px 0 0 rgba(0,0,0,.3), inset 0 2px 0 0 rgba(255,255,255,.12); }
.px-panel.sand { background: var(--sand); }
.px-panel.felt { background: var(--felt); color: var(--white); }
.px-panel.flat { box-shadow: var(--px-border); }

.px-title-bar {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  background: var(--slate); color: var(--white); box-shadow: 0 2px 0 0 var(--ink), inset 0 -2px 0 0 rgba(0,0,0,.25);
  font-family: var(--font-title); font-size: 15px; z-index: 2;
}

/* ---------- buttons ---------- */
.px-btn {
  font: inherit; font-size: 13px; line-height: 1.2; color: var(--ink);
  background: var(--yellow); border: 0; border-radius: 0; margin: 2px; padding: 7px 12px 9px;
  cursor: pointer; position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  box-shadow: var(--px-border), inset 0 -3px 0 0 rgba(0,0,0,.25), inset 0 2px 0 0 rgba(255,255,255,.4);
  -webkit-appearance: none; appearance: none; outline: none; white-space: nowrap;
}
.px-btn:active { transform: translateY(1px); box-shadow: var(--px-border), inset 0 -1px 0 0 rgba(0,0,0,.25), inset 0 3px 0 0 rgba(0,0,0,.15); }
.px-btn:focus-visible { outline: 2px dashed var(--white); outline-offset: 3px; }
.px-btn.yellow { background: var(--yellow); }
.px-btn.red { background: var(--red); color: var(--white); }
.px-btn.green { background: var(--green); }
.px-btn.blue { background: var(--blue); color: var(--white); }
.px-btn.gray { background: var(--grayL); }
.px-btn.dark { background: var(--slate); color: var(--white); }
.px-btn.white { background: var(--white); }
.px-btn.gold { background: var(--gold); }
.px-btn.small { font-size: 11px; padding: 4px 8px 6px; }
.px-btn.wide { display: flex; width: calc(100% - 4px); }
.px-btn.big { font-family: var(--font-title); font-size: 16px; padding: 10px 16px 12px; }
.px-btn[disabled] { filter: grayscale(1) brightness(.85); opacity: .55; pointer-events: none; }
.px-btn .px-btn-icon { margin: -2px 0; }

/* ---------- inputs ---------- */
.px-input {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--white); border: 0; border-radius: 0;
  padding: 6px 8px; margin: 2px; box-shadow: var(--px-border), inset 0 2px 0 0 rgba(0,0,0,.12); outline: none; width: calc(100% - 4px); /* 100% + the 2px margins stuck out 4px on the right */
  -webkit-user-select: text; user-select: text;
}
.px-slider { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; margin: 0; }
.px-slider::-webkit-slider-runnable-track { height: 6px; background: var(--slate); box-shadow: var(--px-border); }
.px-slider::-moz-range-track { height: 6px; background: var(--slate); box-shadow: var(--px-border); }
.px-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 18px; margin-top: -6px; background: var(--yellow); box-shadow: var(--px-border), inset 0 -3px 0 rgba(0,0,0,.25); border: 0; border-radius: 0; }
.px-slider::-moz-range-thumb { width: 14px; height: 18px; background: var(--yellow); box-shadow: var(--px-border); border: 0; border-radius: 0; }

.px-toggle { display: inline-block; width: 40px; height: 20px; margin: 0 2px; background: var(--grayD); position: relative; box-shadow: var(--px-border); cursor: pointer; flex: none; }   /* 2px side margin like .px-btn: its outline ends on the buttons' edge line */
.px-toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: var(--white); box-shadow: inset 0 -2px 0 rgba(0,0,0,.25); transition: left .1s steps(3); }
.px-toggle.on { background: var(--green); }
.px-toggle.on::after { left: 22px; }

/* ---------- bars & tags ---------- */
.px-bar { height: 8px; background: var(--slate); box-shadow: var(--px-border); position: relative; overflow: hidden; }
.px-bar > .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--green); box-shadow: inset 0 -2px 0 rgba(0,0,0,.25); }
.px-tag { display: inline-block; font-family: var(--font-small); font-size: 10px; padding: 1px 4px; background: var(--slate); color: var(--white); box-shadow: var(--px-border); margin: 2px; }

/* ---------- speech-bubble tail ---------- */
/* A stepped pixel tail pointing left, joined to the bubble's 2px px-border outline: cells in the bubble colour open the outline
   where it meets the bubble and fill a stepped triangle; ink cells draw its edge. On a dark panel the ink disappears like the
   bubble's own outline and the white triangle alone still reads as the tail. Bubbles: position relative + px-border;
   --tail-y = top of the tail, --say-bg = bubble colour (default white). Shape, 2px cells, x = 0 at the bubble's left edge:
        x: -10 -8 -6 -4 -2
     y 0:                K   (outline)
     y 2:             K  W
     y 4:          K  W  W
     y 6:       K  W  W  W
     y 8:   K   K  K  K  K                                                                                                        */
.dc-say::before, .tl-hero-say::before, .hp-cover-say::before {
  --tw: var(--say-bg, var(--white));
  content: ''; position: absolute; left: 0; top: var(--tail-y, 8px); width: 2px; height: 2px; pointer-events: none;
  box-shadow: -2px 2px 0 var(--tw), -2px 4px 0 var(--tw), -4px 4px 0 var(--tw), -2px 6px 0 var(--tw), -4px 6px 0 var(--tw), -6px 6px 0 var(--tw),
    -4px 2px 0 var(--ink), -6px 4px 0 var(--ink), -8px 6px 0 var(--ink),
    -10px 8px 0 var(--ink), -8px 8px 0 var(--ink), -6px 8px 0 var(--ink), -4px 8px 0 var(--ink), -2px 8px 0 var(--ink);
}

/* the same tail turned to point up (on the bubble's top edge) or down (under its bottom edge); x = 0 at the element's left */
.tb-bubble.down::before, .tb-bubble.up::before, .vs-bubble::after {
  --tw: var(--say-bg, var(--white));
  content: ''; position: absolute; width: 2px; height: 2px; pointer-events: none; background: none; clip-path: none; border: 0; margin: 0;
}
.tb-bubble.down::before { top: 0; bottom: auto;
  box-shadow: 2px -2px 0 var(--tw), 4px -2px 0 var(--tw), 4px -4px 0 var(--tw), 6px -2px 0 var(--tw), 6px -4px 0 var(--tw), 6px -6px 0 var(--tw), 2px -4px 0 var(--ink), 4px -6px 0 var(--ink), 6px -8px 0 var(--ink), 8px -10px 0 var(--ink), 8px -8px 0 var(--ink), 8px -6px 0 var(--ink), 8px -4px 0 var(--ink), 8px -2px 0 var(--ink); }
.tb-bubble.up::before, .vs-bubble::after { top: 100%; bottom: auto;
  box-shadow: 2px 0px 0 var(--tw), 4px 0px 0 var(--tw), 4px 2px 0 var(--tw), 6px 0px 0 var(--tw), 6px 2px 0 var(--tw), 6px 4px 0 var(--tw), 2px 2px 0 var(--ink), 4px 4px 0 var(--ink), 6px 6px 0 var(--ink), 8px 8px 0 var(--ink), 8px 6px 0 var(--ink), 8px 4px 0 var(--ink), 8px 2px 0 var(--ink), 8px 0px 0 var(--ink); }

/* ---------- scroll ---------- */
.px-scroll { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; scrollbar-width: none; }
/* no scrollbar track, like the map: phones float their scrollbar over the content (no width), and a desktop 6px track made the
   scrolling content sit 6px off the header / footer lines — hiding it keeps one layout everywhere */
.px-scroll::-webkit-scrollbar { width: 0; height: 0; }

/* ---------- modal & toast ---------- */
.px-modal-backdrop {
  position: absolute; inset: 0; background: rgba(24,20,37,.66); display: flex; align-items: center; justify-content: center;
  animation: px-fade-in .12s steps(3);
}
.px-modal-backdrop.closing { animation: px-fade-out .12s steps(3) forwards; }
.px-modal { width: 300px; max-height: calc(var(--stage-h) - 60px); display: flex; flex-direction: column; animation: px-pop .18s steps(4); }
/* the close button sits INSIDE the top-right corner (26px visual, ~40px hit area via ::before); the title reserves room
   for it and its row is at least as tall as the button, so it never touches the panel border or the first row below */
.px-modal-title { font-family: var(--font-title); font-size: 16px; margin: -2px 36px 8px 0; min-height: 26px; line-height: 26px; }
/* overflow-x: hidden — overflow-y:auto would otherwise make it auto too, and an invisible hit area (e.g. .px-toggle::before)
   reaching past the edge turned the body into a sideways-scrollable strip with a stray scrollbar */
.px-modal-body { white-space: pre-wrap; overflow-x: hidden; overflow-y: auto; font-size: 12px; line-height: 1.6; max-height: calc(var(--stage-h) - 170px);
  padding: 2px; margin: -2px; }   /* 2px inside + 2px outside: content stays put, but a child's 2px outline at the body's edge is no longer clipped */
.px-modal-body:first-child { padding-right: 34px; } /* no title: keep text clear of the × (32px + the 2px negative margin) */
.px-modal-btns { display: flex; justify-content: flex-end; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.px-modal-x { position: absolute !important; right: 8px; top: 7px; }
/* centred with auto margins (not left:50% + translateX): a left:50% box can only shrink-to-fit into the right half
   (180px), so every toast wrapped into a narrow tower; and px-pop's transform no longer knocks it off-centre */
.px-toast {
  position: absolute; left: 0; right: 0; bottom: 90px; margin: 0 auto; width: fit-content; max-width: 300px;
  background: var(--ink); color: var(--white); padding: 6px 10px; font-size: 12px; text-align: center;
  box-shadow: 0 0 0 2px var(--white), 0 0 0 4px var(--ink); animation: px-pop .15s steps(3); pointer-events: none !important;
  transition: opacity .2s steps(3);
}
.px-toast.out { opacity: 0; }

/* ---------- animations ---------- */
@keyframes px-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes px-fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes px-pop { 0% { transform: scale(.85); } 70% { transform: scale(1.04); } 100% { transform: scale(1); } }
@keyframes px-blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes px-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes px-shake { 0%, 100% { transform: translate(0, 0); } 20% { transform: translate(-3px, 1px); } 40% { transform: translate(3px, -1px); } 60% { transform: translate(-2px, -1px); } 80% { transform: translate(2px, 1px); } }
@keyframes px-bounce { 0%, 100% { transform: translateY(0); } 30% { transform: translateY(-6px); } 60% { transform: translateY(0); } 80% { transform: translateY(-2px); } }
.blink { animation: px-blink 1s steps(1) infinite; }
.float { animation: px-float 1.6s steps(4) infinite; }
.shake { animation: px-shake .3s steps(6); }
.pop { animation: px-pop .2s steps(4); }
.fade-in { animation: px-fade-in .25s steps(5); }
.bounce { animation: px-bounce .6s steps(8); }

.hidden { display: none !important; }
.row { display: flex; flex-direction: row; align-items: center; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1 1 auto; min-height: 0; }
.center { display: flex; align-items: center; justify-content: center; }
.gap4 { gap: 4px; } .gap8 { gap: 8px; }

/* ---------- desktop letterbox side panels (landscape only; stage width = 56.25vh there) ---------- */
#stage { box-shadow: 0 0 0 2px #000, 0 0 0 4px #2a2440, 0 18px 60px rgba(0,0,0,.6); }
.desk-side { display: none; }
@media (min-width: 980px) and (min-aspect-ratio: 5/4) {
  .desk-side {
    display: block; position: absolute; top: 50%; transform: translateY(-50%);
    width: calc(50vw - 28.125vh - 64px); max-width: 280px;
    font-family: var(--font); font-size: 13px; line-height: 1.6; color: var(--grayL);
    -webkit-font-smoothing: none;
  }
  #desk-left { right: calc(50vw + 28.125vh + 40px); text-align: right; }
  #desk-right { left: calc(50vw + 28.125vh + 40px); }
  .desk-title { font-family: var(--font-title); font-size: 26px; line-height: 1.2; color: var(--yellow); text-shadow: 0 2px 0 var(--ink), 0 3px 0 var(--redD); margin-bottom: 10px; }
  .desk-title span { display: block; font-size: 15px; color: var(--pink); text-shadow: none; margin-top: 4px; }
  .desk-h { font-family: var(--font-title); font-size: 16px; color: var(--yellow); margin-bottom: 8px; }
  .desk-side p { margin: 0 0 12px; }
  .desk-side ul { list-style: none; margin: 0 0 14px; padding: 0; }
  .desk-side li { margin: 0 0 8px; }
  .desk-side li b { display: block; color: var(--white); font-weight: 700; }
  .desk-keys li { color: var(--grayL); }
  .desk-side kbd {
    display: inline-block; min-width: 18px; padding: 0 5px; margin-right: 4px; text-align: center;
    font: 11px var(--font-num); color: var(--ink); background: var(--grayL);
    box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink), inset 0 -2px 0 rgba(0,0,0,.25);
  }
  .desk-note { font-family: var(--font-small); font-size: 11px; color: var(--gray); }
}
@media (min-width: 980px) and (min-aspect-ratio: 5/4) and (max-height: 520px) { .desk-side { display: none; } }

#debug-hud { position: absolute; right: 2px; top: 2px; z-index: 200; font: 9px var(--font-small); color: var(--yellowL); background: rgba(0,0,0,.5); padding: 1px 3px; pointer-events: none; }

/* landscape phone: rotate hint (toggled by main.js layout) */
#rotate-hint { display: none; }
#rotate-hint.on {
  display: flex; position: fixed; inset: 0; z-index: 1000; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(11, 9, 16, .94); color: var(--yellowL); font: 14px var(--font);
}
#rotate-hint .rh-phone {
  width: 26px; height: 44px; border: 4px solid var(--white); box-shadow: 0 0 0 2px var(--ink);
  background: var(--slate); animation: rh-turn 1.6s steps(4) infinite;
}
@keyframes rh-turn { 0%, 30% { transform: rotate(-90deg); } 60%, 100% { transform: rotate(0deg); } }

/* bigger touch targets without changing the look (TUX-5) */
.px-toggle { overflow: visible; }
.px-toggle::before { content: ''; position: absolute; inset: -10px -6px; }
.px-modal-x { width: 26px; height: 26px; min-width: 26px; min-height: 26px !important; padding: 0 !important; margin: 0 !important; font-size: 14px; line-height: 1; }
.px-modal-x::before { content: ''; position: absolute; inset: -7px; } /* ≈40px tap target */

/* ---------- DOT MATGO additions ---------- */
.px-btn.hwa { background: var(--hwaRed); color: var(--white); }
.px-btn.jade { background: var(--jade); color: var(--ink); }
.px-btn.night { background: var(--night); color: var(--dokFire); }
.px-panel.hanji { background: var(--hanji); }
.px-panel.night { background: var(--night); color: var(--white); box-shadow: var(--px-border), inset 0 -3px 0 0 rgba(0,0,0,.3), inset 0 2px 0 0 rgba(108,242,255,.18); }
.t-hwa { color: var(--hwaRed); } .t-jade { color: var(--jade); } .t-fire { color: var(--dokFire); } .t-gold { color: var(--gold); }
.px-card { flex: none; }
/* HP bar (story duels) */
.px-hp { height: 8px; background: var(--ink); box-shadow: var(--px-border); position: relative; overflow: hidden; }
.px-hp > .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--green); transition: width .35s steps(6); box-shadow: inset 0 -2px 0 rgba(0,0,0,.25); }
.px-hp > .fill.low { background: var(--red); }
.px-hp > .ghost { position: absolute; left: 0; top: 0; bottom: 0; background: var(--yellowL); transition: width .6s .35s steps(8); }
