/* Catppuccin Latte (light) and Frappe (dark). */

:root[data-theme="latte"] {
  --base: #eff1f5;
  --mantle: #e6e9ef;
  --surface0: #ccd0da;
  --surface1: #bcc0cc;
  --overlay0: #9ca0b0;
  --text: #4c4f69;
  --subtext: #6c6f85;
  --blue: #1e66f5;
  --sapphire: #209fb5;
  --teal: #179299;
  --green: #40a02b;
  --yellow: #df8e1d;
  --peach: #fe640b;
  --red: #d20f39;
  --mauve: #8839ef;
  --sea-deep: #7aa7c7;
  --sea-shallow: #9ec7dd;
}

:root[data-theme="frappe"] {
  --base: #303446;
  --mantle: #292c3c;
  --surface0: #414559;
  --surface1: #51576d;
  --overlay0: #737994;
  --text: #c6d0f5;
  --subtext: #b5bfe2;
  --blue: #8caaee;
  --sapphire: #85c1dc;
  --teal: #81c8be;
  --green: #a6d189;
  --yellow: #e5c890;
  --peach: #ef9f76;
  --red: #e78284;
  --mauve: #ca9ee6;
  --sea-deep: #1e2436;
  --sea-shallow: #2b3448;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--base);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--mantle);
  border-bottom: 1px solid var(--surface0);
}

.brand { font-weight: 600; letter-spacing: 0.02em; }
.brand i { color: var(--peach); margin-right: 0.4rem; }

.theme-toggle {
  background: var(--surface0);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 0.9rem;
}
.theme-toggle:hover { background: var(--surface1); }

main { flex: 1; padding: 1rem; }

.sea-wrap {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
}

canvas#sea {
  border: 1px solid var(--surface1);
  border-radius: 8px;
  max-width: 100%;
  display: block;
  background: var(--sea-deep);
}

.legend {
  width: 20rem;
  background: var(--mantle);
  border: 1px solid var(--surface0);
  border-radius: 8px;
  padding: 0.9rem 1rem;
}

.legend h2 { margin: 0 0 0.6rem; font-size: 1rem; }
.legend table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.legend td { padding: 0.22rem 0; vertical-align: top; }
.legend td:first-child { width: 7.5rem; white-space: nowrap; }

kbd {
  background: var(--surface0);
  border: 1px solid var(--surface1);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  font-family: inherit;
  font-size: 0.8rem;
}

.hint {
  margin: 0.9rem 0 0;
  font-size: 0.84rem;
  color: var(--subtext);
  line-height: 1.45;
  border-left: 3px solid var(--peach);
  padding-left: 0.7rem;
}

.footer {
  display: flex;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--mantle);
  border-top: 1px solid var(--surface0);
  font-size: 0.82rem;
  color: var(--subtext);
}
.footer a { color: var(--blue); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

.setup { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1.1rem; }

.setup label {
  font-size: 0.8rem;
  color: var(--subtext);
  margin-top: 0.3rem;
}

.setup select,
.setup button {
  background: var(--surface0);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  font: inherit;
  font-size: 0.88rem;
}

.setup select:hover { background: var(--surface1); }

.setup input[type="range"] { accent-color: var(--peach); width: 100%; }

.setup button {
  margin-top: 0.7rem;
  cursor: pointer;
  background: var(--peach);
  color: var(--mantle);
  border-color: var(--peach);
  font-weight: 600;
}
.setup button:hover { filter: brightness(1.08); }

.stats {
  margin: 0.6rem 0 0;
  font-size: 0.8rem;
  color: var(--subtext);
  line-height: 1.5;
}

/* --- navigation and status ------------------------------------------- */
.nav { display: flex; gap: 0.15rem; flex-wrap: wrap; }

.nav a {
  color: var(--subtext);
  text-decoration: none;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  font-size: 0.88rem;
}
.nav a:hover { background: var(--surface0); color: var(--text); }
.nav a.on { background: var(--surface0); color: var(--peach); }
.nav a i { margin-right: 0.3rem; opacity: 0.8; }

.statusbar {
  display: flex;
  gap: 1.4rem;
  flex-wrap: wrap;
  padding: 0.5rem 1rem;
  background: var(--surface0);
  border-bottom: 1px solid var(--surface1);
  font-size: 0.85rem;
}
.statusbar i { color: var(--peach); margin-right: 0.35rem; }
.statusbar small { color: var(--subtext); }

/* --- flashes ---------------------------------------------------------- */
.flashes { padding: 0.6rem 1rem 0; }
.flash {
  margin: 0 0 0.4rem;
  padding: 0.55rem 0.8rem;
  border-radius: 6px;
  font-size: 0.88rem;
  border-left: 3px solid;
}
.flash.ok { background: var(--mantle); border-color: var(--green); }
.flash.warn { background: var(--mantle); border-color: var(--yellow); }
.flash i { margin-right: 0.4rem; }
.flash.ok i { color: var(--green); }
.flash.warn i { color: var(--yellow); }

/* --- layout ----------------------------------------------------------- */
.columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(21rem, 1fr));
  gap: 1rem;
  align-items: start;
}

.panel {
  background: var(--mantle);
  border: 1px solid var(--surface0);
  border-radius: 8px;
  padding: 1rem 1.1rem;
}
.panel.wide { grid-column: 1 / -1; margin-bottom: 1rem; }

h1 { font-size: 1.25rem; margin: 0 0 0.5rem; }
h2 { font-size: 1rem; margin: 1.1rem 0 0.5rem; }
h3 { font-size: 0.92rem; margin: 0 0 0.3rem; }

.lead { font-size: 0.9rem; color: var(--subtext); margin: 0 0 0.8rem; line-height: 1.5; }
.tiny { font-size: 0.78rem; color: var(--subtext); margin: 0.15rem 0; line-height: 1.4; }
.muted { color: var(--overlay0); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }
.dim { opacity: 0.45; }

.warning, .warning-text { color: var(--yellow); }
.warning { font-size: 0.85rem; }
.cheap { color: var(--green); }
.dear { color: var(--peach); }

/* --- buttons and inputs ----------------------------------------------- */
button.small, .setup button {
  background: var(--surface0);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: 5px;
  padding: 0.22rem 0.55rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
button.small:hover:not(:disabled) { background: var(--surface1); }
button.small:disabled { opacity: 0.35; cursor: default; }
button.small.danger:hover { background: var(--red); color: var(--mantle); border-color: var(--red); }

input.qty {
  width: 4.5rem;
  background: var(--surface0);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: 5px;
  padding: 0.2rem 0.35rem;
  font: inherit;
  font-size: 0.8rem;
}

select {
  background: var(--surface0);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: 5px;
  padding: 0.2rem 0.35rem;
  font: inherit;
  font-size: 0.8rem;
}

/* --- plots ------------------------------------------------------------ */
.plots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.plot {
  border: 1px solid var(--surface0);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  min-height: 5.5rem;
}
.plot.filled { background: var(--surface0); border-color: var(--surface1); }
.plot.empty { border-style: dashed; }

/* --- tables ----------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th { text-align: left; font-weight: 600; color: var(--subtext); font-size: 0.78rem; }
th.right { text-align: right; }
.build-table td, .stock-table td, .market-table td, .market-table th, .skill-table td {
  padding: 0.3rem 0.35rem;
  border-bottom: 1px solid var(--surface0);
  vertical-align: middle;
}
.market-table tbody tr:hover { background: var(--surface0); }

/* --- map -------------------------------------------------------------- */
.region { margin-bottom: 1.2rem; }
.region h2 { margin-bottom: 0.4rem; }

.ports {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.45rem;
}
.port {
  background: var(--surface0);
  border: 1px solid var(--surface1);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.port.here { border-color: var(--peach); }
.port.home { border-color: var(--teal); }

.tag {
  display: inline-block;
  font-size: 0.7rem;
  background: var(--peach);
  color: var(--mantle);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  align-self: flex-start;
}
.tag.warn { background: var(--yellow); }

/* --- fleet and skills ------------------------------------------------- */
.fleet-ship {
  border: 1px solid var(--surface0);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.5rem;
}
.fleet-ship.active { border-color: var(--peach); background: var(--surface0); }

.repair {
  border-left: 3px solid var(--yellow);
  padding-left: 0.7rem;
  margin-top: 0.8rem;
}

.trees {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 0.9rem;
}
.tree {
  background: var(--surface0);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
}
.tree h2 { margin-top: 0; display: flex; justify-content: space-between; align-items: baseline; }
.points { font-size: 0.78rem; color: var(--peach); font-weight: 600; }

.log { list-style: none; margin: 0; padding: 0; font-size: 0.83rem; }
.log li { padding: 0.2rem 0; border-bottom: 1px solid var(--surface0); }
.log .muted { margin-right: 0.5rem; }

/* --- the chart -------------------------------------------------------- */
.chart-scroll { overflow-x: auto; padding-bottom: 0.4rem; }

.chart {
  display: grid;
  grid-template-columns: repeat(9, minmax(7.6rem, 1fr));
  gap: 3px;
  min-width: 70rem;
}

.cell {
  border-radius: 5px;
  padding: 0.4rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-height: 5.2rem;
  border: 2px solid transparent;
}
.cell-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.3rem; }
.cell strong { font-size: 0.8rem; line-height: 1.2; }
.cell.here { border-color: var(--peach); }
.cell.home { border-color: var(--teal); }
.cell form { margin-top: auto; }
.cell i { font-size: 0.7rem; opacity: 0.7; }

/* Region tints, kept faint so the text stays readable in both themes. */
.region-groene_snoer   { background: color-mix(in srgb, var(--green) 18%, var(--mantle)); }
.region-peperkust      { background: color-mix(in srgb, var(--peach) 18%, var(--mantle)); }
.region-ijzeren_baaien { background: color-mix(in srgb, var(--sapphire) 18%, var(--mantle)); }
.region-suikerbanken   { background: color-mix(in srgb, var(--yellow) 18%, var(--mantle)); }
.region-zoutlanden     { background: color-mix(in srgb, var(--mauve) 18%, var(--mantle)); }
.region-buitenwater    { background: color-mix(in srgb, var(--red) 20%, var(--mantle)); }

.legend-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.8rem; }
.swatch {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  border: 1px solid var(--surface1);
}

/* --- tide and world events -------------------------------------------- */
.tide { margin-bottom: 1rem; }
.tide-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.85rem; }
.tide-head i { color: var(--sapphire); margin-right: 0.35rem; }

.tide-bar {
  height: 6px;
  background: var(--surface0);
  border-radius: 3px;
  overflow: hidden;
  margin: 0.3rem 0;
}
.tide-bar div { height: 100%; background: var(--sapphire); }

.event-here {
  border: 1px solid var(--red);
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
  background: color-mix(in srgb, var(--red) 10%, var(--mantle));
}
.event-here h2 { margin: 0 0 0.3rem; }
.event-here h2 i { color: var(--red); margin-right: 0.4rem; }

i.beast { color: var(--red); opacity: 1; }

.guns {
  border-left: 3px solid var(--sapphire);
  padding-left: 0.7rem;
  margin-top: 0.9rem;
}
.guns h2 { margin-top: 0; }

.contract {
  border: 1px solid var(--surface0);
  border-radius: 6px;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.5rem;
}
.contract.done { border-color: var(--green); background: color-mix(in srgb, var(--green) 8%, var(--mantle)); }
.contract h3 { margin: 0 0 0.2rem; }
.contract-actions { display: flex; gap: 0.35rem; margin-top: 0.35rem; }

.milestone { margin-bottom: 0.7rem; }
.milestone-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.87rem;
  margin-bottom: 0.2rem;
}
.milestone-head i { color: var(--green); margin-right: 0.35rem; }
.milestone-bar { height: 5px; background: var(--surface0); border-radius: 3px; overflow: hidden; }
.milestone-bar div { height: 100%; background: var(--peach); }
.milestone.complete .milestone-bar div { background: var(--green); }

/* --- login gate ------------------------------------------------------- */
.gate { max-width: 26rem; margin: 3rem auto; }
.gate .setup input[type="text"],
.gate .setup input[type="password"] {
  background: var(--surface0);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font: inherit;
}
.gate a { color: var(--blue); }

.linkbutton {
  display: inline-block;
  margin-top: 0.6rem;
  background: var(--peach);
  color: var(--mantle);
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}

.topbar-right { display: flex; align-items: center; gap: 0.4rem; }
.whoami { font-size: 0.82rem; color: var(--subtext); }
.navlink {
  color: var(--subtext);
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  text-decoration: none;
}
.navlink:hover { background: var(--surface0); color: var(--text); }
.navlink.on { background: var(--surface0); color: var(--peach); }

.admin-world { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; margin: 0.6rem 0 0.3rem; }
.danger-zone { display: flex; gap: 0.35rem; align-items: center; }
input.wide-input { width: 9rem; }

/* --- the island ------------------------------------------------------- */
.island {
  position: relative;
  width: 100%;
  max-width: 46rem;
  margin: 0 auto 1rem;
  aspect-ratio: 1 / 1;
}

.island-art {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 10px;
  /* Keep the pixels crisp instead of letting the browser smear them. */
  image-rendering: pixelated;
}

.iso-sprite {
  position: absolute;
  width: 15%;
  transform: translate(-50%, -78%);
  image-rendering: pixelated;
  pointer-events: none;
}

.iso-plot {
  position: absolute;
  width: 15%;
  transform: translate(-50%, -78%);
}

.iso-plot > summary {
  display: block;
  list-style: none;
  cursor: pointer;
  line-height: 0;
}
.iso-plot > summary::-webkit-details-marker { display: none; }

.iso-plot .iso-sprite {
  position: static;
  width: 100%;
  transform: none;
  pointer-events: auto;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
  transition: transform 0.12s ease;
}
.iso-plot > summary:hover .iso-sprite { transform: translateY(-3px); }

/* Empty plot: a flat isometric diamond you can drop a building on. */
.diamond {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 1;
  background: rgba(255, 255, 255, 0.14);
  border: 2px dashed rgba(255, 255, 255, 0.55);
  transform: perspective(60px) rotateX(28deg);
  border-radius: 3px;
  position: relative;
  transition: background 0.12s ease;
}
.iso-plot > summary:hover .diamond { background: rgba(255, 255, 255, 0.3); }

.diamond i {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.8rem;
  line-height: 1;
}

.locked-diamond {
  background: rgba(0, 0, 0, 0.22);
  border-style: dotted;
  border-color: rgba(255, 255, 255, 0.25);
}
.iso-plot.locked { pointer-events: none; }

/* Popover attached to a plot. Pure HTML details, no script. */
.plot-popover {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  width: 15rem;
  background: var(--mantle);
  border: 1px solid var(--surface1);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  z-index: 500;
}
.plot-popover h4 { margin: 0 0 0.25rem; font-size: 0.9rem; }
.plot-popover select { width: 100%; margin-bottom: 0.4rem; }
.iso-plot[open] { z-index: 600 !important; }

.ref-icon { width: 3rem; padding-right: 0.4rem !important; }
.ref-icon img { image-rendering: pixelated; display: block; }

.uniques {
  border-left: 3px solid var(--mauve);
  padding-left: 0.7rem;
  margin-top: 0.9rem;
}
.uniques h2 { margin-top: 0; }
.uniques h3 { margin: 0.6rem 0 0.3rem; font-size: 0.82rem; color: var(--subtext); }
.unique-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--surface0);
}

/* --- treasure charts --------------------------------------------------- */
.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0.7rem;
}
.chart-card {
  background: var(--surface0);
  border: 1px solid var(--surface1);
  border-radius: 7px;
  padding: 0.6rem 0.75rem;
}
.chart-card.complete { border-color: var(--yellow); }
.chart-card.spent { opacity: 0.55; }
.chart-card h3 { margin: 0 0 0.25rem; }

.pieces { display: flex; gap: 3px; margin: 0.45rem 0 0.25rem; }
.piece {
  flex: 1;
  height: 9px;
  border-radius: 2px;
  background: var(--surface1);
  border: 1px solid var(--overlay0);
}
.piece.have { background: var(--yellow); border-color: var(--yellow); }

/* --- fleet artwork ----------------------------------------------------- */
.fleet-ship { display: flex; gap: 0.6rem; align-items: flex-start; }
.fleet-body { flex: 1; min-width: 0; }
.ship-art {
  width: 3.6rem;
  height: 3.6rem;
  flex: none;
  image-rendering: pixelated;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
}

a.whoami { text-decoration: none; }
a.whoami:hover { color: var(--text); text-decoration: underline; }
