/* ============================================================
   House — guild ledger
   A ship's manifest: ruled rows, tabular figures, running balances.
   Palette drawn from Tales of Pirates' tropical water rather than
   the usual weathered-parchment pirate cliche.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,900&family=Karla:wght@400;500;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --ink:    #071219;   /* deep hull, page */
  --hull:   #0D2130;   /* raised surface */
  --rope:   #1B3B52;   /* rules and borders */
  --teal:   #2BB3A3;   /* shallow water, primary */
  --brass:  #E0A93B;   /* currency */
  --coral:  #E2664F;   /* deductions */
  --sail:   #EDE6D8;   /* primary text */
  --mist:   #8FA8B8;   /* secondary text */

  --display: 'Fraunces', Georgia, serif;
  --body:    'Karla', system-ui, sans-serif;
  --data:    'IBM Plex Mono', ui-monospace, monospace;

  --rail: 216px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--sail);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.55;
  /* faint horizon band, like light on water at the top of the hold */
  background-image:
    radial-gradient(1200px 340px at 50% -160px, rgba(43,179,163,.13), transparent 70%);
  background-repeat: no-repeat;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- shell ---------- */

.shell { display: flex; min-height: 100vh; }

.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  border-right: 1px solid var(--rope);
  padding: 28px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.mark {
  font-family: var(--display);
  font-weight: 900;
  font-size: 30px;
  letter-spacing: -.02em;
  line-height: .95;
  color: var(--sail);
  font-variation-settings: 'SOFT' 40, 'WONK' 1;
}
.mark span { display: block; font-family: var(--data); font-size: 10px;
  letter-spacing: .22em; text-transform: uppercase; color: var(--mist);
  font-weight: 500; margin-top: 8px; }

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a {
  color: var(--mist);
  padding: 8px 10px;
  border-left: 2px solid transparent;
  font-size: 14px;
  transition: color .14s, border-color .14s;
}
.nav a:hover { color: var(--sail); text-decoration: none; }
.nav a[aria-current] { color: var(--sail); border-left-color: var(--teal); }

.rail footer {
  margin-top: auto;
  font-family: var(--data);
  font-size: 10.5px;
  color: var(--mist);
  letter-spacing: .04em;
  line-height: 1.7;
}

main { flex: 1; min-width: 0; padding: 40px 44px 90px; max-width: 1180px; }

/* ---------- headings ---------- */

.eyebrow {
  font-family: var(--data);
  font-size: 10.5px;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--teal);
  margin: 0 0 10px;
}

h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(30px, 4.4vw, 44px);
  letter-spacing: -.02em;
  line-height: 1.05;
  margin: 0 0 8px;
  font-variation-settings: 'SOFT' 30, 'WONK' 1;
}

.lede { color: var(--mist); margin: 0 0 34px; max-width: 62ch; }

h2 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -.01em;
  margin: 44px 0 14px;
}

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

.ledger { width: 100%; border-collapse: collapse; }

.ledger thead th {
  font-family: var(--data);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--mist);
  text-align: left;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--rope);
  white-space: nowrap;
}

.ledger tbody tr { border-bottom: 1px solid rgba(27,59,82,.5); }
.ledger tbody tr:hover { background: rgba(43,179,163,.05); }
.ledger td { padding: 13px 12px; vertical-align: middle; }

.ledger .num {
  font-family: var(--data);
  font-variant-numeric: tabular-nums;
  font-size: 13.5px;
  text-align: right;
  white-space: nowrap;
}

.pos { color: var(--teal); }
.neg { color: var(--coral); }
.gp  { color: var(--brass); }

.rowidx {
  font-family: var(--data);
  font-size: 11px;
  color: var(--rope);
  width: 34px;
  text-align: right;
}

/* ---------- rank pennants ----------
   Maritime signal flags: each rank gets its own device, so rank is
   readable at a glance without reading the word. */

.rank { display: inline-flex; align-items: center; gap: 9px; white-space: nowrap; }

.pennant {
  width: 20px; height: 14px;
  border: 1px solid rgba(237,230,216,.35);
  flex: 0 0 auto;
  border-radius: 1px;
}
.pennant.t1 { background: #35566B; }
.pennant.t2 { background: linear-gradient(135deg, var(--teal) 50%, #0D2130 50%); }
.pennant.t3 { background:
  linear-gradient(90deg, var(--teal) 50%, #0D2130 50%),
  linear-gradient(0deg, var(--teal) 50%, #0D2130 50%);
  background-size: 100% 50%, 100% 50%;
  background-position: top, bottom;
  background-repeat: no-repeat; }
.pennant.t4 { background: var(--brass); position: relative; }
.pennant.t4::after {
  content: ''; position: absolute; inset: 3px;
  background: #0D2130;
  clip-path: polygon(50% 0,61% 35%,98% 35%,68% 57%,79% 92%,50% 70%,21% 92%,32% 57%,2% 35%,39% 35%);
}

.rank-name { font-size: 14px; }

/* ---------- waterline: XP toward next rank ----------
   Progress as a rising tide rather than a filled bar. */

.waterline {
  position: relative;
  height: 7px;
  background: rgba(27,59,82,.55);
  border-radius: 4px;
  overflow: hidden;
  min-width: 90px;
}
.waterline i {
  position: absolute; inset: 0 auto 0 0;
  background: linear-gradient(90deg, #1B7F80, var(--teal));
  border-radius: 4px;
  animation: rise .7s cubic-bezier(.22,.8,.3,1) both;
  transform-origin: left;
}
.waterline.full i { background: linear-gradient(90deg, #A8791F, var(--brass)); }

@keyframes rise { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@media (prefers-reduced-motion: reduce) {
  .waterline i { animation: none; }
}

.xpnote {
  font-family: var(--data);
  font-size: 11px;
  color: var(--mist);
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}

/* ---------- cards ---------- */

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 14px; margin-bottom: 34px; }

.card {
  background: var(--hull);
  border: 1px solid var(--rope);
  border-radius: 3px;
  padding: 18px 18px 16px;
}
.card .k {
  font-family: var(--data);
  font-size: 10px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--mist); margin-bottom: 9px;
}
.card .v {
  font-family: var(--data);
  font-size: 27px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  line-height: 1;
}
.card .sub { font-size: 12px; color: var(--mist); margin-top: 7px; }

/* ---------- market ---------- */

.listing {
  background: var(--hull);
  border: 1px solid var(--rope);
  border-left: 2px solid var(--teal);
  border-radius: 3px;
  padding: 15px 17px;
  margin-bottom: 11px;
}
.listing.buy { border-left-color: #4A9BD1; }
.listing header { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; margin-bottom: 11px; }
.listing h3 { margin: 0; font-family: var(--body); font-size: 15px; font-weight: 700; }
.listing .when { font-family: var(--data); font-size: 10.5px; color: var(--mist); white-space: nowrap; }
.listing ul { list-style: none; margin: 0; padding: 0; }
.listing li { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: 14px; }
.listing li img { width: 22px; height: 22px; image-rendering: pixelated; flex: 0 0 auto; }
.listing li .price { margin-left: auto; font-family: var(--data); font-size: 13px; color: var(--brass); font-variant-numeric: tabular-nums; }
.listing .note { margin-top: 11px; padding-top: 11px; border-top: 1px solid var(--rope); font-size: 13px; color: var(--mist); font-style: italic; }

.tag {
  font-family: var(--data); font-size: 9.5px; letter-spacing: .14em; text-transform: uppercase;
  padding: 2px 7px; border: 1px solid currentColor; border-radius: 2px;
}
.tag.sell { color: var(--teal); }
.tag.buy  { color: #4A9BD1; }

/* ---------- forms ---------- */

form.stack { display: flex; flex-direction: column; gap: 13px; max-width: 340px; }
label { font-family: var(--data); font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--mist); display: block; margin-bottom: 6px; }
input[type=text], input[type=password] {
  width: 100%;
  background: var(--ink);
  border: 1px solid var(--rope);
  border-radius: 2px;
  color: var(--sail);
  font-family: var(--data);
  font-size: 14px;
  padding: 10px 12px;
}
input:focus { border-color: var(--teal); outline: none; }
button {
  background: var(--teal); color: #04161A;
  border: 0; border-radius: 2px;
  font-family: var(--body); font-weight: 700; font-size: 14px;
  padding: 11px 20px; cursor: pointer;
}
button:hover { background: #35C8B6; }
button.ghost { background: transparent; color: var(--mist); border: 1px solid var(--rope); }
button.ghost:hover { color: var(--sail); border-color: var(--mist); }

.alert { border-left: 2px solid var(--coral); background: rgba(226,102,79,.09); padding: 11px 14px; font-size: 13.5px; margin-bottom: 16px; }
.ok    { border-left: 2px solid var(--teal); background: rgba(43,179,163,.09); padding: 11px 14px; font-size: 13.5px; margin-bottom: 16px; }

.empty { color: var(--mist); padding: 40px 0; text-align: center; }
.empty strong { display: block; color: var(--sail); font-family: var(--display); font-size: 17px; margin-bottom: 5px; }

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

.who { display: flex; align-items: center; gap: 11px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--rope); flex: 0 0 auto; }
.mut { color: var(--mist); }
.right { text-align: right; }

.pill { font-family: var(--data); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--brass); border: 1px solid rgba(224,169,59,.4); padding: 1px 6px; border-radius: 2px; margin-left: 7px; }

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

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .rail {
    width: auto; flex: none; height: auto; position: static;
    border-right: 0; border-bottom: 1px solid var(--rope);
    padding: 20px; gap: 16px;
  }
  .rail footer { display: none; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .nav a { border-left: 0; border-bottom: 2px solid transparent; padding: 5px 9px; }
  .nav a[aria-current] { border-left-color: transparent; border-bottom-color: var(--teal); }
  main { padding: 26px 18px 70px; }
  .ledger .hide-sm { display: none; }
  .ledger td, .ledger thead th { padding-left: 7px; padding-right: 7px; }
}

/* ---------- rank emblems ---------- */

.emblem {
  flex: 0 0 auto;
  vertical-align: middle;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.5));
}

.rank { gap: 8px; }
.rank-name { font-weight: 500; letter-spacing: .01em; }

/* the top rank earns a little light */
.rank:has(.emblem) .rank-name { line-height: 1.2; }

.card .v .rank { font-size: 17px; }

/* ---------- redemptions ---------- */

.toolbar {
  display: flex; align-items: center; gap: 12px;
  margin: 0 0 22px; flex-wrap: wrap;
}
.toolbar input[type=text] { max-width: 320px; flex: 1 1 220px; }
.toolbar .mut { font-family: var(--data); font-size: 11.5px; white-space: nowrap; }

.redeem-grid {
  display: grid;
  grid-template-columns: minmax(0,1fr) 260px;
  gap: 26px;
  align-items: start;
}
.redeem-main { min-width: 0; overflow-x: auto; }

.nowrap { white-space: nowrap; }

/* icon and label need real air between them */
.withicon { display: inline-flex; align-items: center; gap: 12px; }
.withicon .iname { line-height: 1.3; }
.ico {
  width: 24px; height: 24px;
  image-rendering: pixelated;
  flex: 0 0 auto;
  display: inline-block;
}

/* ---------- totals panel ---------- */

.totals {
  background: var(--hull);
  border: 1px solid var(--rope);
  border-radius: 3px;
  padding: 16px 16px 12px;
  position: sticky;
  top: 26px;
}
.totals h2 { margin: 0 0 4px; font-size: 16px; }
.totals .xpnote { margin: 0 0 12px; }

.totals-scroll { max-height: 420px; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.totals-scroll::-webkit-scrollbar { width: 7px; }
.totals-scroll::-webkit-scrollbar-thumb { background: var(--rope); border-radius: 4px; }

.totals ul { list-style: none; margin: 0; padding: 0; }
.totals li {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(27,59,82,.45);
  font-size: 13.5px;
}
.totals li:last-child { border-bottom: 0; }
.totals .tname {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.totals li b {
  font-family: var(--data);
  font-variant-numeric: tabular-nums;
  color: var(--brass);
  font-size: 13px;
}

/* ---------- small icon buttons ---------- */

.iconbtn {
  background: transparent;
  border: 1px solid var(--rope);
  color: var(--mist);
  border-radius: 2px;
  padding: 4px 9px;
  font-size: 14px; line-height: 1.2;
  cursor: pointer;
}
.iconbtn:hover { color: var(--sail); border-color: var(--mist); background: transparent; }
button.danger { color: var(--coral); border-color: rgba(226,102,79,.45); }
button.danger:hover { color: #fff; background: var(--coral); border-color: var(--coral); }

/* ---------- centred sheet ---------- */

.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(3,8,12,.78);
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
}
.modal[hidden] { display: none !important; }

.sheet {
  background: var(--hull);
  border: 1px solid var(--rope);
  border-radius: 4px;
  box-shadow: 0 24px 70px rgba(0,0,0,.6);
  padding: 26px;
  width: 100%; max-width: 920px;
  margin: auto;
}
.sheet h2 { margin: 0 0 4px; }

.logrow {
  display: flex; gap: 8px; align-items: center;
  margin-bottom: 9px; flex-wrap: wrap;
}
.logrow input[type=date] { width: 148px; }
.logrow select { flex: 0 0 165px; }
.logrow input[type=text] { flex: 1 1 170px; min-width: 150px; }
.logrow .qtyin { width: 74px; }

.logrow select,
.logrow input[type=number],
.logrow input[type=date] {
  background: var(--ink);
  border: 1px solid var(--rope);
  border-radius: 2px;
  color: var(--sail);
  font-family: var(--data);
  font-size: 13px;
  padding: 10px;
}
.logrow select { font-family: var(--body); font-size: 14px; }
.logrow select:focus, .logrow input:focus { border-color: var(--teal); outline: none; }

.sheet-actions {
  display: flex; gap: 10px; align-items: center;
  margin-top: 18px; padding-top: 18px;
  border-top: 1px solid var(--rope);
  flex-wrap: wrap;
}

@media (max-width: 980px) {
  .redeem-grid { grid-template-columns: 1fr; }
  .totals { position: static; }
  .totals-scroll { max-height: 240px; }
}
@media (max-width: 700px) {
  .logrow { border: 1px solid var(--rope); border-radius: 3px; padding: 10px; }
  .logrow select, .logrow input[type=text] { flex: 1 1 100%; }
}
