/* Vintage Story Helper -- warm, dark, parchment-and-iron palette chosen to sit
   close to the game's own UI so the recipe grids read as familiar. */

:root {
  --bg:          #14110d;
  --bg-raised:   #1e1a14;
  --bg-sunken:   #0f0d0a;
  --panel:       #251f18;
  --panel-edge:  #3a3128;
  --slot:        #17130f;
  --slot-edge:   #4a3f32;

  --ink:         #e8dcc8;
  --ink-dim:     #a9987e;
  --ink-faint:   #6f6353;

  --accent:      #c8963c;
  --accent-soft: #7a5a22;
  --copper:      #b87333;
  --iron:        #8f9296;
  --good:        #7fa650;
  --warn:        #c96a4a;

  --radius: 8px;
  --shadow: 0 8px 28px rgba(0,0,0,.55);
  --font: "Segoe UI", Roboto, system-ui, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  overflow-wrap: break-word;
}

body {
  /* Subtle woven texture so large dark areas don't read as flat black. */
  background-image:
    radial-gradient(circle at 15% 10%, rgba(200,150,60,.05), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(120,90,40,.05), transparent 45%);
  background-attachment: fixed;
}

/* ----------------------------------------------------------------- topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: linear-gradient(180deg, #221c15, #1a1610);
  border-bottom: 1px solid var(--panel-edge);
  box-shadow: 0 2px 14px rgba(0,0,0,.5);
}

.menu-btn {
  display: none;
  background: none;
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  color: var(--ink);
  padding: 6px;
  cursor: pointer;
}
.menu-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex-shrink: 1; }
.brand-mark { font-size: 22px; color: var(--accent); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-family: var(--serif); font-size: 17px; letter-spacing: .2px; white-space: nowrap; }
.brand-text small { color: var(--ink-faint); font-size: 11px; white-space: nowrap; }

/* min-width:0 lets the input shrink below its intrinsic size instead of
   forcing the whole topbar — and the page — wider than the viewport. */
.search-wrap { position: relative; flex: 1 1 auto; min-width: 0; max-width: 460px; margin-left: auto; }

#search {
  width: 100%;
  padding: 9px 14px;
  background: var(--bg-sunken);
  border: 1px solid var(--panel-edge);
  border-radius: 999px;
  color: var(--ink);
  font-size: 14px;
  font-family: inherit;
}
#search:focus { outline: none; border-color: var(--accent-soft); box-shadow: 0 0 0 3px rgba(200,150,60,.12); }
#search::placeholder { color: var(--ink-faint); }

.results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  max-height: 62vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 50;
}

.result {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.result:last-child { border-bottom: none; }
.result:hover, .result[aria-selected="true"] { background: rgba(200,150,60,.12); }
.result img, .result .noicon { width: 28px; height: 28px; flex: none; }
.result-name { flex: 1; min-width: 0; font-size: 14px; }
.result-name small { display: block; color: var(--ink-faint); font-size: 11px; font-family: ui-monospace, monospace; }
.result-kinds { font-size: 10px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .5px; flex: none; }

.overall { display: flex; align-items: center; gap: 7px; flex: none; }
.overall .ring { width: 34px; height: 34px; transform: rotate(-90deg); }
.ring-bg, .ring-fg { fill: none; stroke-width: 3; }
.ring-bg { stroke: rgba(255,255,255,.09); }
.ring-fg {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 97.4;
  stroke-dashoffset: 97.4;
  transition: stroke-dashoffset .4s ease;
}
#overallPct { font-size: 13px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }

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

.layout { display: flex; align-items: flex-start; }

.sidebar {
  position: sticky;
  top: 61px;
  flex: none;
  width: 250px;
  height: calc(100vh - 61px);
  overflow-y: auto;
  padding: 18px 10px 40px;
  border-right: 1px solid var(--panel-edge);
}

.side-group { font-size: 10px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--ink-faint); padding: 14px 12px 6px; }

.side-link {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--ink-dim);
  text-decoration: none;
  font-size: 14px;
  border-left: 3px solid transparent;
  cursor: pointer;
}
.side-link:hover { background: rgba(255,255,255,.04); color: var(--ink); }
.side-link.active { background: rgba(200,150,60,.1); border-left-color: var(--accent); color: var(--ink); }
.side-link .side-count { float: right; font-size: 11px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.side-link.done .side-count { color: var(--good); }

main { flex: 1; min-width: 0; padding: 26px 30px 90px; max-width: 900px; }

/* ------------------------------------------------------------------ stage */

.intro-card {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 30px;
  color: var(--ink-dim);
  font-size: 14px;
}

.stage { margin-bottom: 54px; scroll-margin-top: 74px; }

.stage-head { border-bottom: 1px solid var(--panel-edge); padding-bottom: 14px; margin-bottom: 20px; }

.stage-eyebrow {
  font-size: 10px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}
.stage-eyebrow.parallel { color: var(--iron); }

.stage-head h2 { font-family: var(--serif); font-size: 30px; margin: 4px 0 2px; font-weight: 600; }
.stage-tagline { color: var(--ink-dim); font-style: italic; margin: 0 0 10px; }

.stage-goal {
  display: inline-block;
  background: rgba(200,150,60,.1);
  border: 1px solid var(--accent-soft);
  border-radius: 5px;
  padding: 5px 11px;
  font-size: 13px;
  color: var(--ink);
}
.stage-goal b { color: var(--accent); font-weight: 600; }

.bar { height: 5px; background: rgba(255,255,255,.07); border-radius: 3px; overflow: hidden; margin-top: 14px; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--copper), var(--accent)); transition: width .35s ease; }

section.block { margin: 26px 0; }
section.block > h3 {
  font-family: var(--serif);
  font-size: 20px;
  margin: 0 0 10px;
  color: var(--ink);
  font-weight: 600;
}

.prose { color: var(--ink-dim); font-size: 15px; }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0 0 12px; padding-left: 20px; }
.prose li { margin-bottom: 5px; }
.prose strong { color: var(--ink); font-weight: 600; }
.prose code {
  background: var(--bg-sunken);
  border: 1px solid var(--panel-edge);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: .88em;
  font-family: ui-monospace, "Cascadia Code", monospace;
  color: var(--accent);
}

/* --------------------------------------------------------------- checklist */

.tasks { list-style: none; margin: 14px 0 0; padding: 0; }

.task {
  display: flex;
  gap: 11px;
  padding: 10px 12px;
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  background: var(--bg-raised);
  margin-bottom: 8px;
  transition: border-color .18s, opacity .18s;
}
.task:hover { border-color: #4b4034; }
.task.done { opacity: .5; }
.task.done .task-text { text-decoration: line-through; }

.task-check {
  flex: none;
  width: 21px; height: 21px;
  margin-top: 2px;
  border: 2px solid var(--slot-edge);
  border-radius: 5px;
  background: var(--slot);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  color: transparent;
  font-size: 13px;
  line-height: 1;
}
.task-check:hover { border-color: var(--accent); }
.task.done .task-check { background: var(--good); border-color: var(--good); color: #14110d; }
.task-check:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.task-main { min-width: 0; flex: 1; }
.task-text { font-size: 15px; }
.task-note { font-size: 13px; color: var(--ink-faint); margin-top: 3px; }
.task-items { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* -------------------------------------------------------------------- chip */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  vertical-align: baseline;
  background: var(--panel);
  border: 1px solid var(--slot-edge);
  border-radius: 5px;
  padding: 1px 7px 1px 4px;
  font-size: .92em;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  line-height: 1.5;
}
.chip:hover, .chip.open { border-color: var(--accent); background: rgba(200,150,60,.14); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip img { width: 20px; height: 20px; image-rendering: pixelated; flex: none; }
.chip .noicon { width: 20px; height: 20px; flex: none; }
.chip.missing { border-style: dashed; color: var(--warn); cursor: help; }

/* Fallback tile for the ~40% of items the wiki has no icon for. */
.noicon {
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #3b3226, #241e17);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-faint);
  text-transform: uppercase;
  line-height: 1;
}

/* ---------------------------------------------------------------- popover */

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60; }

.popover {
  position: absolute;
  z-index: 70;
  width: min(360px, calc(100vw - 24px));
  max-height: 70vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--slot-edge);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.pop-close {
  position: absolute;
  top: 6px; right: 8px;
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}
.pop-close:hover { color: var(--ink); }

.pop-title { display: flex; align-items: center; gap: 9px; margin-bottom: 3px; padding-right: 22px; }
.pop-title img { width: 32px; height: 32px; image-rendering: pixelated; }
.pop-title .noicon { width: 32px; height: 32px; font-size: 11px; }
.pop-title strong { font-family: var(--serif); font-size: 17px; font-weight: 600; }
.pop-code { font-family: ui-monospace, monospace; font-size: 11px; color: var(--ink-faint); margin-bottom: 12px; }

.recipe { border-top: 1px solid var(--panel-edge); padding-top: 12px; margin-top: 12px; }
.recipe:first-of-type { border-top: none; margin-top: 0; }

.recipe-kind {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--accent);
  border-radius: 3px;
  padding: 2px 7px;
  margin-bottom: 10px;
  font-weight: 700;
}
.recipe-kind.knapping    { background: #9c8e77; }
.recipe-kind.clayforming { background: #b07a4e; }
.recipe-kind.smithing    { background: var(--iron); }
.recipe-kind.alloy       { background: var(--copper); }
.recipe-kind.barrel      { background: #7b6a4a; }
.recipe-kind.cooking     { background: var(--good); }

/* -- crafting grid ------------------------------------------------------- */

.craft { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.grid3 {
  display: grid;
  grid-template-columns: repeat(3, 40px);
  grid-template-rows: repeat(3, 40px);
  gap: 3px;
  background: var(--bg-sunken);
  border: 2px solid var(--slot-edge);
  border-radius: 5px;
  padding: 3px;
}

.slot {
  background: var(--slot);
  border: 1px solid rgba(255,255,255,.05);
  border-radius: 3px;
  display: grid;
  place-items: center;
  position: relative;
  cursor: default;
}
.slot.filled { cursor: pointer; border-color: var(--slot-edge); }
.slot.filled:hover { border-color: var(--accent); }
.slot.unused { opacity: .25; }
.slot img { width: 30px; height: 30px; image-rendering: pixelated; }
.slot .noicon { width: 30px; height: 30px; font-size: 8px; padding: 1px; text-align: center; }
.slot .qty {
  position: absolute;
  right: 1px; bottom: 0;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
}
.slot .tool-dot {
  position: absolute;
  left: 2px; top: 2px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--iron);
}

.arrow { font-size: 22px; color: var(--ink-faint); }

.out {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.out .slot { width: 48px; height: 48px; border-color: var(--accent-soft); }
.out .slot img { width: 36px; height: 36px; }
.out-qty { font-size: 12px; color: var(--accent); font-weight: 600; }

.recipe-note { font-size: 12px; color: var(--ink-faint); margin-top: 9px; }
.recipe-note b { color: var(--ink-dim); }

/* -- voxel patterns ------------------------------------------------------ */

.voxel-wrap { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; }
.voxel-layer { text-align: center; }
.voxel-label { font-size: 10px; color: var(--ink-faint); margin-bottom: 3px; }

.voxel {
  display: grid;
  gap: 1px;
  background: var(--slot-edge);
  border: 1px solid var(--slot-edge);
  border-radius: 3px;
  padding: 1px;
}
.vx { width: 9px; height: 9px; background: var(--bg-sunken); }
.vx.on { background: linear-gradient(160deg, #d8b071, #a97c3c); }
.voxel.clayforming .vx.on { background: linear-gradient(160deg, #c08a5e, #8a5a34); }
.voxel.smithing .vx.on   { background: linear-gradient(160deg, #b9bcc0, #7d8288); }

.from-line { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; color: var(--ink-dim); }

/* -- list-style recipes (alloy, barrel, cooking) ------------------------- */

.ing-list { list-style: none; margin: 0 0 10px; padding: 0; }
.ing-list li { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; }
.ing-list .ratio { margin-left: auto; font-size: 12px; color: var(--accent); font-variant-numeric: tabular-nums; }
.ing-opts { display: flex; flex-wrap: wrap; gap: 5px; }

/* ------------------------------------------------------------------ misc */

.loading { text-align: center; padding: 80px 20px; color: var(--ink-faint); }
.spinner {
  width: 34px; height: 34px;
  margin: 0 auto 14px;
  border: 3px solid var(--panel-edge);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.pitfalls {
  background: rgba(201,106,74,.07);
  border: 1px solid rgba(201,106,74,.3);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-top: 22px;
}
.pitfalls h4 { margin: 0 0 7px; font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--warn); }
.pitfalls ul { margin: 0; padding-left: 18px; color: var(--ink-dim); font-size: 13.5px; }
.pitfalls li { margin-bottom: 4px; }

.footer-note {
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--panel-edge);
  font-size: 12px;
  color: var(--ink-faint);
}
.footer-note a { color: var(--ink-dim); }

.reset-btn {
  background: none;
  border: 1px solid var(--panel-edge);
  color: var(--ink-faint);
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.reset-btn:hover { border-color: var(--warn); color: var(--warn); }

.empty { color: var(--ink-faint); font-size: 13px; font-style: italic; }

/* --------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .menu-btn { display: block; }
  .brand-text small { display: none; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 270px;
    height: 100vh;
    z-index: 65;
    background: var(--bg-raised);
    transform: translateX(-100%);
    transition: transform .22s ease;
    padding-top: 18px;
  }
  .sidebar.open { transform: none; }

  main { padding: 18px 16px 80px; }
  .stage-head h2 { font-size: 25px; }

  /* Hover is not a thing on touch, so the popover becomes a bottom sheet
     that is reachable with a thumb. */
  .popover {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    top: auto;
    width: 100%;
    max-height: 78vh;
    border-radius: 14px 14px 0 0;
    border-bottom: none;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    animation: sheet .22s ease;
  }
  @keyframes sheet { from { transform: translateY(100%); } }

  .pop-close { font-size: 26px; top: 8px; right: 12px; }
}

@media (max-width: 620px) {
  /* Brand and search cannot both fit on one row at phone widths, so the
     search drops to its own line rather than pushing the page sideways. */
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .brand { flex: 1 1 auto; }
  .brand-text strong { font-size: 15px; white-space: normal; }
  .search-wrap { order: 3; flex: 1 0 100%; max-width: none; margin-left: 0; }
  .overall { display: none; }
  .grid3 { grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 44px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.prose em { color: var(--ink); font-style: italic; }
