/* Ember Forge — chrome around the canvas scene.
   Dark forge palette; the canvas provides all the warm light. */

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

html, body {
  height: 100%;
  overflow: hidden;
  background: #0d0709;
  color: #e8dccc;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }
.muted { color: #8a7a6a; font-size: 13px; }

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------------------------------------------------------------- top bar */

#topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  background: #17100d;
  border-bottom: 1px solid #2c201a;
  flex-wrap: wrap;
}

.stat { display: flex; flex-direction: column; line-height: 1.15; }
.stat > span:first-child { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 11px; color: #8a7a6a; text-transform: uppercase; letter-spacing: 0.06em; }
.stat.gold > span:first-child { color: #ffd76a; }
.stat.embers > span:first-child { color: #ff9d5c; }

.icon-btn {
  margin-left: auto;
  font-size: 20px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #241812;
}
.icon-btn:hover { background: #2f2016; }

/* ----------------------------------------------------------------- layout */

#layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

#scene-wrap {
  position: relative;
  flex: 1.1;
  min-width: 0;
  cursor: pointer;
}
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#item-plate {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: min(70%, 300px);
  text-align: center;
  pointer-events: none;
}
#item-name { font-size: 13px; color: #cdbba5; margin-bottom: 4px; text-shadow: 0 1px 3px #000; }
.bar { height: 8px; background: rgba(0,0,0,0.55); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #ff8c32, #ffd76a); transition: width 0.15s linear; }

#boost-badges { position: absolute; top: 10px; left: 10px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.badge {
  background: rgba(255, 140, 40, 0.9);
  color: #2a1000;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 20px;
}
.badge.surge { background: rgba(120, 200, 255, 0.9); color: #002a40; }

.surge-offer {
  position: absolute;
  top: 10px;
  right: 10px;
  background: #1c72c9;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
.surge-offer:hover { background: #2585e2; }

/* ------------------------------------------------------------------ panel */

#panel {
  flex: 1;
  min-width: 300px;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  background: #14100e;
  border-left: 1px solid #2c201a;
}

#tabs { display: flex; border-bottom: 1px solid #2c201a; }
.tab {
  flex: 1;
  padding: 12px 4px;
  font-size: 14px;
  font-weight: 600;
  color: #8a7a6a;
  position: relative;
  border-bottom: 2px solid transparent;
}
.tab.active { color: #ffd76a; border-bottom-color: #ff8c32; }
.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #6ee787;
  margin-left: 4px;
  vertical-align: super;
}

.tab-page { display: none; flex: 1; overflow-y: auto; padding: 12px; }
.tab-page.active { display: block; }

.buy-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; color: #8a7a6a; }
.qty {
  padding: 4px 12px;
  border-radius: 8px;
  background: #241812;
  font-size: 13px;
  font-weight: 600;
}
.qty.active { background: #ff8c32; color: #2a1000; }

/* --------------------------------------------------------- shop rows */

.gen-row, .upg-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 12px;
  background: #1d1512;
  border: 1px solid #2c201a;
  transition: transform 0.06s ease, background 0.15s;
}
.gen-row:not(:disabled):hover, .upg-row:not(:disabled):hover { background: #261a14; }
.gen-row:not(:disabled):active { transform: scale(0.98); }
.gen-row:disabled, .upg-row:disabled { opacity: 0.45; cursor: default; }
.gen-row.locked { opacity: 0.3; filter: grayscale(0.7); }

.gen-info { flex: 1; min-width: 0; }
.gen-name { font-weight: 700; font-size: 14px; }
.gen-name small { color: #8a7a6a; font-weight: 600; margin-left: 6px; }
.gen-desc { font-size: 12px; color: #8a7a6a; margin-top: 1px; }
.gen-rate { font-size: 12px; color: #b7e0a8; margin-top: 2px; }
.gen-buy { text-align: right; white-space: nowrap; }
.gen-cost { font-weight: 700; color: #ffd76a; font-size: 14px; }
.gen-cost.cant { color: #a06b52; }
.gen-icon {
  position: relative;
  flex: none;
  width: 44px;
  height: 44px;
  background-repeat: no-repeat;
  border-radius: 8px;
}
.gen-row.locked .gen-icon { filter: brightness(0.12) saturate(0.2); }
.gen-count {
  position: absolute;
  bottom: -5px;
  right: -8px;
  font-size: 11px;
  font-weight: 800;
  color: #cdbba5;
  background: #241812;
  border: 1px solid #3a2a1e;
  border-radius: 9px;
  padding: 0 5px;
  min-width: 12px;
  text-align: center;
}

/* ----------------------------------------------------------- reforge tab */

.reforge-box { text-align: center; padding: 22px 12px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.reforge-box h2 { font-size: 18px; color: #ff9d5c; }
.reforge-box p { font-size: 14px; max-width: 320px; }

.big-btn {
  background: #ff8c32;
  color: #2a1000;
  font-weight: 800;
  font-size: 15px;
  padding: 12px 26px;
  border-radius: 12px;
  transition: transform 0.06s ease;
}
.big-btn:not(:disabled):hover { background: #ffa14f; }
.big-btn:not(:disabled):active { transform: scale(0.97); }
.big-btn:disabled { opacity: 0.35; cursor: default; }
.big-btn.reward { background: #1c72c9; color: #fff; }
.big-btn.ghost { background: #241812; color: #cdbba5; }

/* ---------------------------------------------------------------- overlays */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 4, 5, 0.82);
}

.load-box { text-align: center; color: #cdbba5; font-size: 15px; }
.load-anvil { font-size: 44px; animation: pulse 1.1s ease-in-out infinite; margin-bottom: 10px; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }

.modal {
  background: #1d1512;
  border: 1px solid #3a2a1e;
  border-radius: 16px;
  padding: 26px 28px;
  max-width: 380px;
  width: calc(100% - 40px);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal h2 { color: #ffd76a; font-size: 19px; }
.modal p { font-size: 14px; line-height: 1.45; }
.offline-amount { font-size: 24px; font-weight: 800; color: #ffd76a; }
.modal-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }

/* ----------------------------------------------------------------- mobile */

@media (max-width: 760px) {
  #layout { flex-direction: column; }
  #scene-wrap { flex: none; height: 44%; }
  #panel { max-width: none; border-left: 0; border-top: 1px solid #2c201a; }
  #topbar { gap: 12px; padding: 8px 12px; }
  .stat > span:first-child { font-size: 16px; }
}

/* ------------------------------------------------------------------ store */
/* Built by src/store.js, and only in the self-hosted build — on the portals the
   module returns nothing, the Store tab stays hidden, and none of this is ever
   on screen. Warm palette, so the shop belongs to the forge. */

.store-box { padding: 14px 16px; }
.store-box h2 { font-size: 17px; margin-bottom: 6px; }

.store-perks { margin: 10px 0 14px; padding-left: 18px; font-size: 13px; line-height: 1.6; }
.store-perks b { color: #ffb75e; }

.store {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid #3a2820;
  border-radius: 10px;
  background: #17100d;
}

.store.is-busy { opacity: 0.7; }

.store-copy { font-size: 13px; line-height: 1.5; }
.store-label { font-size: 12px; color: #8a7a6a; }

.store-field {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #3a2820;
  border-radius: 8px;
  background: #0d0709;
  color: #e8dccc;
  font: inherit;
  font-size: 13px;
  user-select: text;
  -webkit-user-select: text;
}

.store-field:focus-visible { outline: 2px solid #ff9427; outline-offset: 1px; }

.store-row { display: flex; flex-wrap: wrap; gap: 8px; }

.store-btn {
  flex: 1 1 8rem;
  padding: 10px 8px;
  border-radius: 8px;
  background: #ff9427;
  color: #241206;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

.store-btn--ghost {
  background: transparent;
  border: 1px solid #3a2820;
  color: #8a7a6a;
  font-weight: 600;
}

.store-btn:disabled { opacity: 0.5; cursor: default; }

.store-msg { font-size: 12px; min-height: 1em; }

/* The one string a player must be able to copy exactly. */
.store-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: #ffb75e;
  word-break: break-all;
  user-select: all;
  -webkit-user-select: all;
}

.store-fine { font-size: 11px; color: #8a7a6a; line-height: 1.5; }
.store-fine a { color: #8a7a6a; }

/* Stripe mounts its own light-themed iframe here; this only has to be a
   legible, scrollable box with a way out. */
.checkout-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px;
  background: rgba(8, 4, 3, 0.88);
  backdrop-filter: blur(4px);
  overflow: auto;
}

.checkout-mount {
  width: min(460px, 100%);
  max-height: 86vh;
  overflow: auto;
  padding: 14px;
  border-radius: 12px;
  background: #fff;
}

.checkout-close {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: 12px;
  width: 40px;
  height: 40px;
  border: 1px solid #3a2820;
  border-radius: 50%;
  background: #17100d;
  color: #e8dccc;
  font-size: 1.4rem;
  line-height: 1;
}
