/* ===================================================================
   Escape the Derpy Dungeon — hand-drawn grimoire design system
   =================================================================== */

@font-face {
  font-family: 'Patrick Hand';
  src: url('assets/fonts/PatrickHand.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Shantell Sans';
  src: url('assets/fonts/ShantellSans.woff2') format('woff2');
  font-weight: 400 800; font-display: swap;
}

:root {
  --paper: #f3e9d2; --paper2: #ece0c4;
  --ink: #2b2622; --line: #2b2622;
  --card: #fbf4e2;
  --teal: #3e7c78; --mustard: #cf8f22; --crimson: #c0473b; --moss: #6e8b3d;
  --gold: #e0a63c;
  --shadow: rgba(43, 38, 34, .22);
  --panel: rgba(251, 244, 226, .82);
  --display: 'Shantell Sans', 'Patrick Hand', 'Comic Sans MS', cursive;
  --body: 'Patrick Hand', 'Comic Sans MS', system-ui, cursive;
}
:root[data-theme='dark'] {
  --paper: #20242a; --paper2: #191c21;
  --ink: #ece2ca; --line: #10130f;
  --card: #2c323b;
  --teal: #5aa39d; --mustard: #e7b552; --crimson: #db6a60; --moss: #93b25e;
  --gold: #e7b552;
  --shadow: rgba(0, 0, 0, .5);
  --panel: rgba(30, 34, 40, .86);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--paper);
  font-size: 18px;
  line-height: 1.35;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
#app { position: fixed; inset: 0; }

/* paper grain over everything */
body::before {
  content: ''; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: url('assets/texture-paper.png');
  background-size: cover; opacity: .5; mix-blend-mode: multiply;
}
:root[data-theme='dark'] body::before { opacity: .28; mix-blend-mode: overlay; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; z-index: 1; }
[hidden] { display: none !important; }

/* ------------------------------- buttons -------------------------------- */
.btn {
  font-family: var(--display); font-weight: 700; font-size: 1.05rem;
  color: var(--ink); background: var(--card);
  border: 2.5px solid var(--line);
  border-radius: 16px 13px 17px 12px;
  padding: .7em 1.1em; cursor: pointer;
  box-shadow: 3px 4px 0 var(--shadow);
  transition: transform .08s ease, box-shadow .08s ease, background .15s;
  text-align: center; width: 100%;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 5px 0 var(--shadow); }
.btn:active { transform: translate(2px, 3px); box-shadow: 1px 1px 0 var(--shadow); }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; transform: none; }
.btn-primary { background: var(--gold); }
.btn-ghost { background: transparent; box-shadow: none; border-style: dashed; }
.btn-danger { background: var(--crimson); color: #fff; }
.danger-text { color: var(--crimson); }
.icon-btn, .mini-btn {
  font-family: var(--display); border: 2.5px solid var(--line); background: var(--card);
  border-radius: 12px 10px 13px 9px; cursor: pointer; color: var(--ink);
}
.icon-btn { width: 44px; height: 44px; font-size: 1.3rem; box-shadow: 2px 3px 0 var(--shadow); }
.mini-btn { padding: .25em .6em; font-size: .82rem; box-shadow: 2px 2px 0 var(--shadow); }
.mini-btn:active, .icon-btn:active { transform: translate(1px, 2px); box-shadow: 0 0 0; }
.mini-btn.disabled, .mini-btn:disabled { opacity: .4; }

/* ------------------------------ dashboard ------------------------------- */
#dashboard {
  align-items: center; justify-content: center; text-align: center;
  background: linear-gradient(rgba(243,233,210,.35), rgba(243,233,210,.7)), url('assets/bg-dashboard.png');
  background-size: cover; background-position: center;
}
:root[data-theme='dark'] #dashboard { background: linear-gradient(rgba(20,22,26,.55), rgba(20,22,26,.82)), url('assets/bg-dashboard.png'); background-size: cover; background-position: center; }
.dash-inner { width: min(440px, 92vw); display: flex; flex-direction: column; gap: 14px; align-items: center; padding: 20px 0; max-height: 100dvh; overflow: auto; }
.logo { width: min(360px, 82vw); filter: drop-shadow(2px 3px 3px var(--shadow)); animation: pop .5s ease; }
.menu { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.menu-row { display: flex; gap: 10px; }
.menu-row .btn { flex: 1; }
.resume-wrap { width: 100%; }
.btn-resume { display: flex; flex-direction: column; gap: 2px; background: var(--moss); color: #fff; border-color: var(--line); animation: breathe 2.4s ease-in-out infinite; }
.btn-resume .btn-title { font-size: 1.15rem; }
.btn-resume .btn-sub { font-family: var(--body); font-weight: 400; font-size: .85rem; opacity: .95; }
.install-btn { background: none; border: none; color: var(--ink); font-family: var(--body); text-decoration: underline; cursor: pointer; opacity: .8; }
.credit { font-size: .75rem; opacity: .7; margin-top: 4px; }
.sw-note { position: absolute; bottom: 8px; left: 8px; right: 8px; font-size: .72rem; opacity: .7; text-align: center; }

/* -------------------------------- game ---------------------------------- */
#game {
  background: linear-gradient(rgba(243,233,210,.4), rgba(243,233,210,.75)), url('assets/bg-room.png');
  background-size: cover; background-position: center;
}
#game[data-room='boss'] { background: linear-gradient(rgba(40,30,30,.5), rgba(30,24,24,.8)), url('assets/bg-boss.png'); background-size: cover; background-position: center; }
:root[data-theme='dark'] #game { background: linear-gradient(rgba(20,22,26,.6), rgba(20,22,26,.85)), url('assets/bg-room.png'); background-size: cover; }

.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 2.5px solid var(--line); backdrop-filter: blur(2px);
}
.hp { display: flex; align-items: center; gap: 8px; flex: 1; }
.hp-heart { color: var(--crimson); font-size: 1.3rem; }
.hp-bar { flex: 1; max-width: 200px; height: 16px; border: 2.5px solid var(--line); border-radius: 10px; background: var(--card); overflow: hidden; }
.hp-fill { display: block; height: 100%; background: var(--crimson); transition: width .4s cubic-bezier(.2,.8,.3,1); }
.hp-num { font-family: var(--display); font-weight: 700; }
.topmeta { display: flex; flex-direction: column; align-items: flex-end; font-size: .78rem; line-height: 1.25; }
.topmeta span { white-space: nowrap; }
.meta-mode { opacity: .75; }

.board { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 14px; overflow: auto; position: relative; }
.board.shake { animation: shake .4s ease; }

.room { display: flex; gap: 12px; align-items: center; justify-content: center; perspective: 900px; }
.boss-room .card { margin-top: 0; }

/* -------------------------------- cards --------------------------------- */
.card {
  --w: min(27vw, 122px);
  width: var(--w); aspect-ratio: 5 / 7; position: relative;
  background: var(--card); border: 2.5px solid var(--line);
  border-radius: 14px 11px 15px 12px;
  box-shadow: 3px 4px 0 var(--shadow);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  animation: deal .4s cubic-bezier(.2,.8,.3,1) backwards;
}
.card.big { --w: min(34vw, 160px); z-index: 2; }
.card:nth-child(1) { transform: rotate(-3deg); animation-delay: .02s; }
.card:nth-child(2) { animation-delay: .1s; }
.card:nth-child(3) { transform: rotate(3deg); animation-delay: .18s; }
.card.clickable { cursor: pointer; }
.card.clickable { animation: deal .4s backwards, wobble 1.6s ease-in-out infinite .6s; }
.card.beaten { filter: grayscale(.6) opacity(.7); transform: rotate(90deg) scale(.82); }
.card.lost { filter: grayscale(.4); outline: 3px dashed var(--crimson); outline-offset: -6px; }
.card-art { position: absolute; inset: 8% 6%; width: 88%; height: 84%; object-fit: contain; }
.card .trap-art { font-size: 2.4rem; }
.corner { position: absolute; font-family: var(--display); font-weight: 800; font-size: 1rem; line-height: .9; display: flex; flex-direction: column; align-items: center; z-index: 3; }
.corner i { font-style: normal; font-size: .85em; }
.corner.tl { top: 5px; left: 7px; } .corner.br { bottom: 5px; right: 7px; transform: rotate(180deg); }
.card.suit-D .corner { color: var(--mustard); } .card.suit-H .corner { color: var(--crimson); } .card.suit-S .corner { color: var(--ink); }
.card-badge { position: absolute; top: 4px; left: 50%; transform: translateX(-50%); font-family: var(--display); font-size: .62rem; font-weight: 700; background: var(--ink); color: var(--paper); padding: 1px 7px; border-radius: 8px; letter-spacing: .5px; z-index: 4; }
.card.big .card-badge { background: var(--crimson); color: #fff; font-size: .7rem; }

.facedown { background: repeating-linear-gradient(45deg, var(--teal), var(--teal) 8px, color-mix(in srgb, var(--teal) 80%, black) 8px, color-mix(in srgb, var(--teal) 80%, black) 16px); }
.card-back { position: absolute; inset: 10px; border: 2.5px dashed var(--paper); border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.card-back span { font-size: 2rem; filter: drop-shadow(1px 1px 0 rgba(0,0,0,.3)); }

/* hand-drawn X: red = cleared/defeated, black = forfeited */
.card-x { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 6; overflow: visible; }
.card-x path { fill: none; stroke-width: 13; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 100; animation: drawx .26s ease forwards; filter: drop-shadow(1px 2px 0 var(--shadow)); }
.card-x path:nth-child(2) { animation-delay: .14s; }
.card-x.red path { stroke: var(--crimson); }
.card-x.black path { stroke: var(--ink); }
@keyframes drawx { to { stroke-dashoffset: 0; } }

/* looted gear drops into its slot */
.slot .card.just-equipped { animation: equipdrop .5s cubic-bezier(.2, .9, .3, 1.15); }
@keyframes equipdrop { 0% { transform: translateY(-140px) scale(1.5) rotate(-8deg); opacity: 0; } 55% { opacity: 1; } 100% { transform: translateY(0) scale(1) rotate(0); } }

.btn small { display: block; font-family: var(--body); font-weight: 400; font-size: .72em; opacity: .8; margin-top: -1px; }

/* ----------------------------- enemy + dice ----------------------------- */
.enemy-panel { text-align: center; display: flex; flex-direction: column; gap: 2px; background: var(--panel); border: 2.5px solid var(--line); border-radius: 14px; padding: 8px 16px; box-shadow: 3px 3px 0 var(--shadow); }
.enemy-name { font-family: var(--display); font-weight: 800; font-size: 1.25rem; }
.enemy-sub { font-size: .82rem; opacity: .85; }
.enemy-sub.suit-D { color: var(--mustard); } .enemy-sub.suit-H { color: var(--crimson); }
.enemy-req { font-size: .82rem; opacity: .8; }

.dice { display: flex; gap: 12px; }
.dice.placeholder .die { opacity: .35; }
.die { width: 46px; height: 46px; background: var(--card); border: 2.5px solid var(--line); border-radius: 10px 8px 11px 9px; display: grid; grid-template-columns: repeat(3, 1fr); padding: 6px; gap: 1px; box-shadow: 2px 3px 0 var(--shadow); }
.die.rolled { animation: tumble .4s ease; }
.die i { display: block; border-radius: 50%; }
.die i.on { background: var(--ink); }
.roll-outcome { font-family: var(--display); font-weight: 700; text-align: center; background: var(--panel); border-radius: 10px; padding: 4px 12px; }

/* -------------------------------- tray ---------------------------------- */
.tray { display: flex; gap: 12px; }
.slot { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; background: var(--panel); border: 2.5px dashed var(--line); border-radius: 14px; padding: 6px 10px; min-width: 92px; }
.slot .card { --w: 58px; animation: none; transform: none; box-shadow: 2px 2px 0 var(--shadow); }
.slot-label { font-size: .72rem; text-transform: uppercase; letter-spacing: 1px; opacity: .7; }
.slot-ph { font-size: 1.6rem; opacity: .4; height: 58px; display: flex; align-items: center; }
.slot.empty { opacity: .8; }

/* ------------------------------ action bar ------------------------------ */
.actionbar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--panel); border-top: 2.5px solid var(--line); min-height: 62px; }
.actionbar .btn { width: auto; flex: 0 1 auto; }
.big-roll { font-size: 1.25rem; padding: .7em 1.6em; animation: breathe 1.8s ease-in-out infinite; }
.act-heal { background: var(--moss); color: #fff; }
.hint { font-size: .9rem; opacity: .85; text-align: center; flex-basis: 100%; }
.logline { text-align: center; font-size: .82rem; padding: 4px 12px 8px; opacity: .8; min-height: 1.4em; background: var(--panel); }

.loot-pool { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; flex-basis: 100%; }
.pool-card { display: inline-flex; align-items: center; gap: 6px; background: var(--card); border: 2px solid var(--line); border-radius: 10px; padding: 4px 8px; }
.pool-card.pool-junk { opacity: .6; } .pool-card i { font-style: italic; font-size: .78rem; }
.pool-used { opacity: .5; padding: 4px 8px; }

/* ------------------------------- overlays ------------------------------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(20,18,14,.55); backdrop-filter: blur(3px); animation: fade .2s ease; }
.sheet { width: min(480px, 94vw); max-height: 92dvh; overflow: auto; background: var(--paper2); border: 3px solid var(--line); border-radius: 20px 16px 22px 18px; box-shadow: 6px 8px 0 rgba(0,0,0,.35); padding: 20px; display: flex; flex-direction: column; gap: 12px; animation: pop .28s cubic-bezier(.2,.9,.3,1.2); }
.sheet-title { font-family: var(--display); font-weight: 800; font-size: 1.6rem; text-align: center; }
.sheet-title.win { color: var(--moss); } .sheet-title.lose { color: var(--crimson); }
.muted { opacity: .7; font-size: .88rem; text-align: center; }

.mode-list { display: flex; flex-direction: column; gap: 10px; }
.mode-card { text-align: left; display: flex; flex-direction: column; gap: 2px; font-family: var(--body); background: var(--card); border: 2.5px solid var(--line); border-radius: 14px; padding: 12px 14px; cursor: pointer; box-shadow: 3px 3px 0 var(--shadow); }
.mode-card b { font-family: var(--display); font-size: 1.2rem; } .mode-card span { font-size: .85rem; opacity: .8; }
.mode-card.featured { background: var(--gold); }
.mode-card:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--shadow); }

.set-list { display: flex; flex-direction: column; gap: 8px; }
.set-row { display: flex; justify-content: space-between; align-items: center; font-family: var(--body); font-size: 1rem; background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 10px 14px; cursor: pointer; }
.set-row.static { cursor: default; }
.switch { font-family: var(--display); font-size: .8rem; padding: 2px 10px; border-radius: 10px; background: #bbb4a3; color: #fff; }
.switch.on { background: var(--moss); }
.chips { display: flex; gap: 6px; } .chip { font-family: var(--display); font-size: .8rem; border: 2px solid var(--line); background: var(--card); border-radius: 10px; padding: 3px 9px; cursor: pointer; }
.chip.sel { background: var(--gold); }
.version { text-align: center; font-size: .7rem; opacity: .6; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 8px; text-align: center; }
.stat span { display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .5px; opacity: .7; }
.stat b { font-family: var(--display); font-size: 1.35rem; }

.ach-list { display: flex; flex-direction: column; gap: 8px; }
.ach-count { font-size: 1rem; opacity: .7; }
.ach { display: flex; gap: 10px; align-items: center; background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.ach.locked { opacity: .55; } .ach-emoji { font-size: 1.6rem; }
.ach-text { display: flex; flex-direction: column; } .ach-text b { font-family: var(--display); } .ach-text i { font-style: normal; font-size: .8rem; opacity: .8; }

.how { font-size: .95rem; display: flex; flex-direction: column; gap: 8px; }
.how ul { padding-left: 18px; display: flex; flex-direction: column; gap: 3px; }
.suit-D { color: var(--mustard); font-weight: 700; } .suit-H { color: var(--crimson); font-weight: 700; } .suit-S { color: var(--ink); font-weight: 700; }

.end-screen { display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center; }
.end-art { width: 100%; max-height: 34vh; object-fit: cover; border: 2.5px solid var(--line); border-radius: 14px; box-shadow: 3px 4px 0 var(--shadow); }
.end-sub { font-size: 1rem; } .end-sub b { color: var(--moss); }
.end-stats { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; font-size: .85rem; }
.end-stats b { font-family: var(--display); font-size: 1.2rem; display: block; }
.fresh-ach { background: var(--gold); border: 2.5px solid var(--line); border-radius: 12px; padding: 8px 12px; width: 100%; }
.fresh-ach h3 { font-family: var(--display); font-size: 1rem; margin-bottom: 4px; }
.ach-chip { display: inline-block; background: var(--card); border: 2px solid var(--line); border-radius: 10px; padding: 3px 8px; margin: 2px; font-size: .85rem; }
.end-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; width: 100%; }
.end-actions .btn { flex: 1 1 auto; }
.daily-date { text-align: center; font-family: var(--display); font-size: 1.2rem; } .daily-done { text-align: center; font-size: 1.05rem; }

/* -------------------------------- toasts -------------------------------- */
.toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { font-family: var(--display); font-weight: 700; background: var(--ink); color: var(--paper); border-radius: 12px; padding: 8px 16px; box-shadow: 3px 4px 0 rgba(0,0,0,.35); animation: drop .3s ease; }
.toast.out { animation: fade .4s ease forwards reverse; opacity: 0; }

/* ------------------------------ animations ------------------------------ */
@keyframes deal { from { opacity: 0; transform: translateY(30px) rotate(0) scale(.9); } }
@keyframes pop { from { opacity: 0; transform: scale(.85); } }
@keyframes fade { from { opacity: 0; } }
@keyframes drop { from { opacity: 0; transform: translateY(-14px); } }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.035); } }
@keyframes wobble { 0%,100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes tumble { 0% { transform: rotate(-40deg) scale(.7); } 60% { transform: rotate(12deg) scale(1.08); } 100% { transform: rotate(0) scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-9px) rotate(-1deg); } 40% { transform: translateX(8px) rotate(1deg); } 60% { transform: translateX(-6px); } 80% { transform: translateX(5px); } }

.reduce-motion *, .reduce-motion *::before { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; }

/* ------------------------------ responsive ------------------------------ */
@media (min-width: 720px) {
  body { font-size: 19px; }
  .card { --w: 130px; } .card.big { --w: 168px; }
  .board { gap: 20px; }
  .room { gap: 18px; }
}
@media (max-height: 620px) {
  .card { --w: min(22vw, 96px); } .card.big { --w: min(28vw, 120px); }
  .board { gap: 8px; padding: 8px; }
  .slot .card { --w: 46px; } .slot-ph { height: 46px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .board { flex-direction: row; flex-wrap: wrap; }
}
