: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;
  touch-action: none;
  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);
  align-items: center;
  padding: 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-slot,
.tc-adsense-unit {
  width: 100%;
  min-width: 0;
  min-height: 32px;
  overflow: hidden;
}

.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: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 8px;
  padding: 10px 10px 10px 12px;
}

.sailing-menu-button {
  position: fixed;
  z-index: 6;
  top: calc(max(76px, calc(env(safe-area-inset-top) + 68px)) + var(--ad-offset));
  right: 10px;
  backdrop-filter: blur(16px);
}

.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 {
  width: min(100%, 720px);
  height: auto;
  aspect-ratio: 42 / 23;
  margin: 12px auto;
  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;
}

.tier-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 20px;
  padding: 2px 7px;
  border: 1px solid rgba(202, 181, 133, 0.36);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(236, 220, 174, 0.1), rgba(0, 0, 0, 0.14)),
    rgba(61, 52, 35, 0.72);
  color: #d9c895;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.02em;
  vertical-align: 0.02em;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.42);
}

.tier-badge.chip {
  margin-top: 0;
}

.tier-badge-rare {
  border-color: rgba(244, 199, 67, 0.72);
  background:
    linear-gradient(180deg, rgba(255, 235, 139, 0.42), rgba(120, 79, 17, 0.2)),
    #8a641f;
  color: #ffe68f;
  box-shadow:
    inset 0 1px 0 rgba(255, 245, 188, 0.38),
    0 0 0 1px rgba(64, 40, 8, 0.42);
}

.tier-badge-legendary {
  gap: 4px;
  border-color: rgba(112, 214, 255, 0.84);
  background:
    linear-gradient(180deg, rgba(172, 235, 255, 0.38), rgba(21, 82, 124, 0.28)),
    #123a56;
  color: #d8f6ff;
  box-shadow:
    inset 0 1px 0 rgba(215, 249, 255, 0.38),
    0 0 12px rgba(78, 191, 255, 0.24);
}

.tier-badge-legendary::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  transform: rotate(45deg);
  background: linear-gradient(135deg, #ecfbff, #50b9ff 55%, #1e5c9b);
  border: 1px solid rgba(217, 249, 255, 0.7);
  box-shadow: 0 0 6px rgba(88, 201, 255, 0.62);
}

.combat-tier {
  margin-left: 6px;
}

.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;
}

.bones-lab-screen {
  grid-template-columns: minmax(0, 1.12fr) minmax(260px, 0.88fr);
  align-items: stretch;
}

.bones-lab-screen .bones-scene {
  min-height: 420px;
  background:
    linear-gradient(180deg, rgba(231, 204, 140, 0.1), transparent 36%),
    linear-gradient(180deg, #263633 0 24%, #5a3b23 24% 70%, #251812 70%);
}

.bones-lab-screen .bones-scene::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0 9%, rgba(0, 0, 0, 0.22) 9% 10%, transparent 10% 21%, rgba(0, 0, 0, 0.18) 21% 22%, transparent 22%),
    repeating-linear-gradient(0deg, rgba(255, 244, 214, 0.04) 0 2px, transparent 2px 16px);
  pointer-events: none;
}

.bones-lab-screen .bones-scene::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 14% 70%, rgba(26, 13, 7, 0.34) 0 28px, transparent 30px),
    radial-gradient(ellipse at 82% 66%, rgba(14, 8, 5, 0.3) 0 34px, transparent 36px);
  mix-blend-mode: multiply;
  opacity: 0.78;
}

.tavern-light {
  position: absolute;
  top: -80px;
  left: 50%;
  width: 280px;
  height: 220px;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(227, 188, 94, 0.5), transparent 68%);
  animation: lantern 2.8s ease-in-out infinite;
}

.dealer-hand {
  position: absolute;
  z-index: 4;
  right: 6%;
  top: 34%;
  width: 220px;
  height: 168px;
  opacity: 0;
  transform: translateX(135%);
  transition: opacity 0.18s ease, transform 0.42s ease;
  pointer-events: none;
}

.dealer-hand.marked {
  opacity: 1;
  transform: translateX(0);
}

.dealer-hand.deal {
  animation: deal-card 1.08s cubic-bezier(.2, .9, .25, 1);
}

.point-card {
  position: absolute;
  left: 78px;
  top: 22px;
  width: 98px;
  height: 128px;
  display: grid;
  place-items: center;
  border: 2px solid #382315;
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 0 16%, rgba(98, 61, 33, 0.2) 16% 17%, transparent 17%),
    linear-gradient(#f2dec0, #b8955e);
  color: #21150d;
  box-shadow: 0 18px 22px rgba(0, 0, 0, 0.32);
}

.point-card span {
  align-self: end;
  color: #6a3e22;
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
}

.point-card strong {
  align-self: start;
  font-size: 3rem;
  line-height: 0.95;
}

.hand-cuff {
  position: absolute;
  right: 0;
  top: 30px;
  width: 82px;
  height: 42px;
  background: linear-gradient(#2f3c38, #17211f);
  border: 2px solid #09100f;
  transition: opacity 0.22s ease, transform 0.42s ease;
}

.hand-palm {
  position: absolute;
  right: 12px;
  top: 62px;
  width: 68px;
  height: 52px;
  border-radius: 28px 28px 18px 18px;
  background: linear-gradient(#b68156, #72452f);
  box-shadow:
    -24px 16px 0 -12px #8b573b,
    24px 16px 0 -12px #8b573b;
  transition: opacity 0.22s ease, transform 0.42s ease;
}

.dealer-hand.settled .hand-cuff,
.dealer-hand.settled .hand-palm {
  opacity: 0;
  transform: translateX(120px);
}

.felt-table {
  position: absolute;
  inset: auto 5% 7% 5%;
  height: 70%;
  overflow: visible;
  border: 12px solid #4d3320;
  border-radius: 44% 44% 18px 18px;
  background:
    radial-gradient(ellipse at 23% 64%, rgba(7, 13, 10, 0.36), transparent 18%),
    radial-gradient(ellipse at 76% 61%, rgba(83, 47, 21, 0.2), transparent 15%),
    radial-gradient(ellipse at 48% 82%, rgba(12, 8, 5, 0.22), transparent 28%),
    radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.08), transparent 28%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.035) 0 2px, transparent 2px 16px),
    #284935;
  box-shadow: inset 0 0 0 4px rgba(20, 11, 5, 0.46), 0 24px 40px rgba(0, 0, 0, 0.32);
}

.felt-table::before,
.felt-table::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.felt-table::before {
  left: 9%;
  top: 44%;
  width: 46px;
  height: 18px;
  border-radius: 50%;
  background: rgba(20, 11, 6, 0.24);
  box-shadow:
    318px 22px 0 8px rgba(12, 8, 5, 0.18),
    188px -78px 0 -4px rgba(207, 166, 94, 0.12);
  transform: rotate(-12deg);
}

.felt-table::after {
  right: 13%;
  bottom: 15%;
  width: 54px;
  height: 2px;
  background: rgba(18, 10, 6, 0.24);
  transform: rotate(-18deg);
  box-shadow:
    -248px -76px 0 rgba(18, 10, 6, 0.14),
    -226px -68px 0 rgba(215, 182, 108, 0.08);
}

.dice-bowl {
  position: absolute;
  left: 50%;
  top: 68%;
  width: min(430px, 70%);
  height: 170px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 50% 55%, rgba(18, 28, 22, 0.18), rgba(8, 10, 8, 0.62)),
    rgba(20, 36, 25, 0.68);
  border: 1px solid rgba(240, 226, 190, 0.18);
}

.sprite-die {
  position: absolute;
  top: 40px;
  width: 86px;
  height: 86px;
  border: 0;
  border-radius: 0;
  background-image: url("art/gambling/dice-sprites.svg");
  background-repeat: no-repeat;
  background-size: 600% 100%;
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.42);
}

.sprite-die:first-child {
  left: calc(50% - 104px);
  transform: rotate(-8deg);
}

.sprite-die:last-child {
  left: calc(50% + 22px);
  transform: rotate(10deg);
}

.sprite-die[data-face="1"] { background-position: 0% 0; }
.sprite-die[data-face="2"] { background-position: 20% 0; }
.sprite-die[data-face="3"] { background-position: 40% 0; }
.sprite-die[data-face="4"] { background-position: 60% 0; }
.sprite-die[data-face="5"] { background-position: 80% 0; }
.sprite-die[data-face="6"] { background-position: 100% 0; }

.point-rail,
.roll-total {
  position: absolute;
  z-index: 4;
  top: -86px;
  width: 112px;
  padding: 10px;
  border: 1px solid rgba(227, 210, 166, 0.18);
  background:
    linear-gradient(180deg, rgba(52, 71, 67, 0.84), rgba(20, 28, 27, 0.86)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 12px);
  box-shadow: 0 14px 22px rgba(0, 0, 0, 0.22);
}

.point-rail {
  left: calc(50% - 126px);
}

.roll-total {
  left: calc(50% + 14px);
  text-align: left;
}

.point-rail span,
.roll-total span,
.bones-ledger span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.point-rail strong,
.roll-total strong {
  display: block;
  margin-top: 2px;
  font-size: 1.6rem;
}

.bones-controls {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(22, 20, 15, 0.72);
}

.rules-card {
  display: grid;
  gap: 5px;
  min-height: 70px;
  padding: 10px 12px;
  border: 1px solid rgba(218, 194, 128, 0.26);
  border-radius: 7px;
  background: rgba(13, 18, 15, 0.62);
}

.rules-card strong {
  font-size: 1.05rem;
}

.rules-card span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.3;
}

.stake-row,
.bet-grid {
  display: grid;
  gap: 8px;
}

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

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

.stake-row button,
.bet-grid button,
.bones-roll-button {
  min-height: 44px;
}

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

.bet-grid button {
  display: grid;
  align-content: center;
  min-height: 74px;
  padding: 9px 8px;
}

.bet-grid span {
  display: block;
  margin-top: 4px;
  color: rgba(239, 230, 206, 0.74);
  font-size: 0.68rem;
  line-height: 1.15;
}

.bones-roll-button {
  font-size: 1.02rem;
}

.bones-ledger {
  grid-column: 1 / -1;
}

.bones-ledger article {
  display: grid;
  align-content: center;
  min-height: 58px;
}

.bones-ledger .wide {
  grid-column: span 2;
}

.bones-ledger strong {
  display: block;
  margin-top: 4px;
  line-height: 1.2;
}

@keyframes lantern {
  0%, 100% { opacity: 0.8; transform: translateX(-50%) scale(1); }
  50% { opacity: 1; transform: translateX(-50%) scale(1.05); }
}

@keyframes deal-card {
  0% { opacity: 0; transform: translateX(135%) rotate(-3deg); }
  18% { opacity: 1; }
  68% { opacity: 1; transform: translateX(10%) rotate(2deg); }
  100% { opacity: 1; transform: translateX(0) rotate(0); }
}

@keyframes deal-card-mobile {
  0% { opacity: 0; transform: translateX(135%) scale(0.78) rotate(-3deg); }
  18% { opacity: 1; }
  68% { opacity: 1; transform: translateX(10%) scale(0.78) rotate(2deg); }
  100% { opacity: 1; transform: translateX(0) scale(0.78) rotate(0); }
}

@media (max-width: 560px) {
  .ad-banner {
    left: 8px;
    right: 8px;
    height: 42px;
    padding: 6px 10px;
  }

  .hud-top {
    left: 8px;
    right: 8px;
  }

  .hud-top div {
    padding: 7px 7px;
  }

  .bottom-sheet {
    padding: calc(max(8px, env(safe-area-inset-top)) + var(--ad-offset) + 58px) 10px max(8px, env(safe-area-inset-bottom));
  }

  .panel-header {
    gap: 8px;
  }

  .panel-actions {
    gap: 6px;
  }

  .icon-button {
    width: 38px;
    min-width: 38px;
    height: 38px;
  }

  .panel-header p,
  .combat-top p {
    font-size: 0.66rem;
  }

  h1,
  h2 {
    font-size: 1.16rem;
  }

  .scene-canvas {
    height: clamp(138px, 24dvh, 188px);
    min-height: 138px;
    margin: 8px 0 8px;
  }

  .tabs {
    gap: 5px;
    margin: 7px 0 7px;
  }

  .tab {
    min-height: 36px;
  }

  .tab-panel {
    padding-bottom: 14px;
  }

  .row {
    min-height: 58px;
    padding: 9px;
  }

  .port-sail-card {
    min-height: 72px;
    padding: 9px;
  }

  .combat {
    place-items: stretch;
    padding: calc(8px + var(--ad-offset)) 8px max(8px, env(safe-area-inset-bottom));
  }

  .combat-card {
    width: 100%;
    max-height: calc(100dvh - var(--ad-offset) - max(16px, env(safe-area-inset-bottom)) - 10px);
    padding: 10px;
  }

  .combat-scene {
    width: min(100%, calc(174px * 42 / 23));
    height: auto;
    min-height: 0;
    margin: 8px auto;
  }

  .bars {
    gap: 6px;
    margin: 9px 0;
  }

  .combat-stats {
    gap: 5px;
    margin-bottom: 8px;
  }

  .combat-stats div {
    padding: 7px 4px;
  }

  .combat-stats strong {
    font-size: 0.82rem;
  }

  .combat-stats span {
    font-size: 0.56rem;
  }

  #combatText {
    max-height: 6.9em;
    overflow-y: auto;
    margin: 6px 0 9px;
    font-size: 0.9rem;
    line-height: 1.28;
  }

  .combat-actions {
    gap: 6px;
  }

  .combat-actions button {
    min-height: 46px;
    padding: 0 7px;
    gap: 5px;
  }

  .combat-actions svg {
    width: 17px;
    height: 17px;
  }

  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;
  }

  .bones-lab-screen {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .bones-lab-screen .bones-scene {
    min-height: 232px;
  }

  .felt-table {
    inset: auto 3% 3% 3%;
    height: 75%;
    border-width: 8px;
  }

  .dealer-hand {
    right: 3%;
    top: 26%;
    width: 168px;
    height: 132px;
  }

  .dealer-hand.marked {
    transform: translateX(0) scale(0.78);
    transform-origin: right top;
  }

  .dealer-hand:not(.marked) {
    transform: translateX(135%) scale(0.78);
    transform-origin: right top;
  }

  .dealer-hand.deal {
    animation: deal-card-mobile 1.08s cubic-bezier(.2, .9, .25, 1);
  }

  .point-card {
    left: 68px;
    top: 18px;
  }

  .point-rail,
  .roll-total {
    top: -66px;
    width: 84px;
    padding: 7px;
  }

  .point-rail {
    left: calc(50% - 92px);
  }

  .roll-total {
    left: calc(50% + 8px);
  }

  .point-rail strong,
  .roll-total strong {
    font-size: 1.35rem;
  }

  .dice-bowl {
    left: 50%;
    top: 70%;
    width: min(252px, 72%);
    height: 126px;
  }

  .sprite-die {
    top: 32px;
    width: 62px;
    height: 62px;
  }

  .sprite-die:first-child {
    left: calc(50% - 76px);
  }

  .sprite-die:last-child {
    left: calc(50% + 14px);
  }

  .bones-controls {
    padding: 8px;
    gap: 7px;
  }

  .rules-card {
    min-height: 54px;
    padding: 8px 10px;
    gap: 2px;
  }

  .rules-card strong {
    font-size: 0.95rem;
  }

  .rules-card span {
    font-size: 0.68rem;
    line-height: 1.25;
  }

  .stake-row,
  .bet-grid {
    gap: 6px;
  }

  .stake-row button {
    min-height: 36px;
    padding-inline: 4px;
  }

  .bet-grid button {
    min-height: 56px;
    padding: 7px 6px;
  }

  .bet-grid strong {
    font-size: 0.78rem;
  }

  .bet-grid span {
    margin-top: 2px;
    font-size: 0.58rem;
  }

  .bones-roll-button {
    min-height: 40px;
    font-size: 0.94rem;
  }

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

  .bones-ledger article {
    min-height: 46px;
    padding: 7px;
  }

  .bones-ledger span {
    font-size: 0.56rem;
  }

  .bones-ledger strong {
    margin-top: 2px;
    font-size: 0.72rem;
    line-height: 1.15;
  }

  .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: repeat(2, minmax(0, 1fr));
  }

  .trade-action-group {
    grid-template-columns: repeat(3, minmax(34px, 1fr));
    gap: 4px;
    padding: 5px;
  }

  .trade-action-group button {
    min-height: 36px;
    padding: 0 3px;
    font-size: 0.72rem;
  }

  .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 (max-width: 560px) and (max-height: 760px) {
  .ad-banner {
    height: 38px;
  }

  .hud-top div {
    padding: 6px 6px;
  }

  .hud strong {
    font-size: 0.92rem;
  }

  .hud span,
  .hud-top span {
    font-size: 0.6rem;
  }

  .bottom-sheet {
    padding-top: calc(max(7px, env(safe-area-inset-top)) + var(--ad-offset) + 52px);
  }

  .panel-header {
    min-height: 42px;
  }

  .scene-canvas {
    height: clamp(112px, 19dvh, 140px);
    min-height: 112px;
    margin: 7px 0;
  }

  .tabs {
    margin: 6px 0;
  }

  .tab {
    min-height: 34px;
  }

  .port-sail-card {
    min-height: 66px;
  }

  .combat-card {
    padding: 8px;
  }

  .combat-scene {
    width: min(100%, calc(140px * 42 / 23));
    height: auto;
    min-height: 0;
    margin: 7px auto;
  }

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

  .combat-stats div {
    padding: 6px 3px;
  }

  #combatText {
    max-height: 5.2em;
    font-size: 0.84rem;
  }

  .combat-actions button {
    min-height: 42px;
    font-size: 0.86rem;
  }
}

@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);
  }
}
