/* Corps of Discovery — desert palette */
:root {
  --sand: #ebd9b4;
  --bone: #f8efdc;
  --dune: #cfa867;
  --dune-dark: #a9823f;
  --mesa: #a2421f;
  --mesa-dark: #7d2f14;
  --sage: #66764c;
  --sage-light: #c9d1b0;
  --canyon: #33231a;
  --canyon-soft: #5a4434;
  --turq: #2b7a80;
  --danger: #8f1d14;
  --radius-s: 4px;
  --radius-m: 10px;
  --head: "IM Fell English", "Iowan Old Style", Georgia, serif;
  --body: "Alegreya Sans", "Gill Sans", "Trebuchet MS", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.5;
  color: var(--canyon);
  background-color: var(--sand);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(255, 245, 220, .7), transparent 60%),
    radial-gradient(ellipse at 90% 100%, rgba(207, 168, 103, .45), transparent 55%);
  background-attachment: fixed;
  min-height: 100vh;
}
h1, h2, h3, h4 { font-family: var(--head); font-weight: 400; line-height: 1.15; margin: 0 0 .5em; }
h1 { font-size: 2.6rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.45rem; }
p { margin: 0 0 .8em; max-width: 70ch; }
a { color: var(--turq); }
img { max-width: 100%; display: block; }
.hidden { display: none !important; }
.muted { color: var(--canyon-soft); }
.small { font-size: .88rem; }
.center { text-align: center; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }

/* ---------- buttons & inputs ---------- */
button, .btn {
  font: 600 1rem var(--body);
  background: var(--mesa); color: var(--bone);
  border: 0; border-radius: var(--radius-s);
  padding: .65em 1.2em; cursor: pointer;
  box-shadow: 0 3px 0 var(--mesa-dark);
  transition: transform .08s, box-shadow .08s, background .15s;
}
button:hover { background: #b34d27; }
button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--mesa-dark); }
button:disabled { background: #b9a588; box-shadow: 0 3px 0 #9a876c; cursor: not-allowed; color: #f1e7d3; }
button.secondary { background: var(--sage); box-shadow: 0 3px 0 #4a5736; }
button.secondary:hover { background: #75865a; }
button.ghost { background: transparent; color: var(--canyon); box-shadow: inset 0 0 0 2px var(--dune-dark); }
button.ghost:hover { background: rgba(207, 168, 103, .25); }
button.small { padding: .35em .8em; font-size: .9rem; }
button.danger { background: var(--danger); box-shadow: 0 3px 0 #5e120c; }
:focus-visible { outline: 3px solid var(--turq); outline-offset: 2px; }
label { display: block; font-weight: 600; margin: .6em 0 .25em; }
input, select, textarea {
  font: 1rem var(--body); color: var(--canyon);
  background: #fffaf0; border: 2px solid var(--dune); border-radius: var(--radius-s);
  padding: .55em .7em; width: 100%;
}
textarea { min-height: 100px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--turq); outline: none; }

/* ---------- panels ---------- */
.panel {
  background: var(--bone);
  border: 1px solid #d9c49a;
  border-radius: var(--radius-m);
  padding: 22px 24px;
  box-shadow: 0 1px 0 #fff inset, 0 8px 24px -14px rgba(51, 35, 26, .45);
}
.panel + .panel { margin-top: 18px; }
.note { background: #f3e3bf; border-left: 4px solid var(--dune-dark); padding: 10px 14px; border-radius: var(--radius-s); margin: 10px 0; }
.note.good { background: #e3e8d2; border-color: var(--sage); }
.note.bad { background: #f2d5c7; border-color: var(--mesa); }
.note.info { background: #d8e9e7; border-color: var(--turq); }
.tag { display: inline-block; font-size: .8rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--sage-light); color: #38432a; }
.tag.rust { background: #efc9b5; color: var(--mesa-dark); }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(rgba(51, 35, 26, .25), rgba(51, 35, 26, .55)), url('../img/title_map.jpg') center/cover;
}
.login-card { width: min(440px, 100%); }
.login-card h1 { font-size: 2.1rem; margin-bottom: .15em; }
.login-card .lede { color: var(--canyon-soft); margin-bottom: 1em; }

/* ---------- ledger (top status bar) ---------- */
.ledger {
  position: sticky; top: 0; z-index: 20;
  background: var(--canyon); color: var(--bone);
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 20px;
  padding: 8px 18px; font-size: .95rem;
  border-bottom: 3px solid var(--dune-dark);
}
.ledger .who { font-family: var(--head); font-size: 1.2rem; margin-right: 6px; }
.ledger .stat { display: flex; flex-direction: column; line-height: 1.15; }
.ledger .stat b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.ledger .stat span { font-size: .75rem; color: #d7c3a0; }
.ledger .meter { width: 90px; height: 8px; background: #5e4a3b; border-radius: 99px; overflow: hidden; margin-top: 3px; }
.ledger .meter i { display: block; height: 100%; background: var(--sage-light); transition: width .4s; }
.ledger .meter.low i { background: #e2734a; }
.ledger button { padding: .3em .8em; font-size: .85rem; }

main.app { max-width: 1120px; margin: 0 auto; padding: 22px 18px 60px; }

/* ---------- briefing / level card ---------- */
.level-hero { border-radius: var(--radius-m); overflow: hidden; border: 1px solid #c8ae7d; margin-bottom: 16px; }
.orders { display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: start; }
.orders img { border-radius: var(--radius-s); border: 1px solid #c8ae7d; }
@media (max-width: 700px) { .orders { grid-template-columns: 1fr; } .orders img { max-width: 200px; } }

/* ---------- outpost ---------- */
.outpost { display: grid; grid-template-columns: 210px 1fr; gap: 20px; align-items: start; }
.outpost-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.outpost-head h2 { margin: 0; }
.tabs { display: flex; flex-direction: column; gap: 6px; position: sticky; top: 80px; }
.tabs button {
  text-align: left; background: #e2c993; color: var(--canyon); box-shadow: 0 3px 0 var(--dune-dark);
  font-family: var(--head); font-size: 1.12rem; font-weight: 400; padding: .5em .9em;
  clip-path: polygon(0 0, 94% 0, 100% 50%, 94% 100%, 0 100%);
}
.tabs button:hover { background: #ebd5a4; }
.tabs button.on { background: var(--mesa); color: var(--bone); box-shadow: 0 3px 0 var(--mesa-dark); }
.tabs button .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--turq); margin-left: 6px; vertical-align: middle; }
@media (max-width: 760px) {
  .outpost { grid-template-columns: 1fr; }
  .tabs { flex-direction: row; overflow-x: auto; position: static; padding-bottom: 6px; }
  .tabs button { flex: 0 0 auto; clip-path: none; }
}

table.market { width: 100%; border-collapse: collapse; }
table.market th { text-align: left; font-family: var(--head); font-weight: 400; font-size: 1.1rem; border-bottom: 2px solid var(--dune); padding: 6px 8px; }
table.market td { border-bottom: 1px dashed #d8c39b; padding: 8px; vertical-align: middle; }
table.market td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.wrapx { overflow-x: auto; }
.qty { width: 70px; display: inline-block; }

.inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.inv-grid .cell { background: #fffaf0; border: 1px solid #e0cda5; border-radius: var(--radius-s); padding: 8px 10px; }
.inv-grid .cell b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }

.choice { display: grid; gap: 10px; }
.choice button.opt {
  text-align: left; background: #fffaf0; color: var(--canyon); box-shadow: inset 0 0 0 2px var(--dune);
  font-weight: 400; padding: 12px 14px; display: block; width: 100%;
}
.choice button.opt:hover { box-shadow: inset 0 0 0 2px var(--turq); background: #fff; }
.choice button.opt.picked { box-shadow: inset 0 0 0 3px var(--mesa); background: #fbe9dd; }
.choice button.opt strong { display: block; font-size: 1.05rem; }
.choice button.opt.right { box-shadow: inset 0 0 0 3px var(--sage); background: #e9eedb; }
.choice button.opt.wrong { box-shadow: inset 0 0 0 3px var(--mesa); background: #f6dccf; }

.streak { display: flex; gap: 6px; margin: 6px 0 14px; }
.streak i { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--dune-dark); }
.streak i.on { background: var(--sage); border-color: var(--sage); }

/* ---------- travel ---------- */
.trail {
  position: relative; border-radius: var(--radius-m); overflow: hidden;
  background: linear-gradient(#f4c98a 0%, #efb578 38%, #d99a5e 60%, #c58a52 100%);
  height: 260px; border: 1px solid #b58a55;
}
.trail .sun { position: absolute; width: 54px; height: 54px; border-radius: 50%; background: #fff3c9; box-shadow: 0 0 40px 18px rgba(255, 239, 190, .7); transition: left 1s linear, top 1s linear; }
.trail .mesas { position: absolute; left: 0; bottom: 70px; width: 100%; height: 90px; }
.trail .ground { position: absolute; left: 0; right: 0; bottom: 0; height: 74px; background: #b98049; }
.trail .river { position: absolute; left: 3%; right: 3%; bottom: 30px; height: 10px; border-radius: 99px; background: var(--turq); opacity: .85; }
.trail .river.dry { background: #8f6a3f; opacity: .6; }
.trail .party { position: absolute; bottom: 30px; transform: translate(-50%, 0); transition: left 1s linear; font-size: 34px; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .35)); }
.trail .flag { position: absolute; bottom: 44px; transform: translateX(-50%); font-family: var(--head); color: var(--bone); font-size: .9rem; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); white-space: nowrap; }
.trail .mark { position: absolute; bottom: 24px; width: 3px; height: 22px; background: var(--canyon); transform: translateX(-50%); }
.daybig { font-family: var(--head); font-size: 3.2rem; line-height: 1; }
.travel-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 16px 0; }
.travel-stats .s { background: #fffaf0; border: 1px solid #e0cda5; border-radius: var(--radius-s); padding: 10px 12px; }
.travel-stats .s b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.bar { height: 14px; background: #e3d2ad; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--sage); transition: width .5s; }
.bar.warn i { background: #d58a2f; }
.bar.low i { background: var(--mesa); }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(41, 27, 18, .62); z-index: 50; display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.modal { width: min(820px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; animation: rise .25s ease-out; }
.modal.wide { width: min(1080px, 100%); }
.modal .art { border-radius: var(--radius-s); margin-bottom: 12px; max-height: 260px; width: 100%; object-fit: cover; }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- encounter tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 14px 0; }
.tiles button {
  aspect-ratio: 1; background: #c99b5c; box-shadow: 0 3px 0 var(--dune-dark), inset 0 0 0 3px #e6c48f;
  font-family: var(--head); font-size: 1.6rem; color: var(--canyon); padding: 0;
}
.tiles button.win { background: var(--sage); color: var(--bone); }
.tiles button.lose { background: var(--mesa); color: var(--bone); }
.tiles button.dim { opacity: .55; }
@media (max-width: 560px) { .tiles { grid-template-columns: repeat(5, 1fr); gap: 6px; } .tiles button { font-size: 1.1rem; } }

/* ---------- hunting ---------- */
.hunt { position: relative; border-radius: var(--radius-m); overflow: hidden; border: 1px solid #b58a55; }
.hunt img.land { width: 100%; }
.hunt .spot {
  position: absolute; transform: translate(-50%, -50%);
  background: rgba(248, 239, 220, .88); color: var(--canyon); box-shadow: 0 2px 0 var(--dune-dark);
  font-size: .82rem; padding: .3em .6em; border-radius: 99px; font-weight: 700;
}
.hunt .spot.found { background: transparent; box-shadow: none; padding: 0; }
.hunt .spot.found img { width: 84px; border-radius: 8px; border: 3px solid var(--sage); background: var(--bone); }
.hunt .spot.empty { background: rgba(120, 90, 60, .75); color: #f1e1c2; }
@media (max-width: 600px) { .hunt .spot { font-size: .68rem; } .hunt .spot.found img { width: 52px; } }

/* ---------- foraging ---------- */
.cards { display: grid; gap: 8px; margin: 12px auto; max-width: 620px; }
.card { aspect-ratio: 3/4; perspective: 600px; padding: 0; background: none; box-shadow: none; border-radius: 8px; }
.card:hover { background: none; }
.card .inner { position: relative; width: 100%; height: 100%; transition: transform .35s; transform-style: preserve-3d; }
.card.up .inner, .card.done .inner { transform: rotateY(180deg); }
.card .face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 8px; overflow: hidden; border: 2px solid #b49461; background: #fbf3e2; }
.card .back { background: url('../img/card_back.jpg') center/cover; }
.card .front { transform: rotateY(180deg); display: flex; flex-direction: column; }
.card .front img, .card .front svg { flex: 1; width: 100%; min-height: 0; object-fit: cover; object-position: center 35%; }
.card .front span { font-size: .72rem; font-weight: 700; padding: 2px 3px; text-align: center; background: #f3e3bf; color: var(--canyon); line-height: 1.1; }
.card.done .face { border-color: var(--sage); }
.card.blank { visibility: hidden; }

/* ---------- surgery / journal ---------- */
.surgery { position: relative; max-width: 620px; margin: 0 auto; }
.surgery .organ { position: absolute; transform: translate(-50%, -50%); font-size: .78rem; padding: .3em .6em; border-radius: 99px; background: rgba(248, 239, 220, .92); color: var(--canyon); box-shadow: 0 2px 0 var(--dune-dark); }
canvas.sketch { width: 100%; max-width: 520px; aspect-ratio: 4/3; background: #fffaf0; border: 2px solid var(--dune); border-radius: var(--radius-s); touch-action: none; cursor: crosshair; }
.journal-entry { display: grid; grid-template-columns: 160px 1fr; gap: 14px; align-items: start; }
.journal-entry img { border-radius: var(--radius-s); border: 1px solid #d0b88a; }
.check { list-style: none; padding: 0; margin: 0; }
.check li { padding: 6px 0 6px 30px; position: relative; border-bottom: 1px dashed #dac69e; }
.check li::before { content: ''; position: absolute; left: 0; top: 9px; width: 18px; height: 18px; border: 2px solid var(--dune-dark); border-radius: 3px; }
.check li.ok::before { background: var(--sage); border-color: var(--sage); }

/* grizzly */
.bear-run { position: relative; height: 150px; background: linear-gradient(#e8c48d, #c99a5d); border-radius: var(--radius-m); overflow: hidden; margin: 12px 0; }
.bear-run img { position: absolute; bottom: 6px; height: 120px; transition: left .1s linear; border-radius: 6px; }
.bear-run .crew { position: absolute; left: 10px; bottom: 16px; font-size: 44px; }
.shots { display: flex; gap: 4px; flex-wrap: wrap; margin: 6px 0; }
.shots i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--canyon-soft); }
.shots i.on { background: var(--canyon); }

/* certificate */
.certificate { background: #fbf4e3; border: 10px double var(--dune-dark); padding: 40px 34px; text-align: center; font-family: var(--head); }
.certificate h1 { font-size: 2.6rem; }
.certificate .name { font-size: 2.2rem; border-bottom: 1px solid var(--canyon); display: inline-block; padding: 0 30px 4px; margin: 10px 0 16px; }
.score-table { width: 100%; max-width: 480px; margin: 12px auto; border-collapse: collapse; font-family: var(--body); text-align: left; }
.score-table td { padding: 6px 8px; border-bottom: 1px dashed #d8c39b; }
.score-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
@media print { .ledger, .noprint { display: none !important; } body { background: #fff; } }

/* perished */
.perished { background: url('../img/perished.jpg') center/cover; border-radius: var(--radius-m); min-height: 420px; display: grid; place-items: center; text-align: center; color: #f3e6cf; padding: 30px; }
.perished .box { background: rgba(30, 20, 14, .72); padding: 24px 28px; border-radius: var(--radius-m); max-width: 560px; }
.perished h1 { color: #f8efdc; }

/* toast */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--canyon); color: var(--bone); padding: 10px 18px; border-radius: var(--radius-s); box-shadow: 0 6px 20px rgba(0, 0, 0, .3); max-width: 90vw; }

/* leaderboard */
table.board { width: 100%; border-collapse: collapse; }
table.board td, table.board th { padding: 6px 8px; border-bottom: 1px dashed #d8c39b; text-align: left; }
table.board th { font-family: var(--head); font-weight: 400; }
.certificate p { margin-left: auto; margin-right: auto; }
@media (max-width: 700px) {
  .ledger { position: static; gap: 4px 14px; padding: 8px 12px; font-size: .85rem; }
  .ledger .who { width: 100%; }
  h1 { font-size: 2rem; }
  .panel { padding: 16px; }
}
