:root {
  color-scheme: dark;
  --ink: #e7dbc2;
  --muted: #a79d86;
  --panel: rgba(31, 29, 24, 0.96);
  --panel-strong: #1f1d18;
  --line: rgba(202, 181, 133, 0.24);
  --gold: #b99046;
  --reef: #6f7d58;
  --danger: #8f4d3f;
  --sky: #6f8582;
  --leaf: #7a844e;
  --ad-offset: 0px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #11130f;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button {
  border: 0;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 241, 188, 0.2), rgba(69, 48, 25, 0.18)),
    linear-gradient(#c2aa70, #9f844e);
  color: #1c1912;
  border: 1px solid rgba(54, 43, 26, 0.45);
  font: inherit;
  font-weight: 800;
  min-height: 44px;
  padding: 0 14px;
  box-shadow:
    inset 0 1px 0 rgba(255, 239, 186, 0.24),
    inset 0 -2px 0 rgba(58, 42, 24, 0.22),
    0 8px 18px rgba(0, 0, 0, 0.18);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.42;
}

svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#app {
  min-height: 100%;
  position: relative;
  isolation: isolate;
  touch-action: none;
}

#sea {
  width: 100vw;
  height: 100vh;
  display: block;
  background: #172321;
}

.ad-banner {
  position: fixed;
  z-index: 7;
  top: max(6px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  height: 48px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(173, 145, 88, 0.12), transparent 34%, rgba(88, 72, 43, 0.18)),
    repeating-linear-gradient(0deg, rgba(228, 209, 158, 0.04) 0 1px, transparent 1px 9px),
    rgba(23, 35, 38, 0.94);
  color: var(--muted);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(16px);
}

.ad-banner span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.ad-banner button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.76rem;
}

.hud {
  position: fixed;
  z-index: 4;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(220, 198, 143, 0.08), rgba(0, 0, 0, 0.16)),
    repeating-linear-gradient(90deg, rgba(224, 204, 157, 0.035) 0 2px, transparent 2px 12px),
    rgba(28, 27, 23, 0.86);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.26),
    0 12px 36px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px);
}

.hud-top {
  z-index: 8;
  top: calc(max(10px, env(safe-area-inset-top)) + var(--ad-offset));
  left: 10px;
  right: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  overflow: hidden;
  border-radius: 8px;
}

.hud-top div {
  min-width: 0;
  padding: 9px 8px;
  background:
    linear-gradient(135deg, rgba(169, 146, 91, 0.12), rgba(16, 16, 13, 0.22)),
    rgba(116, 98, 65, 0.12);
}

.hud strong {
  display: block;
  color: var(--ink);
  font-size: clamp(0.95rem, 2.8vw, 1.1rem);
  line-height: 1.1;
}

.hud span,
.hud-top span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.target-card {
  top: calc(max(76px, calc(env(safe-area-inset-top) + 68px)) + var(--ad-offset));
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 8px;
  padding: 10px 10px 10px 12px;
}

.sail-controls {
  position: fixed;
  z-index: 4;
  left: 12px;
  right: 12px;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 10px;
  align-items: end;
  pointer-events: auto;
}

.joystick {
  width: 132px;
  height: 132px;
  display: grid;
  place-items: center;
  touch-action: none;
}

.joystick-ring {
  width: 112px;
  height: 112px;
  position: relative;
  border: 1px solid rgba(238, 229, 207, 0.22);
  border-radius: 999px;
  background:
    radial-gradient(circle at 50% 50%, rgba(222, 199, 150, 0.15) 0 24%, transparent 25%),
    conic-gradient(from 0deg, rgba(196, 169, 101, 0.14), transparent 18%, rgba(196, 169, 101, 0.11) 25%, transparent 45%, rgba(196, 169, 101, 0.14)),
    rgba(29, 28, 23, 0.82);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
}

.joystick-ring::before,
.joystick-ring::after {
  content: "";
  position: absolute;
  background: rgba(238, 229, 207, 0.14);
}

.joystick-ring::before {
  left: 16px;
  right: 16px;
  top: 50%;
  height: 1px;
}

.joystick-ring::after {
  top: 16px;
  bottom: 16px;
  left: 50%;
  width: 1px;
}

.joystick-knob {
  width: 46px;
  height: 46px;
  position: absolute;
  left: 33px;
  top: 33px;
  border: 1px solid rgba(238, 229, 207, 0.3);
  border-radius: 999px;
  background:
    radial-gradient(circle at 38% 32%, #dfcb8d 0 22%, transparent 23%),
    radial-gradient(circle at 48% 54%, #b39558, #755b33);
  box-shadow:
    inset 0 -3px 0 rgba(62, 43, 24, 0.26),
    0 8px 18px rgba(0, 0, 0, 0.38);
}

.sail-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-content: end;
}

.sail-actions button,
.sail-controls > button {
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.26);
}

#dockBtn {
  grid-column: 1 / -1;
  background: var(--leaf);
  color: #111810;
}

#attackBtn {
  grid-column: 1 / -1;
  background: linear-gradient(#9e5c4d, #6e372f);
  color: #f4ead4;
}

.sail-controls #trimSails {
  grid-column: 1 / -1;
  background: rgba(238, 229, 207, 0.9);
}

.wind-pill {
  grid-column: 1 / -1;
  justify-self: center;
  min-width: 138px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(111, 133, 130, 0.16), transparent 55%),
    repeating-linear-gradient(0deg, rgba(231, 219, 194, 0.035) 0 1px, transparent 1px 8px),
    rgba(31, 29, 24, 0.84);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  backdrop-filter: blur(14px);
}

.chart-map {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: none;
  touch-action: none;
  cursor: grab;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 48%, rgba(94, 112, 78, 0.18), transparent 55%),
    #142321;
  image-rendering: pixelated;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.32),
    inset 0 0 38px rgba(0, 0, 0, 0.26);
}

.chart-map:active {
  cursor: grabbing;
}

.chart-shell {
  min-height: 0;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 8px;
}

.chart-status {
  flex: 0 0 auto;
  margin: 0;
}

.chart-legend {
  flex: 0 0 auto;
  max-height: 56px;
  overflow: hidden;
}

.icon-button {
  width: 44px;
  min-width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  background:
    linear-gradient(180deg, rgba(214, 190, 128, 0.12), rgba(34, 26, 16, 0.18)),
    rgba(111, 91, 56, 0.22);
  color: var(--ink);
  border: 1px solid var(--line);
}

.bottom-sheet {
  position: fixed;
  z-index: 5;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: none;
  padding: calc(max(10px, env(safe-area-inset-top)) + var(--ad-offset) + 64px) 12px max(10px, env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, rgba(188, 159, 99, 0.08), rgba(0, 0, 0, 0.16)),
    repeating-linear-gradient(90deg, rgba(222, 202, 154, 0.025) 0 2px, transparent 2px 11px),
    var(--panel);
  border-top: 0;
  box-shadow: 0 -20px 52px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
}

.sheet-grip {
  display: none;
}

.panel-header,
.combat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header,
.scene-canvas,
.tabs,
.port-sail-card {
  flex: 0 0 auto;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-header p,
.combat-top p {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.1;
}

.scene-canvas,
.combat-scene {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #172f31;
  image-rendering: pixelated;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.28),
    inset 0 -26px 60px rgba(0, 0, 0, 0.18);
}

.scene-canvas {
  height: clamp(190px, 30vh, 280px);
  min-height: 190px;
  margin: 12px 0 10px;
}

.combat-scene {
  height: min(38vh, 230px);
  min-height: 190px;
  margin: 12px 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.22);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  margin: 10px 0 10px;
}

.tab-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 8px;
  overscroll-behavior: contain;
}

.tab {
  min-height: 40px;
  padding: 0 6px;
  background:
    linear-gradient(180deg, rgba(231, 219, 194, 0.05), rgba(0, 0, 0, 0.12)),
    rgba(93, 78, 50, 0.22);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: clamp(0.68rem, 2.2vw, 0.9rem);
}

.tab.active {
  background:
    linear-gradient(180deg, rgba(225, 213, 162, 0.12), rgba(37, 48, 33, 0.18)),
    var(--reef);
  color: #101711;
}

.anchor-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.anchor-tabs button {
  min-height: 38px;
  background:
    linear-gradient(180deg, rgba(231, 219, 194, 0.05), rgba(0, 0, 0, 0.12)),
    rgba(93, 78, 50, 0.22);
  color: var(--ink);
  border-color: var(--line);
}

.anchor-tabs button.active {
  background:
    linear-gradient(180deg, rgba(225, 213, 162, 0.12), rgba(37, 48, 33, 0.18)),
    var(--reef);
  color: #101711;
}

.market-grid,
.jobs-list,
.yard-list,
.tavern-list,
.governor-list,
.log-list,
.captain-ledger,
.reputation-ledger,
.cargo-manifest {
  display: grid;
  gap: 8px;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(91, 78, 52, 0.16);
  box-shadow:
    inset 0 1px 0 rgba(230, 212, 166, 0.05),
    inset 0 -1px 0 rgba(0, 0, 0, 0.18);
}

.port-card {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(151, 126, 76, 0.24), rgba(30, 27, 21, 0.18)),
    repeating-linear-gradient(0deg, rgba(231, 219, 194, 0.026) 0 1px, transparent 1px 8px),
    rgba(92, 78, 52, 0.2);
  margin-bottom: 8px;
}

.port-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.chip {
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.24);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.leave-port {
  width: 100%;
  background: linear-gradient(#a99767, #7e6c45);
  color: #141812;
}

.port-sail-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(112px, 0.38fr);
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid rgba(202, 181, 133, 0.34);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(151, 126, 76, 0.24), rgba(18, 27, 24, 0.3)),
    rgba(35, 32, 24, 0.94);
  box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.24);
}

.port-sail-card strong {
  display: block;
  line-height: 1.1;
}

.port-sail-card small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.76rem;
}

.hold-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(31, 48, 45, 0.34), rgba(30, 27, 21, 0.18)),
    repeating-linear-gradient(0deg, rgba(231, 219, 194, 0.026) 0 1px, transparent 1px 8px),
    rgba(24, 31, 27, 0.62);
  margin-bottom: 8px;
}

.trade-booth-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(176, 154, 93, 0.34);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(104, 88, 48, 0.24), rgba(22, 36, 34, 0.2)),
    repeating-linear-gradient(0deg, rgba(231, 219, 194, 0.026) 0 1px, transparent 1px 8px),
    rgba(27, 30, 24, 0.64);
  margin-bottom: 8px;
}

.hold-warning {
  border-color: rgba(224, 95, 79, 0.62);
}

.hold-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.hold-head strong,
.hold-head small,
.hold-head span {
  display: block;
}

.hold-head small,
.hold-head span {
  color: var(--muted);
  font-size: 0.74rem;
}

.hold-head span {
  flex: 0 0 auto;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 800;
}

.hold-grid {
  display: grid;
  grid-auto-rows: 30px;
  grid-auto-flow: dense;
  gap: 4px;
}

.hold-cell,
.hold-stack {
  min-width: 0;
  border-radius: 5px;
}

.hold-cell {
  min-height: 30px;
  border: 1px dashed rgba(202, 181, 133, 0.16);
  background: rgba(0, 0, 0, 0.16);
}

.hold-stack {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 30px;
  padding: 5px 6px;
  overflow: hidden;
  border: 1px solid rgba(28, 21, 16, 0.72);
  background:
    linear-gradient(135deg, rgba(255, 244, 204, 0.18), rgba(0, 0, 0, 0.14)),
    var(--item-color);
  color: #17140f;
  box-shadow:
    inset 0 1px 0 rgba(255, 244, 204, 0.22),
    inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}

.hold-stack.locked {
  outline: 2px solid rgba(231, 219, 194, 0.26);
  filter: saturate(0.78);
}

.hold-stack.ammo {
  border-color: rgba(24, 20, 16, 0.86);
  box-shadow:
    inset 0 1px 0 rgba(255, 244, 204, 0.2),
    inset 0 -3px 0 rgba(0, 0, 0, 0.28);
}

.hold-stack strong,
.hold-stack span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hold-stack strong {
  font-size: 0.68rem;
  line-height: 1;
}

.hold-stack span {
  font-size: 0.58rem;
  font-weight: 900;
  opacity: 0.82;
}

.row strong {
  display: block;
  line-height: 1.1;
}

.row small,
.status-line {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.captain-ledger {
  margin-bottom: 8px;
}

.cargo-manifest {
  margin-bottom: 8px;
}

.cargo-manifest-row {
  min-height: 58px;
}

.collapse-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(28, 26, 19, 0.66);
  overflow: hidden;
}

.collapse-section summary {
  display: flex;
  align-items: center;
  min-height: 58px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.collapse-section summary::-webkit-details-marker {
  display: none;
}

.collapse-section summary::after {
  content: "▸";
  margin-left: auto;
  color: var(--gold);
  font-size: 1rem;
  line-height: 1;
}

.collapse-section[open] summary::after {
  content: "▾";
}

.collapse-section summary strong {
  display: block;
  line-height: 1.1;
}

.collapse-section summary small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.collapse-body {
  display: grid;
  gap: 8px;
  padding: 0 8px 8px;
}

.collapse-body > .hold-card,
.collapse-body > .cargo-manifest,
.collapse-body > .captain-ledger {
  margin-bottom: 0;
}

.yard-collapse > summary {
  background: rgba(12, 24, 22, 0.62);
}

.captain-goal-row {
  min-height: 74px;
}

.goal-progress {
  display: block;
  width: min(100%, 340px);
  height: 7px;
  margin-top: 8px;
  accent-color: var(--gold);
}

.market-row,
.booth-list-row {
  grid-template-columns: minmax(0, 1fr);
}

.market-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 100%;
}

.trade-action-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(42px, 1fr));
  gap: 6px;
  min-width: 0;
  padding: 6px;
  border: 1px solid rgba(188, 185, 174, 0.26);
  border-radius: 8px;
  box-shadow:
    inset 0 1px 0 rgba(238, 234, 220, 0.07),
    inset 0 -1px 0 rgba(0, 0, 0, 0.28),
    0 1px 0 rgba(0, 0, 0, 0.24);
}

.buy-group {
  background:
    linear-gradient(135deg, rgba(86, 88, 82, 0.48), rgba(30, 31, 28, 0.52)),
    rgba(26, 27, 24, 0.62);
  border-color: rgba(154, 151, 138, 0.42);
}

.sell-group {
  background:
    linear-gradient(135deg, rgba(65, 65, 59, 0.5), rgba(22, 22, 20, 0.58)),
    rgba(20, 20, 18, 0.68);
  border-color: rgba(124, 121, 111, 0.48);
}

.trade-action-group button {
  padding: 0 4px;
  white-space: nowrap;
  font-size: 0.78rem;
}

.booth-actions {
  align-items: stretch;
  grid-template-columns: minmax(70px, 0.9fr) repeat(3, minmax(42px, 1fr));
  width: 100%;
}

.booth-price {
  width: 78px;
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--paper);
  font-weight: 800;
}

.ship-row {
  grid-template-columns: 112px minmax(0, 1fr) auto;
  min-height: 96px;
  align-items: center;
}

.ship-row .ship-row-copy {
  min-width: 0;
}

.yard-section {
  min-height: auto;
  background: rgba(12, 24, 22, 0.62);
  border-color: rgba(202, 181, 133, 0.3);
}

.yard-section strong {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gold);
  font-size: 0.82rem;
}

.shipyard-offer {
  border-color: rgba(196, 171, 104, 0.44);
  background: rgba(34, 30, 20, 0.72);
}

.ship-portrait {
  width: 112px;
  height: 68px;
  object-fit: cover;
  border: 1px solid rgba(202, 181, 133, 0.26);
  border-radius: 6px;
  background: #172f31;
  image-rendering: pixelated;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.34),
    0 7px 16px rgba(0, 0, 0, 0.18);
}

.row-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(48px, auto));
  gap: 6px;
}

.row-actions button {
  min-height: 38px;
  padding: 0 8px;
  font-size: 0.82rem;
}

.fleet-controls {
  display: grid;
  gap: 6px;
}

.fleet-actions {
  grid-template-columns: repeat(3, minmax(50px, auto));
}

.mod-part-row {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(31, 29, 24, 0.58);
}

.mod-part-row > div:first-child strong {
  display: block;
}

.mod-part-row > div:first-child small,
.part-chip small {
  display: block;
  color: var(--muted);
}

.part-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 6px;
}

.color-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(116px, 1fr));
  gap: 6px;
}

.color-field {
  display: grid;
  gap: 6px;
  min-height: 56px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(231, 219, 194, 0.05), rgba(0, 0, 0, 0.12)),
    rgba(93, 78, 50, 0.22);
}

.color-field span {
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.color-field input[type="color"] {
  width: 100%;
  height: 30px;
  padding: 2px;
  border: 1px solid rgba(202, 181, 133, 0.34);
  border-radius: 6px;
  background: rgba(16, 19, 15, 0.65);
}

.part-chip {
  min-height: 50px;
  padding: 6px 8px;
  text-align: left;
  color: var(--ink);
  border-color: var(--line);
  background:
    linear-gradient(180deg, rgba(231, 219, 194, 0.05), rgba(0, 0, 0, 0.12)),
    rgba(93, 78, 50, 0.22);
}

.part-chip.active {
  background:
    linear-gradient(180deg, rgba(225, 213, 162, 0.12), rgba(37, 48, 33, 0.18)),
    var(--reef);
  color: #101711;
}

.part-chip strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.debug-settings {
  margin-top: 16px;
  opacity: 0.48;
}

.debug-settings summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.debug-settings[open] {
  opacity: 0.9;
}

.debug-settings .row {
  margin-top: 8px;
  background: rgba(53, 42, 28, 0.32);
}

.primary-row button {
  background: var(--leaf);
}

.rare-row {
  border-color: rgba(216, 173, 63, 0.42);
  background:
    linear-gradient(90deg, rgba(216, 173, 63, 0.12), rgba(64, 43, 26, 0.04)),
    var(--panel);
}

.rare-row .ship-portrait {
  border-color: rgba(240, 207, 106, 0.55);
}

.capture-replace {
  grid-template-columns: minmax(0, 1fr) minmax(180px, auto);
}

.capture-actions {
  grid-template-columns: repeat(2, minmax(92px, auto));
}

.danger-row button {
  background: var(--danger);
  color: #fff8ef;
}

.combat {
  position: fixed;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(12px + var(--ad-offset)) 12px max(12px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 50% 34%, rgba(111, 133, 130, 0.22), transparent 44%),
    repeating-linear-gradient(0deg, rgba(231, 219, 194, 0.025) 0 1px, transparent 1px 10px),
    linear-gradient(rgba(5, 10, 13, 0.38), rgba(5, 10, 13, 0.78));
}

.combat-card {
  width: min(100%, 760px);
  max-height: calc(100vh - 24px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(142, 119, 73, 0.12), rgba(0, 0, 0, 0.14)),
    repeating-linear-gradient(90deg, rgba(231, 219, 194, 0.025) 0 2px, transparent 2px 12px),
    var(--panel-strong);
  padding: 14px;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.28),
    0 20px 60px rgba(0, 0, 0, 0.48);
}

.intent {
  max-width: 142px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(224, 95, 79, 0.16);
  color: #ffd9d0;
  font-size: 0.72rem;
  font-weight: 800;
  text-align: right;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.bars {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.combat-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.combat-stats div {
  min-width: 0;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(223, 204, 157, 0.06), rgba(0, 0, 0, 0.14)),
    rgba(255, 255, 255, 0.05);
  text-align: center;
}

.combat-stats strong {
  display: block;
  font-size: 0.9rem;
  line-height: 1.05;
}

.combat-stats span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

progress {
  width: 100%;
  height: 12px;
  overflow: hidden;
  border: 0;
  border-radius: 99px;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.28), rgba(255, 255, 255, 0.08)),
    rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.2);
}

progress::-webkit-progress-bar {
  background: rgba(255, 255, 255, 0.1);
}

progress::-webkit-progress-value {
  background: var(--danger);
}

.combat-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.combat-actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background:
    linear-gradient(180deg, rgba(229, 215, 172, 0.12), rgba(50, 32, 19, 0.2)),
    linear-gradient(#a88a52, #765937);
  color: #f0e2c3;
  border-color: rgba(218, 190, 128, 0.28);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.42);
}

dialog {
  width: min(92vw, 520px);
  max-height: 78vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(117, 101, 63, 0.16), rgba(0, 0, 0, 0.18)),
    repeating-linear-gradient(90deg, rgba(231, 219, 194, 0.025) 0 2px, transparent 2px 12px),
    #172326;
  color: var(--ink);
  padding: 18px;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.32),
    0 24px 64px rgba(0, 0, 0, 0.54);
}

dialog.chart-modal {
  width: min(96vw, 980px);
  max-width: min(96vw, 980px);
  height: min(92dvh, 920px);
  max-height: min(92dvh, 920px);
  padding: 12px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.52);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
}

#modalBody {
  margin-top: 16px;
}

dialog.chart-modal #modalBody {
  height: calc(100% - 42px);
  min-height: 0;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
}

.welcome-screen,
.help-screen {
  display: grid;
  gap: 12px;
}

.welcome-hero {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(64, 93, 69, 0.28), rgba(30, 27, 21, 0.18)),
    rgba(26, 37, 34, 0.72);
}

.welcome-hero strong {
  display: block;
  margin-bottom: 5px;
  font-size: 1.15rem;
}

.welcome-hero small,
.help-row small {
  line-height: 1.42;
}

.help-list {
  display: grid;
  gap: 8px;
}

.modal-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.empty {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

dialog.gambling-modal {
  width: min(96vw, 820px);
  max-width: min(96vw, 820px);
  max-height: min(92dvh, 760px);
}

.gambling-screen {
  display: grid;
  gap: 10px;
}

.gambling-scene {
  position: relative;
  overflow: hidden;
  min-height: 240px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 240, 184, 0.035) 0 2px, transparent 2px 18px),
    linear-gradient(180deg, rgba(69, 86, 89, 0.38), rgba(33, 30, 22, 0.3)),
    rgba(28, 37, 31, 0.92);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.38),
    inset 0 -42px 70px rgba(0, 0, 0, 0.24);
}

.bones-table {
  display: grid;
  grid-template-rows: 56px minmax(92px, 1fr);
  align-items: center;
  justify-items: center;
  background:
    radial-gradient(circle at 22% 72%, rgba(67, 29, 20, 0.28) 0 8px, transparent 9px),
    radial-gradient(circle at 76% 64%, rgba(176, 139, 63, 0.18) 0 11px, transparent 12px),
    linear-gradient(180deg, #42525a 0 34%, #315142 35% 100%);
}

.bones-score {
  z-index: 1;
  align-self: start;
  justify-self: start;
  display: grid;
  gap: 2px;
  min-width: 138px;
  margin: 12px;
  padding: 8px 10px;
  border: 1px solid rgba(231, 219, 194, 0.18);
  border-radius: 6px;
  background: rgba(18, 22, 20, 0.64);
}

.bones-score small,
.gambling-ledger small {
  display: block;
  color: var(--muted);
}

.bones-dice {
  z-index: 1;
  display: flex;
  gap: 12px;
  transform: rotate(-2deg);
}

.tavern-die {
  position: relative;
  width: 62px;
  height: 62px;
  border: 2px solid #19160f;
  border-radius: 7px 5px 8px 4px;
  background:
    radial-gradient(circle at 72% 18%, rgba(255, 255, 255, 0.34), transparent 14px),
    radial-gradient(circle at 28% 72%, rgba(86, 45, 29, 0.14), transparent 18px),
    linear-gradient(135deg, #d9c89d, #ae9360);
  box-shadow:
    0 0 0 2px rgba(238, 221, 173, 0.58),
    0 9px 0 rgba(48, 34, 19, 0.55),
    0 13px 16px rgba(0, 0, 0, 0.34),
    inset 0 -7px 11px rgba(52, 30, 14, 0.24);
}

.tavern-die::before {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #15130f;
  box-shadow: var(--pip-shadow);
}

.tavern-die::after {
  content: "";
  position: absolute;
  left: 12px;
  top: 14px;
  width: 34px;
  height: 26px;
  border-top: 2px solid rgba(106, 42, 26, 0.28);
  border-left: 1px solid rgba(106, 42, 26, 0.18);
  transform: skew(-9deg) rotate(5deg);
}

.die-1 { --pip-shadow: none; }
.die-1::before { left: 27px; top: 25px; }
.die-2 { --pip-shadow: 34px 34px 0 #15130f; }
.die-2::before { left: 12px; top: 12px; }
.die-3 { --pip-shadow: 17px 17px 0 #15130f, 34px 34px 0 #15130f; }
.die-3::before { left: 12px; top: 12px; }
.die-4 { --pip-shadow: 34px 0 0 #15130f, 0 34px 0 #15130f, 34px 34px 0 #15130f; }
.die-4::before { left: 12px; top: 12px; }
.die-5 { --pip-shadow: 34px 0 0 #15130f, 17px 17px 0 #15130f, 0 34px 0 #15130f, 34px 34px 0 #15130f; }
.die-5::before { left: 12px; top: 12px; }
.die-6 { --pip-shadow: 0 17px 0 #15130f, 0 34px 0 #15130f, 34px 0 0 #15130f, 34px 17px 0 #15130f, 34px 34px 0 #15130f; }
.die-6::before { left: 12px; top: 12px; }

.bones-card {
  position: absolute;
  right: 10px;
  top: 48px;
  display: grid;
  place-items: center;
  width: 86px;
  height: 112px;
  padding: 8px;
  border: 2px solid rgba(41, 27, 15, 0.72);
  border-radius: 5px;
  background:
    linear-gradient(135deg, rgba(108, 55, 35, 0.12), transparent 42%),
    #d8c18e;
  color: #2a2016;
  transform: translateX(96px) rotate(4deg);
  transition: transform 0.24s ease;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.26);
}

.bones-card.shown {
  transform: translateX(0) rotate(4deg);
}

.bones-card span {
  font-size: 0.62rem;
  font-weight: 900;
}

.bones-card strong {
  font-size: 2rem;
}

.table-scum,
.clockwork-grime {
  position: absolute;
  pointer-events: none;
  opacity: 0.58;
}

.scum-a {
  left: 16%;
  bottom: 18%;
  width: 80px;
  height: 28px;
  border-top: 2px solid rgba(38, 22, 15, 0.5);
  border-left: 2px solid rgba(38, 22, 15, 0.35);
  transform: rotate(-16deg);
}

.scum-b {
  right: 26%;
  bottom: 12%;
  width: 52px;
  height: 22px;
  border-top: 2px solid rgba(137, 96, 42, 0.42);
  transform: rotate(19deg);
}

.clockwork-case {
  min-height: 260px;
  padding: 28px 78px 42px 18px;
  background:
    radial-gradient(circle at 20% 78%, rgba(69, 35, 20, 0.32) 0 10px, transparent 11px),
    linear-gradient(180deg, rgba(115, 78, 38, 0.2), rgba(18, 22, 20, 0.36)),
    #483c2a;
}

.clockwork-face {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  height: 136px;
  padding: 14px;
  border: 5px solid #2b2015;
  border-radius: 7px;
  background:
    linear-gradient(180deg, rgba(229, 202, 124, 0.18), transparent),
    #151a17;
  box-shadow:
    0 0 0 2px rgba(219, 193, 121, 0.45),
    inset 0 0 22px rgba(0, 0, 0, 0.62);
}

.clockwork-symbol {
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid rgba(238, 221, 173, 0.18);
  border-radius: 5px;
  background:
    linear-gradient(180deg, rgba(230, 212, 166, 0.1), rgba(0, 0, 0, 0.28)),
    #263328;
}

.clockwork-symbol::before {
  content: "";
  width: 46px;
  height: 46px;
  background: #d9c37b;
  filter: drop-shadow(0 2px 0 #20170f);
}

.clockwork-symbol.anchor::before {
  clip-path: polygon(47% 0, 58% 0, 58% 50%, 83% 38%, 91% 52%, 63% 69%, 71% 88%, 53% 100%, 36% 88%, 44% 69%, 15% 52%, 23% 38%, 47% 50%);
}

.clockwork-symbol.coin::before {
  border-radius: 50%;
  box-shadow: inset 0 0 0 8px rgba(97, 67, 25, 0.45);
}

.clockwork-symbol.crown::before {
  clip-path: polygon(8% 32%, 26% 52%, 39% 20%, 52% 56%, 70% 21%, 88% 52%, 92% 32%, 82% 88%, 18% 88%);
}

.clockwork-symbol.skull::before {
  clip-path: polygon(25% 20%, 75% 20%, 88% 42%, 80% 70%, 63% 70%, 63% 88%, 38% 88%, 38% 70%, 20% 70%, 12% 42%);
}

.clockwork-symbol.rum::before {
  clip-path: polygon(40% 0, 62% 0, 62% 20%, 72% 30%, 72% 96%, 28% 96%, 28% 30%, 40% 20%);
}

.clockwork-symbol.compass::before {
  clip-path: polygon(50% 0, 61% 38%, 100% 50%, 61% 62%, 50% 100%, 39% 62%, 0 50%, 39% 38%);
}

.clockwork-lever {
  position: absolute;
  right: 15px;
  top: 42px;
  z-index: 2;
  width: 46px;
  height: 138px;
  min-height: 138px;
  padding: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #312419, #17130f);
}

.clockwork-lever span {
  position: absolute;
  left: 18px;
  top: 14px;
  width: 8px;
  height: 92px;
  border-radius: 8px;
  background: #d9c37b;
  transform-origin: 50% 100%;
  transform: rotate(-7deg);
  box-shadow: 0 0 0 2px rgba(30, 22, 15, 0.72);
}

.clockwork-lever span::before {
  content: "";
  position: absolute;
  left: -8px;
  top: -18px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #9b2f27;
  box-shadow: 0 0 0 2px #1a120d;
}

.coin-chute {
  position: absolute;
  right: 80px;
  bottom: 16px;
  width: 130px;
  height: 54px;
  border: 2px solid rgba(34, 24, 14, 0.76);
  border-radius: 0 0 52px 52px;
  background: rgba(18, 16, 13, 0.44);
}

.coin-chute i {
  position: absolute;
  left: calc(14px + var(--drop) * 21px);
  bottom: calc(6px + var(--drop) * 2px);
  width: 18px;
  height: 8px;
  border-radius: 50%;
  background: #d9b95e;
  border: 1px solid #4a3516;
}

.grime-a {
  left: 22px;
  bottom: 24px;
  width: 78px;
  height: 26px;
  border-top: 2px solid rgba(29, 17, 12, 0.6);
  transform: rotate(-12deg);
}

.grime-b {
  right: 24px;
  top: 20px;
  width: 42px;
  height: 72px;
  border-right: 2px solid rgba(29, 17, 12, 0.42);
}

.gambling-ledger {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.gambling-ledger article,
.gambling-status {
  margin: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(91, 78, 52, 0.16);
}

.gambling-status {
  line-height: 1.38;
}

.gambling-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.compact-controls {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.gambling-controls button.active {
  background:
    linear-gradient(180deg, rgba(225, 213, 162, 0.12), rgba(37, 48, 33, 0.18)),
    var(--reef);
  color: #101711;
}

@media (max-width: 560px) {
  dialog.gambling-modal {
    width: 100dvw;
    max-width: 100dvw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    padding: calc(max(10px, env(safe-area-inset-top)) + 4px) 10px calc(max(10px, env(safe-area-inset-bottom)) + 4px);
  }

  .gambling-scene {
    min-height: 218px;
  }

  .gambling-ledger {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gambling-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .compact-controls {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .compact-controls button {
    padding-inline: 4px;
  }

  .clockwork-case {
    min-height: 226px;
    padding: 22px 64px 38px 12px;
  }

  .clockwork-face {
    height: 116px;
    gap: 7px;
    padding: 10px;
  }

  .clockwork-symbol::before {
    width: 34px;
    height: 34px;
  }

  .clockwork-lever {
    right: 11px;
    top: 34px;
    width: 40px;
    height: 124px;
    min-height: 124px;
  }

  .coin-chute {
    right: 62px;
    width: 106px;
  }

  .bones-card {
    right: 8px;
    top: 42px;
    width: 72px;
    height: 92px;
  }

  .tavern-die {
    width: 54px;
    height: 54px;
  }

  .die-1 { --pip-shadow: none; }
  .die-1::before { left: 23px; top: 21px; }
  .die-2 { --pip-shadow: 28px 28px 0 #15130f; }
  .die-3 { --pip-shadow: 14px 14px 0 #15130f, 28px 28px 0 #15130f; }
  .die-4 { --pip-shadow: 28px 0 0 #15130f, 0 28px 0 #15130f, 28px 28px 0 #15130f; }
  .die-5 { --pip-shadow: 28px 0 0 #15130f, 14px 14px 0 #15130f, 0 28px 0 #15130f, 28px 28px 0 #15130f; }
  .die-6 { --pip-shadow: 0 14px 0 #15130f, 0 28px 0 #15130f, 28px 0 0 #15130f, 28px 14px 0 #15130f, 28px 28px 0 #15130f; }

  dialog.chart-modal {
    width: 100dvw;
    max-width: 100dvw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    padding: calc(max(10px, env(safe-area-inset-top)) + 4px) 10px calc(max(10px, env(safe-area-inset-bottom)) + 4px);
  }

  dialog.chart-modal #modalBody {
    height: calc(100% - 40px);
  }

  dialog.chart-modal .modal-close {
    top: calc(max(10px, env(safe-area-inset-top)) + 4px);
    right: 10px;
  }

  .chart-legend {
    max-height: 34px;
  }

  .tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .ship-row {
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .market-actions {
    grid-template-columns: 1fr;
  }

  .ship-row > .fleet-controls,
  .ship-row > button {
    grid-column: 1 / -1;
    width: 100%;
  }

  .ship-portrait {
    width: 92px;
    height: 56px;
  }

  .ship-row .row-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .welcome-hero {
    grid-template-columns: 104px minmax(0, 1fr);
  }

  .modal-actions {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 820px) {
  .hud-top,
  .target-card {
    width: 430px;
    right: auto;
  }

  .bottom-sheet {
    left: 0;
    right: 0;
    width: auto;
    top: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(430px, 520px);
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 12px;
    max-height: none;
    border-top: 0;
    border-left: 0;
    padding: calc(max(18px, env(safe-area-inset-top)) + var(--ad-offset) + 64px) 16px max(14px, env(safe-area-inset-bottom));
    background:
      linear-gradient(90deg, transparent 0 calc(100% - 548px), rgba(18, 19, 15, 0.45) calc(100% - 548px)),
      var(--panel);
  }

  .panel-header {
    grid-column: 1;
    grid-row: 1;
    z-index: 2;
    align-self: start;
    min-width: 0;
    margin: 0;
    padding: 12px;
    border: 1px solid rgba(202, 181, 133, 0.28);
    border-radius: 8px;
    background: rgba(24, 28, 24, 0.78);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
  }

  .scene-canvas {
    grid-column: 1;
    grid-row: 2 / 4;
    justify-self: center;
    align-self: start;
    width: min(100%, calc((100vh - var(--ad-offset) - 138px) * 1.909));
    height: auto;
    aspect-ratio: 21 / 11;
    min-height: 0;
    margin: 0;
    border-radius: 8px;
    object-fit: contain;
  }

  .tabs {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
    margin: 0;
  }

  .tab-panel {
    grid-column: 2;
    grid-row: 2;
    min-height: 0;
    overflow-y: auto;
    padding-right: 2px;
  }

  .port-sail-card {
    grid-column: 2;
    grid-row: 3;
    margin-top: 0;
  }

  .sail-controls {
    left: 18px;
    right: auto;
    bottom: 24px;
    width: 340px;
  }

  .sheet-grip {
    display: none;
  }

  .combat-actions {
    grid-template-columns: repeat(4, 1fr);
  }
}
