/* Tradelane — leather desk, parchment chart, brass fittings. */
:root {
  --paper: #e9dcbd;
  --paper-hi: #f3e8ca;
  --ink: #2a2118;
  --ink-soft: #5b4a33;
  --ox: #7d2f26;
  --brass: #b08a45;
  --brass-hi: #d6b169;
  --leather: #211a13;
  --leather-2: #2c2318;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--leather);
  color: var(--paper);
  font-family: var(--serif);
  overscroll-behavior: none;
}

body {
  background-image:
    radial-gradient(120% 80% at 50% 0%, #33291d 0%, #1c1610 70%);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 10px calc(6px + env(safe-area-inset-bottom));
  gap: 6px;
}

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

.top {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "brand purse" "mtg mtg";
  gap: 2px 10px;
  padding: 8px 2px 6px;
  border-bottom: 1px solid rgba(176,138,69,0.35);
}

.brand { grid-area: brand; min-width: 0; }
.brand-name {
  display: block;
  font-size: 13px;
  letter-spacing: 3.6px;
  font-weight: 600;
  color: var(--brass-hi);
  text-shadow: 0 1px 0 #000;
}
.brand-sub {
  display: block;
  font-size: 11px;
  letter-spacing: 0.7px;
  color: rgba(233,220,189,0.62);
  font-style: italic;
}

.purse { grid-area: purse; text-align: right; }
.cash {
  display: block;
  font-size: 25px;
  line-height: 1;
  letter-spacing: 0.4px;
  color: var(--paper-hi);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 0 #000;
  transition: transform 90ms ease-out;
}
.cash.tick { transform: scale(1.06); }
.purse-sub {
  display: block;
  font-size: 11px;
  letter-spacing: 0.4px;
  color: rgba(233,220,189,0.62);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.mtg {
  grid-area: mtg;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-top: 1px;
}
.mtg-k {
  font-size: 10px;
  letter-spacing: 1.6px;
  color: rgba(176,138,69,0.8);
}
.mtg-v {
  font-size: 11.5px;
  color: rgba(233,220,189,0.75);
  font-variant-numeric: tabular-nums;
}
.mtg.due .mtg-v { color: #f0a08b; }
.mtg.due .mtg-k { color: #e0765b; }

/* ---------- the chart ---------- */

.chartwrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 220px;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 2px 0 rgba(0,0,0,0.5), 0 10px 26px rgba(0,0,0,0.45), inset 0 0 0 1px rgba(0,0,0,0.5);
  background: var(--paper);
  touch-action: manipulation;
}
.chartwrap canvas { display: block; width: 100%; height: 100%; }

.chalk {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ---------- sail plate ---------- */

.sailplate {
  flex: 0 0 auto;
  display: block;
  width: 100%;
  min-height: 54px;
  padding: 8px 14px;
  border: 1px solid rgba(0,0,0,0.55);
  border-radius: 3px;
  background: linear-gradient(180deg, #c8a05a 0%, #ab8340 46%, #8d6a30 100%);
  color: #241a0e;
  font-family: var(--serif);
  text-align: left;
  box-shadow: inset 0 1px 0 rgba(255,238,198,0.55), 0 2px 0 rgba(0,0,0,0.45), 0 6px 14px rgba(0,0,0,0.35);
  transition: transform 70ms ease-out, filter 120ms;
  cursor: pointer;
}
.sailplate:active { transform: translateY(1px) scale(0.995); filter: brightness(0.96); }
.sailplate.armed { background: linear-gradient(180deg, #d7b06a 0%, #b98f45 46%, #96712f 100%); }
.sailplate.off {
  background: linear-gradient(180deg, #4a4034, #3b332a);
  color: rgba(233,220,189,0.55);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
  cursor: default;
}
.sail-main {
  display: block;
  font-size: 14.5px;
  letter-spacing: 0.4px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.sail-sub {
  display: block;
  font-size: 11px;
  margin-top: 2px;
  letter-spacing: 0.3px;
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
}
.sailplate.off .sail-main { font-weight: 500; }

/* ---------- hint ---------- */

.hint {
  margin: 0;
  padding: 0 2px;
  min-height: 15px;
  font-size: 11.5px;
  line-height: 1.25;
  letter-spacing: 0.2px;
  color: rgba(233,220,189,0.8);
  font-style: italic;
}
.hint b { font-style: normal; color: var(--brass-hi); font-weight: 600; }

/* ---------- ledger ---------- */

.ledger {
  flex: 0 1 auto;
  min-height: 150px;
  max-height: 44vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border-radius: 3px;
  box-shadow: 0 8px 22px rgba(0,0,0,0.4), inset 0 0 0 1px rgba(0,0,0,0.28);
  overflow: hidden;
  background-image:
    repeating-linear-gradient(180deg, rgba(107,79,38,0.05) 0 1px, transparent 1px 26px);
}

.ledger-head {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 12px 5px;
  border-bottom: 1px solid rgba(42,33,24,0.3);
  background: rgba(107,79,38,0.07);
}
.ledger-head h2 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 1.7px;
  text-transform: uppercase;
  font-weight: 600;
}
.ledger-head p {
  margin: 0;
  font-size: 9.5px;
  letter-spacing: 0.2px;
  color: rgba(42,33,24,0.66);
  text-align: right;
  font-style: italic;
}

.goods {
  list-style: none;
  margin: 0;
  padding: 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  scrollbar-width: thin;
}

.row {
  display: grid;
  grid-template-columns: 1fr 34px 88px 62px;
  grid-template-areas: "name spark buy sell" "sub spark buy sell";
  align-items: center;
  column-gap: 5px;
  padding: 3px 6px 3px 11px;
  min-height: 48px;
  border-bottom: 1px solid rgba(42,33,24,0.13);
  position: relative;
  transition: background 260ms ease-out;
}
.row.flash-buy { background: rgba(176,138,69,0.28); }
.row.flash-sell { background: rgba(125,47,38,0.16); }
.row.glut::after {
  content: attr(data-glut);
  position: absolute;
  right: 100px;
  top: 6px;
  font-size: 10px;
  color: var(--ox);
  font-weight: 600;
  animation: glutfade 1.6s ease-out forwards;
  pointer-events: none;
}
@keyframes glutfade {
  0% { opacity: 0; transform: translateY(4px); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-6px); }
}

.name {
  grid-area: name;
  font-size: 13px;
  letter-spacing: 0.5px;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sub {
  grid-area: sub;
  font-size: 10px;
  color: rgba(42,33,24,0.6);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  white-space: nowrap;
}
.spark {
  grid-area: spark;
  width: 44px;
  height: 26px;
  display: block;
  opacity: 0.85;
}

.trade {
  width: 100%;
  height: 44px;
  border-radius: 2px;
  border: 1px solid rgba(42,33,24,0.55);
  background: linear-gradient(180deg, rgba(243,232,202,0.95), rgba(224,208,170,0.95));
  color: var(--ink);
  font-family: var(--serif);
  font-size: 9px;
  letter-spacing: 1.1px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: transform 60ms ease-out, background 120ms;
  box-shadow: 0 1px 0 rgba(255,255,255,0.55) inset;
}
.trade:active { transform: scale(0.94); background: #cdb98f; }
.trade.buy { grid-area: buy; }
.trade.sell { grid-area: sell; color: var(--ox); }
.trade[disabled] {
  opacity: 0.3;
  cursor: default;
  transform: none;
}
.trade i {
  display: block;
  white-space: nowrap;
  font-style: normal;
  font-size: 9.5px;
  line-height: 1.2;
  letter-spacing: 0.2px;
  opacity: 0.78;
}
.trade b {
  display: block;
  white-space: nowrap;
  font-size: 9.5px;
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.trade.sell[disabled] { color: var(--ink); }

.yard {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  border-top: 1px solid rgba(42,33,24,0.35);
  background: rgba(42,33,24,0.2);
}
.yard-btn {
  display: block;
  padding: 7px 10px;
  min-height: 46px;
  border: 0;
  background: rgba(233,220,189,0.9);
  font-family: var(--serif);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background 120ms;
}
.yard-btn:active { background: #d8c49b; }
.yard-btn[disabled] { opacity: 0.42; cursor: default; }
.yard-k {
  display: block;
  font-size: 9px;
  letter-spacing: 1.4px;
  color: rgba(42,33,24,0.65);
  text-transform: uppercase;
}
.yard-v {
  display: block;
  font-size: 12px;
  letter-spacing: 0.2px;
  font-variant-numeric: tabular-nums;
}

/* ---------- toast ---------- */

.toast[hidden] { display: none; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translate(-50%, 8px);
  max-width: min(420px, calc(100vw - 28px));
  padding: 9px 14px;
  background: rgba(243,232,202,0.97);
  color: var(--ink);
  border: 1px solid rgba(42,33,24,0.4);
  border-left: 3px solid var(--ox);
  border-radius: 2px;
  font-size: 12px;
  line-height: 1.3;
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  opacity: 0;
  transition: opacity 200ms, transform 200ms;
  pointer-events: none;
  z-index: 40;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- coach marks ---------- */

.spot {
  position: absolute;
  width: 62px; height: 62px;
  margin: -31px 0 0 -31px;
  border-radius: 50%;
  border: 2px solid rgba(125,47,38,0.85);
  box-shadow: 0 0 0 4px rgba(125,47,38,0.14);
  pointer-events: none;
  z-index: 20;
  animation: spotpulse 1.7s ease-out infinite;
}
@keyframes spotpulse {
  0% { transform: scale(0.82); opacity: 0.95; }
  70% { transform: scale(1.14); opacity: 0.15; }
  100% { transform: scale(1.24); opacity: 0; }
}

.coach {
  position: absolute;
  z-index: 30;
  max-width: 268px;
  padding: 11px 13px 10px;
  background: rgba(243,232,202,0.98);
  color: var(--ink);
  border: 1px solid rgba(42,33,24,0.55);
  border-radius: 2px;
  box-shadow: 0 8px 22px rgba(0,0,0,0.45);
  font-size: 12px;
  line-height: 1.35;
}
.coach p { margin: 0 0 8px; }
.coach-go {
  display: inline-block;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid rgba(42,33,24,0.5);
  background: #d8c49b;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 2px;
}
.coach-arrow {
  position: absolute;
  width: 12px; height: 12px;
  background: rgba(243,232,202,0.98);
  border-left: 1px solid rgba(42,33,24,0.55);
  border-bottom: 1px solid rgba(42,33,24,0.55);
  transform: rotate(45deg);
}
.coach.below .coach-arrow { top: -7px; left: 24px; transform: rotate(135deg); }
.coach.above .coach-arrow { bottom: -7px; left: 24px; transform: rotate(-45deg); }

/* ---------- career end ---------- */

.over[hidden] { display: none; }
.over {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(16,12,8,0.78);
  backdrop-filter: blur(2px);
}
.over-card {
  width: 100%;
  max-width: 360px;
  max-height: 88vh;
  overflow: auto;
  padding: 20px 20px 18px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid rgba(42,33,24,0.6);
  box-shadow: 0 20px 50px rgba(0,0,0,0.6), inset 0 0 0 4px rgba(243,232,202,0.6), inset 0 0 0 5px rgba(42,33,24,0.18);
  background-image: repeating-linear-gradient(180deg, rgba(107,79,38,0.05) 0 1px, transparent 1px 24px);
}
.over-kicker {
  margin: 0 0 6px;
  font-size: 9px;
  letter-spacing: 2.4px;
  color: var(--ox);
}
.over-card h2 {
  margin: 0 0 8px;
  font-size: 21px;
  line-height: 1.15;
  letter-spacing: 0.2px;
}
.over-body {
  margin: 0 0 12px;
  font-size: 12.5px;
  line-height: 1.45;
  color: rgba(42,33,24,0.8);
}
.over-stats {
  margin: 0 0 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 12px;
  font-size: 12px;
  border-top: 1px solid rgba(42,33,24,0.25);
  padding-top: 10px;
}
.over-stats dt { color: rgba(42,33,24,0.62); }
.over-stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.over-btn {
  display: block;
  width: 100%;
  min-height: 48px;
  border: 1px solid rgba(42,33,24,0.6);
  background: linear-gradient(180deg, #c8a05a, #96712f);
  color: #241a0e;
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 2px;
}

/* ---------- wider screens ---------- */

@media (min-width: 640px) {
  .app {
    max-width: 980px;
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(320px, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "top top"
      "chart ledger";
    gap: 10px;
    padding: 10px 14px 12px;
    height: 100dvh;
  }
  .top { grid-area: top; }
  .chartwrap { grid-area: chart; min-height: 420px; }
  .sailplate { grid-area: chart; align-self: end; margin: 0 0 10px; width: calc(100% - 20px); margin-left: 10px; }
  .hint { grid-area: chart; align-self: end; margin: 0 0 68px 14px; }
  .ledger { grid-area: ledger; min-height: 0; }
}
