:root {
  --bg: #0d0f12;
  --panel: rgba(18, 20, 24, 0.94);
  --panel-2: rgba(28, 31, 36, 0.9);
  --line: #3a3f47;
  --text: #e8e6e1;
  --muted: #9aa0a8;
  --accent: #c9973f;
  --accent-2: #7fa650;
  --hp: #b8413a;
  --stam: #4f86c6;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

canvas { display: block; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

#crosshair {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 18px; height: 18px;
  display: none;
}
#crosshair.on { display: block; }
#crosshair span, #crosshair::before, #crosshair::after {
  content: ""; position: absolute; background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.9);
}
#crosshair span { left: 8px; top: 0; width: 2px; height: 18px; }
#crosshair::before { left: 0; top: 8px; width: 18px; height: 2px; }

#targetName {
  position: absolute; left: 50%; top: calc(50% + 30px);
  transform: translateX(-50%);
  font-size: 14px; letter-spacing: 0.06em;
  color: #f2ede2; text-shadow: 0 2px 6px #000;
  opacity: 0; transition: opacity 0.12s;
  text-align: center;
}
#targetName.on { opacity: 1; }
#targetName em { display: block; font-style: normal; font-size: 12px; color: var(--muted); margin-top: 2px; }

#topbar {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 18px; align-items: center;
  padding: 10px 18px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.stat label {
  display: block; font-size: 10px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 4px;
  font-family: system-ui, sans-serif;
}
.bar { width: 130px; height: 9px; background: #0a0b0d; border-radius: 5px; overflow: hidden; border: 1px solid #2c3038; }
.bar i { display: block; height: 100%; width: 100%; transition: width 0.18s ease; }
.bar.hp i { background: linear-gradient(90deg, #8f2f2a, var(--hp)); }
.bar.st i { background: linear-gradient(90deg, #35618f, var(--stam)); }
.clock { text-align: right; }
#clockLabel { font-size: 14px; color: var(--text); letter-spacing: 0.04em; text-transform: none; margin: 0; }

#hotbar {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px;
}
.slot {
  position: relative; width: 58px; height: 58px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 22px;
  box-shadow: var(--shadow);
  transition: transform 0.1s, border-color 0.15s;
}
.slot .key {
  position: absolute; top: 3px; left: 5px;
  font-size: 9px; color: var(--muted); font-family: system-ui, sans-serif;
}
.slot .qty {
  position: absolute; bottom: 3px; right: 5px;
  font-size: 11px; color: var(--text); font-family: system-ui, sans-serif;
}
.slot .nm { font-size: 8.5px; color: var(--muted); font-family: system-ui, sans-serif; margin-top: 2px; max-width: 52px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot.sel { border-color: var(--accent); transform: translateY(-4px); background: rgba(201, 151, 63, 0.16); }
.slot.locked { opacity: 0.4; }
.slot.locked .ico { filter: grayscale(1); }

#toast {
  position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%);
  padding: 8px 16px; background: rgba(10, 11, 13, 0.9);
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 6px; font-size: 13px; opacity: 0;
  transition: opacity 0.25s; max-width: 60ch; text-align: center;
}
#toast.on { opacity: 1; }

#hint {
  position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--muted); font-family: system-ui, sans-serif;
  opacity: 0.55;
}
#hint b { color: var(--text); font-weight: 600; }

/* ---------- Panels ---------- */
.panel {
  position: fixed; z-index: 30; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(860px, 94vw); max-height: 86vh;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.panel.hidden { display: none; }
.panel header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
}
.panel h2 { margin: 0; font-size: 18px; letter-spacing: 0.05em; }
.close {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  width: 28px; height: 28px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.close:hover { color: var(--text); border-color: var(--accent); }

.craftBody { display: grid; grid-template-columns: 300px 1fr; overflow: hidden; flex: 1; }
.craftList { border-right: 1px solid var(--line); overflow-y: auto; max-height: 60vh; }
.recipe {
  padding: 11px 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.recipe:hover { background: rgba(255, 255, 255, 0.04); }
.recipe.sel { background: rgba(201, 151, 63, 0.14); box-shadow: inset 3px 0 0 var(--accent); }
.recipe .rname { font-size: 14px; }
.recipe .cat { font-size: 10px; color: var(--muted); font-family: system-ui, sans-serif; text-transform: uppercase; letter-spacing: 0.1em; }
.recipe.locked { opacity: 0.45; }

.craftDetail { padding: 20px; overflow-y: auto; }
.craftDetail h3 { margin: 0 0 4px; font-size: 20px; }
.craftDetail .desc { color: var(--muted); font-size: 13px; margin: 0 0 16px; line-height: 1.5; }
.ing { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dotted rgba(255, 255, 255, 0.1); font-size: 13px; font-family: system-ui, sans-serif; }
.ing .ok { color: var(--accent-2); }
.ing .no { color: var(--hp); }
.craftBtn {
  margin-top: 18px; width: 100%; padding: 12px;
  background: var(--accent); color: #1a1206; border: none; border-radius: 8px;
  font-size: 15px; font-weight: 700; cursor: pointer; font-family: inherit;
  letter-spacing: 0.03em;
}
.craftBtn:disabled { background: #3a3f47; color: #7d838b; cursor: not-allowed; }

.buildGrid { padding: 18px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; overflow-y: auto; }
.buildCard {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 10px; text-align: center; cursor: pointer;
}
.buildCard:hover { border-color: var(--accent); }
.buildCard.sel { border-color: var(--accent); background: rgba(201, 151, 63, 0.16); }
.buildCard .ico { font-size: 26px; }
.buildCard .bn { font-size: 13px; margin-top: 6px; }
.buildCard .bc { font-size: 10px; color: var(--muted); font-family: system-ui, sans-serif; margin-top: 3px; }

.invGrid { padding: 18px; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; overflow-y: auto; }
.invItem { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; text-align: center; }
.invItem .ico { font-size: 22px; }
.invItem .inm { font-size: 12px; margin-top: 4px; }
.invItem .iq { font-size: 12px; color: var(--accent); font-family: system-ui, sans-serif; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Start screen ---------- */
#startScreen {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 35%, #2a2318 0%, #0b0c0e 70%);
}
#startScreen.gone { display: none; }
.startCard { width: min(560px, 92vw); text-align: center; padding: 34px; }
.startCard h1 { font-size: 52px; margin: 0 0 6px; letter-spacing: 0.12em; }
.tag { color: var(--muted); font-style: italic; margin: 0 0 22px; }
.rules { text-align: left; display: inline-block; margin: 0 0 26px; padding-left: 20px; font-size: 14px; line-height: 1.9; color: #d7d3ca; }
.rules b { color: var(--accent); }
#startBtn {
  padding: 14px 40px; font-size: 17px; font-family: inherit; font-weight: 700;
  background: var(--accent); color: #1a1206; border: none; border-radius: 8px; cursor: pointer;
  letter-spacing: 0.04em;
}
#startBtn:hover { filter: brightness(1.1); }

#loading {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; gap: 10px; align-items: center;
  color: var(--muted); font-size: 13px;
}
#loading.gone { display: none; }
.spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
