:root {
  --stone-1: #2b2620;   /* raised stone */
  --stone-2: #201b16;   /* slab body */
  --stone-3: #17130f;   /* recessed / dark */
  --edge-dark: #0c0908; /* carved shadow line */
  --edge-light: rgba(226, 205, 170, 0.06); /* top highlight */
  --ash: #cdbfa8;       /* primary text */
  --ash-soft: #8f8168;  /* muted text */
  --ember: #e8912f;
  --ember-dark: #c56a24;
  --gold: #e6c05a;
  --blood: #a5281c;
  --steel: #8fb3c9;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  /* faint grayscale grain, baked in and shown through translucent slab gradients */
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background:
    radial-gradient(135% 95% at 50% 125%, rgba(214, 108, 42, 0.10), transparent 55%),
    linear-gradient(rgba(6, 5, 4, 0.9), rgba(6, 5, 4, 0.9)),
    var(--noise),
    #070504;
  background-size: auto, auto, 200px 200px, auto;
  background-attachment: fixed, fixed, fixed, fixed;
  color: var(--ash);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.game { max-width: 1060px; margin: 0 auto; padding: 1.5rem 1.25rem 2.5rem; }

/* carved stone slab */
.stone {
  position: relative;
  background:
    linear-gradient(158deg, rgba(43, 38, 32, 0.94), rgba(23, 19, 15, 0.97)),
    var(--noise);
  background-size: auto, 200px 200px;
  border: 1px solid var(--edge-dark);
  border-radius: 7px;
  box-shadow:
    inset 0 1px 0 var(--edge-light),
    inset 0 0 34px rgba(0, 0, 0, 0.55),
    0 10px 26px -14px rgba(0, 0, 0, 0.9);
}

/* --- top bar --- */
.topbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand .logo { font-size: 1.7rem; filter: drop-shadow(0 0 7px rgba(232, 145, 47, 0.6)); }
.brand h1 { margin: 0; font-family: var(--serif); font-size: 1.7rem; font-weight: 700; letter-spacing: 0.02em; color: #e9ddc6; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6); }

.stats { display: flex; gap: 0.55rem; flex-wrap: wrap; }
.stat {
  display: flex; flex-direction: column; align-items: flex-start; min-width: 76px; padding: 0.4rem 0.7rem;
  background: linear-gradient(160deg, var(--stone-1), var(--stone-3));
  border: 1px solid var(--edge-dark); border-radius: 6px;
  box-shadow: inset 0 1px 0 var(--edge-light);
}
.stat.hint-stat { cursor: help; }
.stat .k { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ash-soft); }
.stat .v { font-size: 1.05rem; font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }
#souls { color: var(--ember); }

/* --- offline banner --- */
.offline-banner {
  margin-bottom: 1rem; padding: 0.6rem 1rem;
  background: linear-gradient(90deg, rgba(214, 108, 42, 0.22), rgba(214, 108, 42, 0.05));
  border: 1px solid var(--ember-dark); border-radius: 6px;
  color: var(--gold); font-size: 0.9rem; font-weight: 600; text-align: center;
}

/* --- board --- */
.board { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }

/* --- arena --- */
.arena { display: flex; flex-direction: column; align-items: center; padding: 1.25rem 1.25rem 1.5rem; text-align: center; }
.arena-head { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.5rem; }
.navbtn {
  width: 30px; height: 30px; border: 1px solid var(--edge-dark);
  background: linear-gradient(160deg, var(--stone-1), var(--stone-3)); color: var(--ash);
  border-radius: 5px; cursor: pointer; font-size: 0.7rem; line-height: 1;
  box-shadow: inset 0 1px 0 var(--edge-light);
  transition: color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.navbtn:hover:not(:disabled) { color: var(--ember); border-color: var(--ember-dark); }
.navbtn:disabled { opacity: 0.3; cursor: default; }
.lvl-badge {
  font-family: var(--serif); font-size: 0.85rem; letter-spacing: 0.04em; color: var(--ash);
  border: 1px solid var(--edge-dark); border-radius: 4px; padding: 0.2rem 0.8rem; min-width: 98px;
  background: linear-gradient(160deg, var(--stone-1), var(--stone-3)); box-shadow: inset 0 1px 0 var(--edge-light);
}
.arena.lord .lvl-badge { color: var(--gold); border-color: rgba(230, 192, 90, 0.5); box-shadow: inset 0 1px 0 var(--edge-light), 0 0 14px rgba(230, 192, 90, 0.25); }

.auto-toggle { display: inline-flex; align-items: center; gap: 0.45rem; margin-bottom: 0.6rem; font-size: 0.8rem; color: var(--ash-soft); cursor: pointer; user-select: none; }
.auto-toggle input { width: 16px; height: 16px; accent-color: var(--ember); cursor: pointer; }

/* boss framed in a stone medallion */
.boss-frame {
  position: relative; padding: 12px; margin: 0.3rem 0 1rem; border-radius: 50%;
  background: radial-gradient(circle, var(--stone-3), var(--stone-2));
  box-shadow: inset 0 0 0 2px var(--edge-dark), inset 0 0 22px rgba(0, 0, 0, 0.7), 0 0 0 1px var(--edge-light);
}
.float-layer { position: absolute; inset: 0; overflow: visible; pointer-events: none; }

.boss {
  position: relative; display: block; width: 176px; height: 176px; border: none; border-radius: 50%; cursor: pointer;
  background:
    radial-gradient(circle at 50% 40%, rgba(232, 145, 47, 0.30), transparent 62%),
    radial-gradient(circle at 50% 50%, #2c211a, #150e0a 72%);
  box-shadow: 0 0 0 2px var(--edge-dark), 0 12px 26px -14px rgba(0, 0, 0, 0.9), inset 0 0 40px rgba(0, 0, 0, 0.6);
  transition: transform 0.08s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.boss:hover { box-shadow: 0 0 0 2px var(--ember-dark), 0 0 26px -4px rgba(214, 108, 42, 0.5), inset 0 0 40px rgba(0, 0, 0, 0.6); }
.boss:active { transform: scale(0.95); }
.boss-emoji { font-size: 4.4rem; line-height: 1; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.65)); }
.arena.lord .boss { box-shadow: 0 0 0 2px var(--gold), 0 0 32px -2px rgba(230, 192, 90, 0.45), inset 0 0 40px rgba(0, 0, 0, 0.6); animation: lordPulse 2.2s ease-in-out infinite; }
@keyframes lordPulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--gold), 0 0 24px -4px rgba(230, 192, 90, 0.35), inset 0 0 40px rgba(0, 0, 0, 0.6); }
  50%      { box-shadow: 0 0 0 2px var(--gold), 0 0 42px 2px rgba(230, 192, 90, 0.6),  inset 0 0 40px rgba(0, 0, 0, 0.6); }
}
.boss.whack { animation: whack 0.18s ease; }
@keyframes whack { 0% { transform: scale(0.95); } 40% { transform: scale(1.04) rotate(-1.5deg); } 100% { transform: scale(1); } }

.boss-meta { width: 100%; max-width: 340px; }
.boss-name { font-family: var(--serif); font-size: 1.3rem; font-weight: 700; margin-bottom: 0.55rem; color: #e9ddc6; text-shadow: 0 2px 3px rgba(0, 0, 0, 0.6); }

.hpbar, .timerbar { position: relative; border: 1px solid var(--edge-dark); border-radius: 4px; overflow: hidden; background: #0d0806; box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.6); }
.hpbar { height: 24px; }
.timerbar { height: 14px; margin-top: 0.4rem; }
.hp-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #6e160f, var(--blood) 60%, #cc3a2b); transition: width 0.12s linear; }
.timer-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #5f7226, #a9b647); transition: width 0.12s linear; }
.timer-fill.low { background: linear-gradient(90deg, #6e160f, var(--blood)); animation: timerPulse 0.8s ease-in-out infinite; }
@keyframes timerPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
.hp-text, .timer-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.95); font-variant-numeric: tabular-nums; }
.hp-text { font-size: 0.78rem; }
.timer-text { font-size: 0.62rem; letter-spacing: 0.04em; }
.reward { margin-top: 0.5rem; font-size: 0.85rem; color: var(--ash-soft); }
.reward span { color: var(--ember); font-weight: 700; }
.hint { margin: 0.9rem 0 0; font-size: 0.76rem; color: var(--ash-soft); max-width: 300px; }

/* --- floating combat text --- */
.floater { position: absolute; transform: translate(-50%, -50%); font-weight: 800; font-size: 1rem; pointer-events: none; animation: floatUp 0.75s ease-out forwards; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95); white-space: nowrap; }
.floater.hit { color: #ffd9c2; }
.floater.reward { color: var(--gold); font-size: 1.15rem; }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.8); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -170%) scale(1.05); }
}

/* --- right column: tabs --- */
.rightcol { min-width: 0; overflow: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--edge-dark); }
.tab {
  flex: 1; padding: 0.75rem 0.5rem; border: none; cursor: pointer;
  background: linear-gradient(180deg, rgba(0,0,0,0.28), rgba(0,0,0,0.12));
  color: var(--ash-soft); font-family: var(--serif); font-size: 0.92rem; letter-spacing: 0.02em;
  border-right: 1px solid var(--edge-dark); position: relative;
  transition: color 0.15s ease, background 0.15s ease;
}
.tab:last-child { border-right: none; }
.tab:hover { color: var(--ash); }
.tab.active { color: var(--gold); background: linear-gradient(180deg, rgba(232,145,47,0.10), transparent); }
.tab.active::after { content: ''; position: absolute; left: 12%; right: 12%; bottom: -1px; height: 2px; background: linear-gradient(90deg, transparent, var(--ember), transparent); box-shadow: 0 0 10px var(--ember); }

.tab-body { padding: 1rem 1.05rem 1.15rem; }
.pane { display: none; }
.pane.active { display: block; animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.pane-note { margin: 0 0 0.8rem; font-size: 0.76rem; color: var(--ash-soft); font-style: italic; }
.empty { margin: 0; font-size: 0.82rem; color: var(--ash-soft); font-style: italic; }

/* --- blacksmith --- */
.sword-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.9rem; }
.sword-emoji { font-size: 2.1rem; line-height: 1; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6)); }
.sword-info { display: flex; flex-direction: column; }
.sword-name { font-family: var(--serif); font-weight: 700; font-size: 1.05rem; color: #e9ddc6; }
.sword-lvl { font-size: 0.82rem; color: var(--steel); font-weight: 700; }

.forge-btn {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 0.62rem 0.85rem; margin-top: 0.5rem;
  background: linear-gradient(160deg, var(--stone-1), var(--stone-3)); border: 1px solid var(--edge-dark); border-radius: 6px;
  color: var(--ash); cursor: pointer; font-size: 0.9rem; font-weight: 600;
  box-shadow: inset 0 1px 0 var(--edge-light); opacity: 0.62;
  transition: transform 0.12s ease, box-shadow 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
}
.forge-btn .fl em { color: var(--steel); font-style: normal; }
.forge-btn .cost { font-size: 0.82rem; font-weight: 700; color: var(--ember); font-variant-numeric: tabular-nums; }
.forge-btn.affordable { opacity: 1; border-color: var(--ember-dark); box-shadow: inset 0 1px 0 var(--edge-light), 0 0 16px -8px rgba(214, 108, 42, 0.8); }
.forge-btn.affordable:hover { transform: translateY(-2px); }
.forge-btn.evolve.affordable { border-color: var(--gold); box-shadow: inset 0 1px 0 var(--edge-light), 0 0 16px -6px rgba(230, 192, 90, 0.8); }
.forge-btn.evolve.affordable .cost { color: var(--gold); }
.forge-btn.disabled { opacity: 0.4; cursor: default; }
.forge-btn.disabled .cost { color: var(--ash-soft); font-weight: 600; }

.auto-strike { margin-top: 1rem; padding-top: 0.85rem; border-top: 1px solid var(--edge-dark); }
.auto-head { display: flex; align-items: baseline; justify-content: space-between; }
.auto-title { font-family: var(--serif); font-size: 0.95rem; color: #e9ddc6; }
.auto-rate { font-size: 0.78rem; color: var(--steel); font-weight: 700; }

/* --- rites (upgrades) --- */
.upgrades { display: flex; flex-direction: column; gap: 0.5rem; }
.upgrade {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.7rem;
  width: 100%; padding: 0.55rem 0.75rem; text-align: left;
  background: linear-gradient(160deg, var(--stone-1), var(--stone-3)); border: 1px solid var(--edge-dark); border-radius: 6px;
  color: var(--ash); cursor: pointer; opacity: 0.6; box-shadow: inset 0 1px 0 var(--edge-light);
  transition: transform 0.12s ease, box-shadow 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
}
.upgrade .uico { font-size: 1.3rem; line-height: 1; }
.upgrade .umid { display: flex; flex-direction: column; min-width: 0; }
.upgrade .uname { font-weight: 700; font-size: 0.9rem; }
.upgrade .udesc { font-size: 0.72rem; color: var(--ash-soft); }
.upgrade .ucost { font-size: 0.82rem; font-weight: 700; color: var(--ember); white-space: nowrap; font-variant-numeric: tabular-nums; }
.upgrade.affordable { opacity: 1; border-color: var(--gold); box-shadow: inset 0 1px 0 var(--edge-light), 0 0 16px -8px rgba(230, 192, 90, 0.7); }
.upgrade.affordable:hover { transform: translateY(-2px); }
.upgrade.affordable .ucost { color: var(--gold); }

/* --- characters (the ashen) --- */
.shop { display: flex; flex-direction: column; gap: 0.55rem; }
.buy {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.8rem;
  width: 100%; padding: 0.65rem 0.9rem; text-align: left;
  background: linear-gradient(160deg, var(--stone-1), var(--stone-3)); border: 1px solid var(--edge-dark); border-radius: 6px;
  color: var(--ash); cursor: pointer; opacity: 0.62; box-shadow: inset 0 1px 0 var(--edge-light);
  transition: transform 0.12s ease, box-shadow 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
}
.buy .ico { font-size: 1.7rem; line-height: 1; width: 2rem; text-align: center; }
.buy .mid { display: flex; flex-direction: column; min-width: 0; }
.buy .cname { font-weight: 700; font-size: 0.98rem; }
.buy .cdps { font-size: 0.74rem; color: var(--ash-soft); }
.buy .cdps b { color: var(--steel); font-weight: 700; }
.buy .right { display: flex; flex-direction: column; align-items: flex-end; }
.buy .cost { font-size: 0.85rem; font-weight: 700; color: var(--ember); white-space: nowrap; font-variant-numeric: tabular-nums; }
.buy .owned { font-size: 0.95rem; font-weight: 800; color: var(--ash-soft); font-variant-numeric: tabular-nums; }
.buy.affordable { opacity: 1; border-color: var(--ember-dark); box-shadow: inset 0 1px 0 var(--edge-light), 0 0 18px -8px rgba(214, 108, 42, 0.8); }
.buy.affordable:hover { transform: translateY(-2px); }
.buy.affordable:active { transform: translateY(0) scale(0.99); }
.buy.locked { opacity: 0.4; cursor: default; }
.buy.locked .cname, .buy.locked .cdps { color: var(--ash-soft); font-style: italic; }
.buy.locked .cost { color: var(--ash-soft); }

/* --- footer --- */
.foot { display: flex; align-items: center; justify-content: space-between; margin-top: 2rem; font-size: 0.85rem; }
.foot a { color: var(--ash-soft); text-decoration: none; }
.foot a:hover { color: var(--ember); }
.ghost { background: linear-gradient(160deg, var(--stone-1), var(--stone-3)); border: 1px solid #4a3f30; color: var(--ash-soft); border-radius: 4px; padding: 0.35rem 0.9rem; font-size: 0.78rem; cursor: pointer; box-shadow: inset 0 1px 0 var(--edge-light); transition: color 0.15s ease, border-color 0.15s ease; }
.ghost:hover { color: var(--blood); border-color: var(--blood); }

/* --- custom hover tooltip --- */
.tooltip {
  position: fixed; left: 0; top: 0; z-index: 200; max-width: 320px; pointer-events: none;
  padding: 0.65rem 0.8rem; border-radius: 6px;
  background: linear-gradient(158deg, #2e2822, #17130f), var(--noise);
  background-size: auto, 200px 200px;
  border: 1px solid var(--edge-dark);
  box-shadow: inset 0 1px 0 var(--edge-light), 0 12px 26px -8px rgba(0, 0, 0, 0.9);
  color: var(--ash); font-size: 0.86rem; line-height: 1.55;
  opacity: 0; transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.tooltip.show { opacity: 1; transform: translateY(0); }
.tt-title { font-family: var(--serif); color: #e9ddc6; font-size: 0.98rem; margin-bottom: 0.35rem; }
.tt-row { display: flex; justify-content: space-between; gap: 1.4rem; color: var(--ash-soft); }
.tt-row b { color: var(--ash); font-weight: 700; font-variant-numeric: tabular-nums; }
.tt-total { display: flex; justify-content: space-between; gap: 1.4rem; margin-top: 0.4rem; padding-top: 0.4rem; border-top: 1px solid var(--edge-dark); color: var(--ash-soft); }
.tt-total b { color: var(--gold); font-weight: 800; font-variant-numeric: tabular-nums; }

/* --- responsive --- */
@media (max-width: 760px) {
  .board { grid-template-columns: 1fr; }
  .topbar { justify-content: center; }
  .stats { justify-content: center; }
}
@media (max-width: 480px) {
  .game { padding: 1.25rem 0.9rem 2rem; }
  .boss { width: 152px; height: 152px; }
  .boss-emoji { font-size: 3.8rem; }
  .tab { font-size: 0.82rem; padding: 0.7rem 0.3rem; }
}
