/* Desert Trade: The Game — shared styles
   Palette pulled from the game's card art: sun-baked sand, carved wood,
   parchment, lapis blue panels with gold trim. */
:root {
  --sky: #f8ddaa;
  --sand: #e8c48a;
  --dune: #c98b45;
  --dune-deep: #9a5b26;
  --wood: #4b2e1a;
  --wood-mid: #6e4426;
  --parchment: #f3e2b9;
  --parchment-dark: #e2c993;
  --ink: #2b1a0e;
  --ink-soft: #5c4330;
  --lapis: #1e3a7b;
  --lapis-deep: #13285a;
  --gold: #c9a048;
  --gold-bright: #e6c56f;
  --danger: #8b2a1c;
  --oasis: #2c7464;
  --display: 'Grenze Gotisch', 'Palatino Linotype', Georgia, serif;
  --body: 'Alegreya', Georgia, 'Times New Roman', serif;
  --radius: 6px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--body);
  font-size: 1.125rem;
  line-height: 1.55;
  color: var(--ink);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320' preserveAspectRatio='none'%3E%3Cpath fill='%23d9a560' d='M0 190 C240 120 420 230 720 170 S1200 110 1440 160 V320 H0Z'/%3E%3Cpath fill='%23c98b45' d='M0 250 C300 190 520 290 860 240 S1260 210 1440 250 V320 H0Z'/%3E%3C/svg%3E") bottom / 100% 34vh no-repeat fixed,
    linear-gradient(180deg, var(--sky) 0%, #f2c98a 55%, var(--sand) 100%) fixed;
  font-variant-numeric: lining-nums;
}
img { max-width: 100%; display: block; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; line-height: 1.1; margin: 0 0 .4em; letter-spacing: .01em; }
h1 { font-size: clamp(2.4rem, 5vw, 3.6rem); }
h2 { font-size: clamp(1.8rem, 3.4vw, 2.5rem); }
h3 { font-size: 1.5rem; }
p { margin: 0 0 .8em; max-width: 68ch; }
a { color: var(--lapis); }
.num { font-variant-numeric: tabular-nums lining-nums; }
.muted { color: var(--ink-soft); }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid var(--lapis); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, var(--wood-mid), var(--wood));
  border-bottom: 3px solid var(--gold);
  color: var(--parchment);
  box-shadow: 0 4px 14px rgba(60, 30, 10, .35);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: .5rem 1rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.wordmark { font-family: var(--display); font-size: 1.9rem; color: var(--gold-bright); text-decoration: none; line-height: 1; }
.stats { display: flex; gap: 1.2rem; flex-wrap: wrap; align-items: baseline; margin-right: auto; }
.stat { display: flex; flex-direction: column; line-height: 1.1; }
.stat small { font-size: .78rem; color: #e9d3a6; }
.stat strong { font-size: 1.15rem; color: #fff6e0; }
.stat.money strong { color: var(--gold-bright); font-size: 1.35rem; }
.nav { display: flex; gap: .35rem; flex-wrap: wrap; }
.nav button {
  font: inherit; font-size: .98rem; cursor: pointer;
  background: transparent; color: var(--parchment);
  border: 1px solid rgba(230, 197, 111, .35); border-radius: var(--radius);
  padding: .3rem .7rem;
}
.nav button:hover:not(:disabled) { background: rgba(230, 197, 111, .15); }
.nav button[aria-current="page"] { background: var(--gold); color: var(--wood); border-color: var(--gold); font-weight: 700; }
.nav button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- layout ---------- */
main { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem 6rem; }
.parchment {
  background: var(--parchment);
  background-image: radial-gradient(ellipse at 20% 0%, rgba(255,255,255,.5), transparent 60%), radial-gradient(ellipse at 100% 100%, rgba(160,110,50,.18), transparent 55%);
  border: 6px solid var(--wood);
  border-radius: var(--radius);
  box-shadow: inset 0 0 0 2px var(--gold), 0 10px 30px rgba(80, 40, 10, .3);
  padding: clamp(1rem, 3vw, 2rem);
}
.lapis {
  background: radial-gradient(ellipse at 50% 0%, #2a4c97, var(--lapis-deep));
  color: #f4ead2;
  border: 3px solid var(--gold);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.lapis h3 { color: var(--gold-bright); }
.grid-2 { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 1.75rem; align-items: start; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* framed print for city art */
.print {
  background: #fff; padding: .6rem;
  border: 8px solid var(--wood);
  box-shadow: inset 0 0 0 2px var(--gold), 0 8px 24px rgba(80, 40, 10, .35);
  border-radius: 4px;
}

/* ---------- buttons & forms ---------- */
.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1.1rem; border-radius: var(--radius);
  border: 2px solid var(--gold);
  background: var(--lapis); color: #fff6e0;
  box-shadow: 0 3px 0 var(--lapis-deep);
  transition: transform .06s ease, box-shadow .06s ease;
}
.btn:hover:not(:disabled) { background: #26489a; }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--lapis-deep); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.wood { background: var(--wood-mid); box-shadow: 0 3px 0 var(--wood); }
.btn.wood:hover:not(:disabled) { background: #85552f; }
.btn.ghost { background: transparent; color: var(--wood); border-color: var(--wood-mid); box-shadow: none; }
.btn.ghost:hover:not(:disabled) { background: rgba(110, 68, 38, .1); }
.btn.sell { background: var(--oasis); box-shadow: 0 3px 0 #1a4a3f; }
.btn.sell:hover:not(:disabled) { background: #348a77; }
.btn.danger { background: var(--danger); border-color: #d79a6a; box-shadow: 0 3px 0 #5a1a10; }
.btn.big { font-size: 1.25rem; padding: .75rem 1.6rem; }
.btn.small { font-size: .95rem; padding: .3rem .7rem; }

label { display: block; font-weight: 700; margin-bottom: .2rem; }
input, select, textarea {
  font: inherit; width: 100%;
  padding: .5rem .65rem; border-radius: var(--radius);
  border: 2px solid var(--dune-deep); background: #fffaf0; color: var(--ink);
}
textarea { min-height: 5rem; resize: vertical; }
.field + .field { margin-top: .75rem; }
.hint { font-size: .92rem; color: var(--ink-soft); margin-top: .25rem; }

/* ---------- auth / hero ---------- */
.hero { position: relative; border: 6px solid var(--wood); border-radius: var(--radius); overflow: hidden; box-shadow: inset 0 0 0 2px var(--gold), 0 10px 30px rgba(80,40,10,.3); }
.hero img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.auth-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 1.5rem; }
@media (max-width: 760px) { .auth-grid { grid-template-columns: 1fr; } }

/* ---------- market ---------- */
.market-head { display: flex; justify-content: space-between; align-items: end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.shop-section + .shop-section { margin-top: 2rem; }
.shop-section > h2 { display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap; }
.shop-section > h2 small { font-family: var(--body); font-size: 1rem; font-weight: 400; color: var(--ink-soft); }
.shops { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.shop {
  background: #fbf0d5;
  border: 2px solid var(--dune-deep);
  border-top: 8px solid var(--dune-deep);
  border-radius: var(--radius);
  padding: .9rem 1rem 1rem;
  display: flex; flex-direction: column; gap: .5rem;
}
.shop.sells { border-top-color: var(--lapis); }
.shop.buys { border-top-color: var(--oasis); }
.shop .shop-name { font-size: .95rem; color: var(--ink-soft); }
.shop h3 { margin: 0; font-size: 1.6rem; }
.shop .desc { font-size: .98rem; margin: 0; }
.price { font-size: 1.5rem; font-weight: 700; }
.price small { font-size: .95rem; font-weight: 400; color: var(--ink-soft); }
.haggled { font-size: .9rem; font-weight: 700; padding: .1rem .5rem; border-radius: 99px; display: inline-block; }
.haggled.good { background: #d6eadf; color: #1d5547; }
.haggled.bad { background: #f2d3c8; color: #7a2416; }
.qty { display: flex; align-items: center; gap: .3rem; }
.qty input { width: 5.5rem; text-align: center; }
.qty button { width: 2.4rem; height: 2.4rem; padding: 0; font-size: 1.3rem; }
.shop .actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: auto; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--parchment-dark); vertical-align: top; }
th { font-family: var(--display); font-size: 1.15rem; border-bottom: 2px solid var(--wood-mid); }
td.right, th.right { text-align: right; }
tr.me td { background: rgba(201, 160, 72, .25); font-weight: 700; }
.table-wrap { overflow-x: auto; }
.rank { font-family: var(--display); font-size: 1.3rem; width: 3rem; }

/* ---------- travel ---------- */
.travel { text-align: center; }
.travel .counter { font-family: var(--display); font-size: clamp(5rem, 18vw, 10rem); line-height: 1; color: var(--wood); }
.travel .of { font-size: 1.2rem; color: var(--ink-soft); }
.route-strip { position: relative; margin: 1.5rem auto 0; max-width: 820px; height: 140px; }
.route-strip svg.dunes { position: absolute; inset: auto 0 0 0; width: 100%; height: 70px; }
.route-strip .camel { position: absolute; bottom: 30px; width: 104px; transform: translateX(-50%); transition: left .9s linear; }
.route-strip .end { position: absolute; bottom: 0; font-family: var(--display); font-size: 1.3rem; color: var(--wood); }
.route-strip .end.left { left: 0; }
.route-strip .end.right { right: 0; }
.encounter { max-width: 900px; margin: 1.5rem auto 0; text-align: center; }
.encounter img { border: 6px solid var(--wood); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(80,40,10,.35); }
.dice { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; margin-top: 1rem; }
.die {
  width: 4.2rem; height: 4.2rem; font-size: 2.6rem; line-height: 1; cursor: pointer;
  background: #fffaf0; color: var(--ink); border: 3px solid var(--wood); border-radius: 12px;
  box-shadow: 0 4px 0 var(--wood);
}
.die:hover { background: #fff; transform: translateY(-2px); }
.die:disabled { opacity: .5; cursor: wait; }
.outcome { margin: 1rem auto 0; max-width: 640px; font-size: 1.25rem; padding: 1rem 1.25rem; border-radius: var(--radius); border: 3px solid; }
.outcome.good { background: #e3f1e9; border-color: var(--oasis); }
.outcome.bad { background: #f8e0d6; border-color: var(--danger); }

/* ---------- level pages ---------- */
.level-title { text-align: center; max-width: 820px; margin: 0 auto; }
.level-title .lv { font-family: var(--display); font-size: 1.6rem; color: var(--dune-deep); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin: 1.5rem 0; }
.fact { background: #fbf0d5; border: 2px solid var(--dune-deep); border-radius: var(--radius); padding: .75rem; }
.fact small { display: block; color: var(--ink-soft); }
.fact strong { font-family: var(--display); font-size: 2rem; }
.instructions { font-size: 1.3rem; text-align: left; }

.log { list-style: none; padding: 0; margin: 0; max-height: 420px; overflow-y: auto; }
.log li { padding: .45rem 0; border-bottom: 1px dashed var(--parchment-dark); font-size: 1rem; }
.log li .when { color: var(--ink-soft); font-size: .88rem; display: block; }

/* ---------- toast & modal ---------- */
.toast-wrap { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 70; pointer-events: none; display: flex; flex-direction: column; gap: .5rem; width: min(92vw, 520px); }
.toast { background: var(--wood); color: var(--parchment); border: 2px solid var(--gold); border-radius: var(--radius); padding: .7rem 1rem; box-shadow: 0 8px 20px rgba(0,0,0,.3); animation: toast-in .2s ease-out; }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
.modal-back { position: fixed; inset: 0; background: rgba(40, 20, 5, .55); z-index: 60; display: grid; place-items: center; padding: 1rem; }
.modal { max-width: 520px; width: 100%; margin-bottom: 9rem; }
.modal .row { justify-content: flex-end; margin-top: 1rem; }

/* ---------- dashboard ---------- */
.dash-head { display: flex; justify-content: space-between; align-items: end; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.25rem; }
.dash-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 1.5rem; align-items: start; }
@media (max-width: 960px) { .dash-grid { grid-template-columns: 1fr; } }
.podium { display: grid; gap: .75rem; }
.podium .place { display: grid; grid-template-columns: 4rem 1fr auto; align-items: center; gap: 1rem; background: #fbf0d5; border: 2px solid var(--dune-deep); border-radius: var(--radius); padding: .75rem 1rem; }
.podium .place:first-child { background: linear-gradient(90deg, #f6dc8f, #fbf0d5); border-color: var(--gold); border-width: 3px; }
.podium .place .pos { font-family: var(--display); font-size: 2.6rem; text-align: center; color: var(--dune-deep); }
.podium .place .name { font-family: var(--display); font-size: 1.9rem; line-height: 1.1; }
.podium .place .avg { font-size: 1.7rem; font-weight: 700; text-align: right; }
.podium .place .avg small { display: block; font-size: .9rem; font-weight: 400; color: var(--ink-soft); }
.bars { display: grid; gap: .5rem; }
.bar { display: grid; grid-template-columns: 9rem 1fr 2.5rem; gap: .6rem; align-items: center; font-size: 1rem; }
.bar .track { height: 1rem; background: var(--parchment-dark); border-radius: 99px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--lapis); }

/* ---------- teacher ---------- */
.tabs { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs button { font: inherit; cursor: pointer; padding: .45rem .9rem; border-radius: var(--radius) var(--radius) 0 0; border: 2px solid var(--wood-mid); border-bottom: none; background: var(--parchment-dark); color: var(--wood); }
.tabs button[aria-selected="true"] { background: var(--parchment); font-weight: 700; }
.level-card { border: 2px solid var(--dune-deep); border-radius: var(--radius); padding: 1rem; background: #fbf0d5; }
.level-card + .level-card { margin-top: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; }
.price-table input { width: 6.5rem; padding: .3rem .4rem; }
.city-prices { border: 2px solid var(--dune-deep); border-radius: var(--radius); padding: .8rem 1rem; background: #fbf0d5; }
.city-prices-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 1rem; }
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 99px; font-size: .85rem; background: var(--parchment-dark); }
.pill.playing { background: #d6eadf; }
.pill.perished { background: #f2d3c8; }
.pill.complete, .pill.finished { background: #f6dc8f; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 700px) {
  .topbar { position: static; }
  .stats { gap: .8rem; }
}
