:root {
  --paper: #efe1bf;
  --paper-2: #e6d3a6;
  --paper-3: #d6bd87;
  --ink: #33241a;
  --ink-soft: #6a5236;
  --ink-faint: #a08a64;
  --rust: #9a3b20;
  --rust-dark: #742a15;
  --sea: #2c5a5e;
  --sea-soft: #9fb9ad;
  --gold: #a87a1f;
  --ok: #4c6b2f;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --display: "Didot", "Bodoni 72", "Bodoni MT", "Hoefler Text", "Iowan Old Style", Georgia, serif;
  --mono: "Courier Prime", "Courier New", ui-monospace, monospace;
  --shadow: 0 1px 0 rgba(255, 250, 235, 0.6) inset, 0 10px 30px -18px rgba(51, 36, 26, 0.55);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.5;
  background:
    radial-gradient(ellipse at 15% 10%, rgba(255, 248, 225, 0.9), transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(176, 134, 72, 0.35), transparent 60%),
    radial-gradient(ellipse at 50% 50%, var(--paper), var(--paper-2) 75%, var(--paper-3));
  background-attachment: fixed;
}
::selection { background: var(--rust); color: var(--paper); }
[hidden] { display: none !important; }

.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 100; opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.25 0 0 0 0 0.17 0 0 0 0 0.08 0 0 0 0.22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

h1, h2, h3 { font-family: var(--display); font-weight: 400; margin: 0; letter-spacing: 0.01em; }
h2 { font-size: 1.125rem; }
em { font-style: italic; color: var(--rust); }
small { color: var(--ink-soft); font-size: 0.8em; }

/* ---------- cards & buttons ---------- */
.card {
  background: linear-gradient(180deg, rgba(250, 242, 220, 0.75), rgba(236, 220, 182, 0.75));
  border: 1px solid var(--ink-soft);
  outline: 1px solid rgba(106, 82, 54, 0.35);
  outline-offset: 4px;
  box-shadow: var(--shadow);
  border-radius: 2px;
}
.btn {
  font: inherit; font-size: 0.875rem; letter-spacing: 0.04em;
  padding: 0.5rem 0.95rem; cursor: pointer;
  color: var(--ink); background: transparent;
  border: 1px solid var(--ink); border-radius: 0;
  transition: transform 0.15s ease, background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 2px 2px 0 var(--ink);
}
.btn:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); background-color: rgba(255, 250, 235, 0.6); }
.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; background: transparent; color: var(--ink-soft); border-color: var(--ink-faint); }
.btn-primary { background: var(--rust); color: #fbf1da; border-color: var(--rust-dark); box-shadow: 2px 2px 0 var(--rust-dark); }
.btn-primary:hover:not(:disabled) { background: var(--rust-dark); box-shadow: 3px 3px 0 var(--ink); }
.btn-sea { background: var(--sea); color: #f2ecd9; border-color: #1d3d40; box-shadow: 2px 2px 0 #1d3d40; }
.btn-sea:hover:not(:disabled) { background: #1f4549; }
.btn-ghost { box-shadow: none; border-color: transparent; text-decoration: underline; text-underline-offset: 3px; }
.btn-ghost:hover:not(:disabled) { box-shadow: none; background: transparent; color: var(--rust); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-block { width: 100%; }

input, select {
  font: inherit; color: var(--ink); width: 100%;
  padding: 0.55rem 0.65rem; margin-top: 0.3rem;
  background: rgba(255, 251, 238, 0.7);
  border: 1px solid var(--ink-soft); border-radius: 0;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
input:focus, select:focus { outline: 2px solid var(--sea); outline-offset: 1px; background: #fffbef; }
label { display: block; font-size: 0.9rem; }

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--ink-soft); margin-bottom: 1.25rem; flex-wrap: wrap; }
.tab {
  font: inherit; font-size: 0.95rem; background: none; border: none; cursor: pointer; color: var(--ink-soft);
  padding: 0.6rem 0.9rem; border-bottom: 3px solid transparent; margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--rust); }

/* ---------- auth ---------- */
.auth-screen {
  min-height: 100vh; display: grid; grid-template-columns: 1.2fr 1fr; gap: 4rem;
  align-items: center; padding: 6vh 8vw; max-width: 1400px; margin: 0 auto;
}
.eyebrow { font-family: var(--mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.25em; color: var(--rust); margin: 0 0 1rem; }
.title { font-size: clamp(3rem, 7vw, 6rem); line-height: 0.95; margin-bottom: 1.5rem; animation: rise 0.8s ease both; }
.lede { font-size: 1.1rem; max-width: 34rem; color: var(--ink-soft); animation: rise 0.8s 0.1s ease both; }
.hero-points { list-style: none; padding: 0; margin: 2rem 0 0; display: grid; gap: 0.6rem; animation: rise 0.8s 0.2s ease both; }
.hero-points li { padding-left: 1.6rem; position: relative; }
.hero-points li::before { content: "\2726"; position: absolute; left: 0; color: var(--rust); }
.auth-card { padding: 2rem; animation: rise 0.8s 0.25s ease both; }
.auth-form { display: grid; gap: 1rem; }
.form-error { color: var(--rust); min-height: 1.25rem; margin: 0; font-size: 0.9rem; }
.fine { font-size: 0.78rem; color: var(--ink-faint); margin: 0; }

/* PIN rules + taken-name suggestions */
.pin-rules { list-style: none; margin: -0.35rem 0 0; padding: 0.65rem 0.85rem; display: grid; gap: 0.25rem; font-size: 0.85rem; color: var(--ink-soft); background: rgba(255, 250, 235, 0.45); border: 1px dashed var(--ink-faint); border-radius: 4px; }
.pin-rules li span { display: inline-block; width: 1.1em; font-weight: 700; }
.pin-rules li.ok { color: var(--ok); }
.pin-rules li.bad { color: var(--rust); }
.suggest { margin-top: -0.35rem; padding: 0.65rem 0.85rem; background: rgba(255, 250, 235, 0.45); border: 1px dashed var(--rust); border-radius: 4px; }
.suggest-title { margin: 0 0 0.5rem; font-size: 0.85rem; color: var(--ink-soft); }
.suggest-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip { font: inherit; font-size: 0.9rem; padding: 0.45rem 0.8rem; min-height: 40px; color: var(--ink); background: var(--paper); border: 1px solid var(--rust); border-radius: 999px; cursor: pointer; }
.chip:hover, .chip:focus-visible { background: var(--rust); color: var(--paper); outline: none; }

/* ---------- game ---------- */
.topbar {
  display: flex; align-items: center; gap: 2rem; justify-content: space-between; flex-wrap: wrap;
  padding: 1rem 2.5rem; border-bottom: 2px solid var(--ink); position: sticky; top: 0; z-index: 20;
  background: rgba(236, 222, 186, 0.85); backdrop-filter: blur(14px);
}
.brand { font-family: var(--display); font-size: 1.6rem; }
.ledger { display: flex; gap: 2.25rem; flex-wrap: wrap; }
.ledger-item span { display: block; font-family: var(--mono); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.2em; color: var(--ink-soft); }
.ledger-item strong { font-family: var(--display); font-size: 1.3rem; font-weight: 400; }
.ledger-item.gold strong { color: var(--gold); }
.ledger-item.gold strong::after { content: " \2742"; font-size: 0.8em; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.sync { font-family: var(--mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.15em; color: var(--ok); }
.sync::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; margin-right: 6px; vertical-align: middle; }
.sync[data-state="saving"] { color: var(--gold); }
.sync[data-state="saving"]::before { animation: pulse 0.8s infinite; }
.sync[data-state="offline"], .sync[data-state="error"] { color: var(--rust); }
.banner { background: var(--rust); color: var(--paper); padding: 0.6rem 2.5rem; font-size: 0.9rem; }

.layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 2.5rem; padding: 2.5rem; align-items: start; }
.chart-wrap { padding: 1.5rem; position: sticky; top: 6.5rem; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.hint { margin: 0; font-size: 0.8rem; color: var(--ink-soft); font-style: italic; }
.chart { width: 100%; height: auto; display: block; background: rgba(159, 185, 173, 0.18); border: 1px solid var(--ink-soft); }
.chart .land { fill: #d8c18b; stroke: var(--ink-soft); stroke-width: 0.25; }
.chart .grid line { stroke: rgba(44, 90, 94, 0.18); stroke-width: 0.15; }
.chart .route { fill: none; stroke-width: 0.45; stroke-dasharray: 1.2 0.8; transition: stroke-width 0.2s ease; }
.chart .route:hover { stroke-width: 0.8; }
.chart .port { cursor: pointer; }
.chart .port circle { fill: var(--paper); stroke: var(--ink); stroke-width: 0.4; transition: r 0.2s ease, fill 0.2s ease; }
.chart .port:hover circle, .chart .port.selected circle { fill: var(--rust); }
.chart .port text { font-family: var(--display); font-size: 2.6px; fill: var(--ink); paint-order: stroke; stroke: var(--paper); stroke-width: 0.6px; }
.chart .port .count { font-family: var(--mono); font-size: 1.8px; fill: var(--sea); }
.chart .ship-marker { fill: var(--rust); stroke: var(--ink); stroke-width: 0.2; transition: transform 1s linear; }
.chart .compass { stroke: var(--ink-soft); fill: none; stroke-width: 0.2; }
.chart .compass text { font-size: 2px; fill: var(--ink-soft); stroke: none; font-family: var(--display); }
.chart .cartouche { font-family: var(--display); font-style: italic; font-size: 3px; fill: var(--ink-soft); }

.panel { padding: 1.5rem 1.75rem 2rem; min-height: 60vh; }
.panel-body { animation: fade 0.3s ease both; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 1rem; gap: 1rem; }
.section-title h3 { font-size: 1.05rem; }
.section-title + .section-title { margin-top: 2rem; }
.muted { color: var(--ink-soft); font-size: 0.9rem; }
.empty { color: var(--ink-soft); font-style: italic; padding: 1rem 0; }

.list { display: grid; gap: 1rem; margin-bottom: 2rem; }
.ship {
  border: 1px solid var(--ink-soft); background: rgba(255, 250, 236, 0.45); padding: 1rem 1.1rem;
  animation: rise 0.4s ease both; transition: background-color 0.2s ease, transform 0.2s ease;
}
.ship:hover { background: rgba(255, 250, 236, 0.8); }
.ship-head { display: flex; justify-content: space-between; gap: 0.75rem; align-items: baseline; flex-wrap: wrap; }
.ship-name { font-family: var(--display); font-size: 1.15rem; }
.tag { font-family: var(--mono); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.15em; padding: 0.15rem 0.45rem; border: 1px solid currentColor; }
.tag.escort { color: var(--sea); }
.tag.cargo { color: var(--gold); }
.tag.warn { color: var(--rust); }
.ship-meta { display: flex; gap: 1.25rem; flex-wrap: wrap; font-size: 0.82rem; color: var(--ink-soft); margin: 0.5rem 0 0.75rem; font-family: var(--mono); }
.bar { height: 6px; background: rgba(51, 36, 26, 0.12); border: 1px solid rgba(51, 36, 26, 0.3); position: relative; overflow: hidden; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--ok); transition: width 0.6s ease; }
.bar.low > i { background: var(--rust); }
.bar.mid > i { background: var(--gold); }
.bar.sea > i { background: var(--sea); transition: width 1s linear; }
.bar-label { display: flex; justify-content: space-between; font-size: 0.75rem; font-family: var(--mono); color: var(--ink-soft); margin-bottom: 0.25rem; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.9rem; }

.voyage { border-left: 3px solid var(--sea); padding: 0.85rem 1rem; background: rgba(159, 185, 173, 0.16); animation: rise 0.4s ease both; }
.voyage.done { border-left-color: var(--gold); background: rgba(168, 122, 31, 0.1); }
.voyage .route-line { font-family: var(--display); font-size: 1.05rem; }
.voyage .countdown { font-family: var(--mono); font-size: 0.85rem; }
.outcome { margin: 0.6rem 0 0; padding-left: 1.1rem; font-size: 0.88rem; }
.outcome li { margin: 0.15rem 0; }
.payout { font-family: var(--display); font-size: 1.2rem; color: var(--gold); }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { text-align: left; font-family: var(--mono); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.15em; color: var(--ink-soft); font-weight: 400; padding: 0.4rem; border-bottom: 1px solid var(--ink-soft); }
td { padding: 0.55rem 0.4rem; border-bottom: 1px dashed rgba(106, 82, 54, 0.35); vertical-align: middle; }
td input { width: 4.5rem; margin: 0; padding: 0.3rem 0.4rem; }
.price { font-family: var(--mono); }
.cheap { color: var(--ok); }
.dear { color: var(--rust); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.25rem; }

.yard { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.yard-card { border: 1px solid var(--ink-soft); padding: 1rem; background: rgba(255, 250, 236, 0.45); display: flex; flex-direction: column; gap: 0.5rem; transition: transform 0.2s ease, background-color 0.2s ease; }
.yard-card:hover { transform: translateY(-2px); background: rgba(255, 250, 236, 0.85); }
.yard-card p { margin: 0; font-size: 0.85rem; color: var(--ink-soft); }
.yard-card .cost { font-family: var(--display); font-size: 1.2rem; color: var(--gold); }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.2rem 0.75rem; font-family: var(--mono); font-size: 0.75rem; }

.log-entry { border-bottom: 1px dashed rgba(106, 82, 54, 0.4); padding: 0.8rem 0; }
.log-entry header { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.stats-row { display: flex; gap: 2rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.stats-row div span { display: block; font-family: var(--mono); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.2em; color: var(--ink-soft); }
.stats-row div strong { font-family: var(--display); font-weight: 400; font-size: 1.4rem; }

/* ---------- dialog ---------- */
.dialog {
  border: 1px solid var(--ink); padding: 0; max-width: 560px; width: calc(100% - 2rem); color: var(--ink);
  background: linear-gradient(180deg, #f6ebcf, #e9d6a9); box-shadow: 8px 8px 0 rgba(51, 36, 26, 0.6);
}
.dialog::backdrop { background: rgba(35, 25, 16, 0.45); backdrop-filter: blur(3px); }
.dialog[open] { animation: rise 0.25s ease both; }
.dialog-inner { padding: 1.75rem; display: grid; gap: 1rem; }
.dialog h3 { font-size: 1.4rem; }
.choice { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0.75rem; border: 1px solid var(--ink-soft); cursor: pointer; transition: background-color 0.15s ease; font-size: 0.9rem; }
.choice:hover { background: rgba(255, 251, 238, 0.7); }
.choice input { width: auto; margin: 0; accent-color: var(--rust); }
.choice .grow { flex: 1; }
.choice-list { display: grid; gap: 0.5rem; max-height: 220px; overflow: auto; }
.estimate { font-family: var(--mono); font-size: 0.85rem; padding: 0.75rem; border: 1px dashed var(--ink-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.75rem; }

/* ---------- misc ---------- */
.toasts { position: fixed; right: 1.5rem; bottom: 1.5rem; display: grid; gap: 0.5rem; z-index: 200; max-width: 380px; }
.toast { background: var(--ink); color: var(--paper); padding: 0.75rem 1rem; font-size: 0.9rem; box-shadow: 4px 4px 0 var(--rust); animation: slide 0.25s ease both; }
.toast.error { background: var(--rust-dark); box-shadow: 4px 4px 0 var(--ink); }
.boot { position: fixed; inset: 0; display: grid; place-content: center; gap: 1rem; text-align: center; font-family: var(--display); font-size: 1.2rem; z-index: 50; }
.wheel { width: 46px; height: 46px; margin: 0 auto; border: 3px dashed var(--rust); border-radius: 50%; animation: spin 2.4s linear infinite; }
.lost { display: grid; place-content: center; min-height: 100vh; text-align: center; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.2; } }

@media (max-width: 1000px) {
  .auth-screen { grid-template-columns: 1fr; gap: 2rem; padding: 2rem 1.25rem; }
  .layout { grid-template-columns: 1fr; padding: 1.25rem; gap: 1.5rem; }
  .chart-wrap { position: static; }
  .topbar { padding: 0.75rem 1.25rem; gap: 0.75rem; }
  .ledger { gap: 1.25rem; }
  .panel { padding: 1.25rem 1rem; }
  .field-row { grid-template-columns: 1fr; }
  .banner { padding: 0.6rem 1.25rem; }
}
@media (max-width: 520px) {
  .ledger-item strong { font-size: 1.05rem; }
  .brand { font-size: 1.3rem; }
  table { font-size: 0.8rem; }
  td input { width: 3.5rem; }
  .hide-sm { display: none; }
}
