/* ============================================================
   DICE FOUNDRY — style.css
   Pixel art: Minifantasy by Krishna Palacio
   ============================================================ */

:root {
  --ink: #2a1c14;
  --parch: #c8945a;
  --parch-light: #e8c498;
  --gold: #f0c053;
  --ember: #e07438;
  --dark: #16121f;
  --darker: #0e0b16;
  --steel: #8e8ba4;
  --fit: 1;
}

* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }

html, body { height: 100%; }

body {
  background: var(--darker);
  background-image:
    radial-gradient(ellipse at 50% -20%, #2b2138 0%, transparent 60%),
    radial-gradient(ellipse at 50% 120%, #1d1428 0%, transparent 55%);
  color: var(--parch-light);
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: bold;
  overflow: hidden;
}

.hidden { display: none !important; }

img, canvas, .sprite, #scene, #scene * { image-rendering: pixelated; image-rendering: crisp-edges; }

/* ============ Minifantasy-skinned widgets ============ */

.mf-panel {
  border-style: solid;
  border-width: 12px;
  border-image: url(assets/panel.png) 16 fill stretch;
  color: var(--ink);
}

.mf-panel.light { border-image: url(assets/panel_light.png) 16 fill stretch; }

.mf-btn {
  border-style: solid;
  border-width: 6px 8px;
  border-image: url(assets/btn.png) 6 8 fill stretch;
  background: none;
  font-family: inherit;
  font-weight: bold;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--ink);
  cursor: pointer;
  padding: 1px 6px;
  line-height: 1.2;
}
.mf-btn:hover  { border-image: url(assets/btn_hover.png) 6 8 fill stretch; }
.mf-btn:active { border-image: url(assets/btn_down.png) 6 8 fill stretch; transform: translateY(1px); }
.mf-btn:disabled { opacity: .45; cursor: not-allowed; }
.mf-btn.big { font-size: 18px; padding: 6px 18px; }

.mf-bar {
  border-style: solid;
  border-width: 8px 8px;
  border-image: url(assets/bar_frame.png) 3 4 fill stretch;
  height: 22px;
  position: relative;
  overflow: hidden;
  background: #3a2a20;
  background-clip: padding-box;
  margin: 6px 0;
}
.mf-bar-fill {
  position: absolute; inset: -5px;
  width: 0%;
  background: linear-gradient(180deg, #ffd86e 0%, var(--ember) 55%, #a03c20 100%);
  transition: width .12s steps(8);
}

h2 {
  font-size: 11px;
  letter-spacing: 2px;
  color: #5a3520;
  border-bottom: 2px solid rgba(90,53,32,.35);
  margin: 8px 0 6px;
  padding-bottom: 2px;
}

/* ============ Title screen ============ */

#title-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(224,116,56,.18) 0%, transparent 55%),
    var(--darker);
  z-index: 50;
}
.title-inner { text-align: center; max-width: 560px; padding: 24px; }
#title-dice { width: 528px; height: 80px; max-width: 90vw; }
#title-screen h1 {
  font-size: 54px;
  letter-spacing: 8px;
  color: var(--gold);
  text-shadow: 0 4px 0 #7a3b16, 0 8px 0 #2a1408, 0 0 28px rgba(240,192,83,.35);
  margin: 6px 0 4px;
}
.tagline { color: var(--steel); font-size: 14px; margin-bottom: 26px; }
.title-row { margin-top: 14px; display: flex; gap: 12px; justify-content: center; }
.title-credit { margin-top: 34px; color: #6b6580; font-size: 12px; }

/* ============ HUD ============ */

#app { display: flex; flex-direction: column; height: 100vh; }

#hud {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px 4px;
  gap: 12px;
}
.hud-left { display: flex; align-items: center; gap: 16px; min-width: 300px; }
.hud-gold { display: flex; align-items: center; gap: 8px; font-size: 22px; color: var(--gold); }
.pouch { width: 32px; height: 32px; }
.hud-gps { color: var(--steel); font-size: 14px; }
.hud-cores { color: #9ecbff; font-size: 16px; }
.hud-title {
  font-size: 20px; letter-spacing: 6px; color: var(--gold);
  text-shadow: 0 2px 0 #7a3b16, 0 0 14px rgba(240,192,83,.3);
}
.hud-right { display: flex; align-items: center; gap: 8px; min-width: 300px; justify-content: flex-end; }
#dial {
  width: 32px; height: 32px;
  background: url(assets/dial.png) 0 0 / 800px 32px no-repeat;
}

/* ============ Main columns ============ */

#game-row {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 4px 10px 10px;
  min-height: 0;
}

#left-col, #right-col {
  width: 252px;
  flex: 0 0 252px;
  padding: 6px 10px;
  overflow-y: auto;
  font-size: 12px;
  scrollbar-width: thin;
  scrollbar-color: #7a4a28 transparent;
}

#scene-col {
  flex: 0 1 auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

/* ============ The foundry scene ============ */

#scene-wrap {
  position: relative;
  width: 576px;
  height: 768px;
  transform: scale(var(--fit));
  transform-origin: top center;
  filter: drop-shadow(0 0 24px rgba(224,116,56,.12));
}

#scene {
  position: absolute; top: 0; left: 0;
  width: 144px; height: 192px;
  transform: scale(4);
  transform-origin: 0 0;
}
#scene.shake { animation: shake .55s linear; }
@keyframes shake {
  0%,100% { transform: scale(4) translate(0,0); }
  10% { transform: scale(4) translate(-1.2px,.8px); } 25% { transform: scale(4) translate(1.2px,-.9px); }
  40% { transform: scale(4) translate(-1px,-.7px); }  55% { transform: scale(4) translate(1px,.9px); }
  70% { transform: scale(4) translate(-.7px,.5px); }  85% { transform: scale(4) translate(.6px,-.4px); }
}

#floor { position: absolute; inset: 0; background: url(assets/floor_0.png); }

/* --- animated sprite props (all source-pixel sized, steps() loops) --- */

.torch {
  position: absolute; width: 24px; height: 32px;
  background: url(assets/torch.png) 0 0 no-repeat;
  animation: torch-a .9s steps(8) infinite;
}
@keyframes torch-a { to { background-position-x: -192px; } }

#furnace {
  position: absolute; left: 58px; top: 12px;
  width: 28px; height: 40px;
  background: url(assets/furnace_0.png) no-repeat;
}
#fire {
  position: absolute; left: 60px; top: 28px;
  width: 24px; height: 16px;
  background: url(assets/fire.png) no-repeat;
  background-position: 0 -16px;
  animation: fire-a .8s steps(8) infinite;
  transform-origin: 50% 100%;
}
@keyframes fire-a { to { background-position: -192px -16px; } }
#fire-glow {
  position: absolute; left: 60px; top: 2px;
  width: 24px; height: 48px;
  background: url(assets/fire_glow.png) no-repeat;
  animation: fire-a2 .8s steps(8) infinite;
  mix-blend-mode: screen;
  opacity: .85;
}
@keyframes fire-a2 { to { background-position-x: -192px; } }
#embers {
  position: absolute; left: 60px; top: 2px;
  width: 24px; height: 48px;
  background: url(assets/embers.png) no-repeat;
  animation: fire-a2 1.1s steps(8) infinite;
}
#steam {
  position: absolute; left: 52px; top: -6px;
  width: 40px; height: 40px;
  background: url(assets/steam.png) no-repeat;
  animation: steam-a 1.2s steps(8) infinite;
  opacity: 0;
}
#steam.on { opacity: .9; }
@keyframes steam-a { to { background-position-x: -320px; } }

#belt { position: absolute; left: 64px; top: 52px; width: 16px; height: 48px; }
.belt-tile {
  position: absolute; width: 16px; height: 16px; left: 0;
  background: url(assets/belt.png) no-repeat;
  animation: belt-a .45s steps(3) infinite;
}
@keyframes belt-a { to { background-position-x: -48px; } }

.anvil { position: absolute; width: 24px; height: 20px; background: url(assets/anvil_0.png) no-repeat; }

#smith {
  position: absolute; left: 82px; top: 36px;
  width: 32px; height: 32px;
  background: url(assets/smith.png) no-repeat;
  animation: smith-a .7s steps(6) infinite;
}
@keyframes smith-a { to { background-position-x: -192px; } }

.dwarf {
  position: absolute; width: 32px; height: 32px;
  background: url(assets/dwarf_hammer.png) no-repeat;
  animation: dwarf-a .8s steps(6) infinite;
}
.dwarf.flip { transform: scaleX(-1); }
@keyframes dwarf-a { to { background-position-x: -192px; } }

.engine {
  position: absolute; width: 24px; height: 48px;
  background-image: url(assets/engine_0.png);
  animation: engine-a .7s steps(6) infinite;
}
@keyframes engine-a { to { background-position-x: -144px; } }

.ore { position: absolute; width: 32px; height: 32px; background: url(assets/ore_0.png) no-repeat; }
.ore-a { left: 6px; top: 152px; }
.ore-b { left: 106px; top: 152px; background-image: url(assets/ore_1.png); }

.burst {
  position: absolute; width: 32px; height: 32px;
  background: url(assets/burst_fire.png) no-repeat;
  animation: burst-a .75s steps(15) forwards;
  pointer-events: none;
}
@keyframes burst-a { to { background-position-x: -480px; } }

/* --- the clickable forge --- */
#forge-hit {
  position: absolute; left: 52px; top: 8px;
  width: 40px; height: 48px;
  background: none; border: none; cursor: pointer;
  outline: none;
}
#forge-hit:hover { filter: drop-shadow(0 0 4px rgba(240,192,83,.4)); }
#forge-hit.clank { animation: clank .12s linear; }
@keyframes clank {
  30% { transform: translate(0,1px); }
}

/* --- dice --- */
#dice-layer { position: absolute; inset: 0; pointer-events: none; }
.die {
  position: absolute; width: 16px; height: 16px;
  transition: transform .1s linear;
}
.die.pop { animation: die-pop .35s ease-out; }
@keyframes die-pop {
  0% { transform: scale(1); } 40% { transform: scale(1.45); } 100% { transform: scale(1); }
}
.die.maxed { animation: die-max .5s ease-out; }
@keyframes die-max {
  0% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(240,192,83,0)); }
  40% { transform: scale(1.6); filter: drop-shadow(0 0 4px rgba(240,192,83,1)); }
  100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(240,192,83,0)); }
}

/* ============ FX overlay (unscaled, crisp text) ============ */

#fx-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.float-text {
  position: absolute;
  font-size: 15px; font-weight: bold;
  color: var(--gold);
  text-shadow: 0 2px 0 #000, 0 0 6px rgba(0,0,0,.8);
  animation: float-up 1.1s ease-out forwards;
  white-space: nowrap;
}
.float-text.crit { color: #ff9c4a; font-size: 19px; }
.float-text.forge { color: #b8e0ff; }
@keyframes float-up {
  0% { opacity: 0; transform: translateY(6px) scale(.8); }
  15% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-46px) scale(1); }
}

.coin {
  position: absolute; width: 10px; height: 10px;
  background: radial-gradient(circle at 35% 30%, #ffe9a0 0%, #f0c053 45%, #9c6a1e 100%);
  border: 2px solid #5e3c10;
  border-radius: 50%;
  pointer-events: none;
}

#jackpot-banner {
  position: absolute; top: 38%; left: 50%;
  transform: translate(-50%,-50%) rotate(-4deg);
  font-size: 44px; letter-spacing: 4px;
  color: var(--gold);
  text-shadow: 0 4px 0 #7a3b16, 0 0 30px rgba(240,192,83,.9);
  animation: jackpot-a 2.4s ease-out forwards;
  pointer-events: none;
  z-index: 5;
}
@keyframes jackpot-a {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(.3) rotate(-4deg); }
  12% { opacity: 1; transform: translate(-50%,-50%) scale(1.15) rotate(-4deg); }
  20% { transform: translate(-50%,-50%) scale(1) rotate(-4deg); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%,-58%) scale(1) rotate(-4deg); }
}

/* ============ Left column ============ */

#blueprints { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; }
.bp-tab {
  border-style: solid; border-width: 6px 8px;
  border-image: url(assets/btn.png) 6 8 fill stretch;
  font-family: inherit; font-weight: bold; font-size: 12px;
  color: var(--ink); cursor: pointer; text-align: center; padding: 2px 0;
}
.bp-tab.sel { border-image: url(assets/btn_down.png) 6 8 fill stretch; color: #7a2410; }
.bp-tab.locked { opacity: .5; }
.bp-tab:hover { border-image: url(assets/btn_hover.png) 6 8 fill stretch; }
.bp-tab.sel:hover { border-image: url(assets/btn_down.png) 6 8 fill stretch; }

#bp-detail { margin-top: 6px; line-height: 1.5; }
#bp-detail .bp-name { font-size: 14px; color: #7a2410; }
#bp-detail .row { display: flex; justify-content: space-between; }
#bp-detail .afford { color: #1d6b2a; }
#bp-detail .broke { color: #a02020; }

#job-line { min-height: 16px; }
#job-hint { font-size: 10px; color: #5a3520; }

#odds-bars { display: flex; align-items: flex-end; gap: 3px; height: 56px; padding-top: 4px; }
.odds-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.odds-col .bar { width: 100%; background: linear-gradient(180deg,#ffd86e,#b35c24); border: 1px solid #5e3c10; }
.odds-col .lbl { font-size: 9px; color: #5a3520; }

/* ============ Right column ============ */

.upg {
  display: grid;
  grid-template-columns: 36px 1fr 64px;
  gap: 6px; align-items: center;
  padding: 5px 2px;
  border-bottom: 2px solid rgba(90,53,32,.25);
}
.upg-icon { width: 36px; height: 36px; }
.upg-name { font-size: 12px; color: #4a2a16; }
.upg-desc { font-size: 10px; font-weight: normal; color: #6b4a30; line-height: 1.25; }
.upg-lvl { color: #7a2410; }
.upg button { width: 100%; font-size: 10px; padding: 2px 0; }
.upg .cost { display: block; font-size: 10px; }

#mini-stats { margin-top: 8px; }
.ms-row { display: flex; justify-content: space-between; padding: 2px 0; }
.ms-row b { color: #7a2410; }

/* ============ Modals ============ */

#modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10,8,18,.78);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
#modal { width: 440px; max-width: 92vw; max-height: 84vh; overflow-y: auto; padding: 10px 14px; font-size: 13px; }
#modal h2 { font-size: 14px; }
#modal-body { line-height: 1.6; color: var(--ink); }
#modal-body table { width: 100%; border-collapse: collapse; }
#modal-body td { padding: 2px 4px; border-bottom: 1px solid rgba(90,53,32,.25); }
#modal-body td:last-child { text-align: right; color: #7a2410; }
#modal-body .warn { color: #a02020; }
#modal-body .good { color: #1d6b2a; }
#modal-buttons { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }

/* ============ Fit small screens ============ */
@media (max-height: 880px) { :root { --fit: .86; } #scene-col { min-width: 500px; } }
@media (max-height: 760px) { :root { --fit: .72; } #scene-col { min-width: 420px; } }
