/* Fonts are bundled (no network needed). The Star Pups Emoji/Symbols/Arrows files are tiny subsets
   of Noto fonts covering only the characters the game uses, as a fallback for systems (e.g. some Linux
   installs) without an emoji font. Regenerate them with tools/subset_fonts.py. */
@font-face { font-family: 'Chewy'; src: url('../fonts/Chewy-Regular.ttf') format('truetype'); font-display: block; }
@font-face { font-family: 'Patrick Hand'; src: url('../fonts/PatrickHand-Regular.ttf') format('truetype'); font-display: block; }
@font-face { font-family: 'Star Pups Emoji'; src: url('../fonts/StarPupsEmoji.ttf') format('truetype'); font-display: block; }
@font-face { font-family: 'Star Pups Symbols'; src: url('../fonts/StarPupsSymbols.ttf') format('truetype'); font-display: block; }
@font-face { font-family: 'Star Pups Symbols'; src: url('../fonts/StarPupsArrows.ttf') format('truetype'); unicode-range: U+2190-21FF; font-display: block; }
:root {
  --emoji: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', 'Star Pups Emoji', 'Star Pups Symbols';
  --font-display: 'Chewy', var(--emoji), cursive;
  --font-body: 'Patrick Hand', var(--emoji), cursive;
  --ink: #2a2140; --paper: #fff4e0; --paper2: #fbe7c6; --pink: #ff8fab; --yellow: #ffd166;
  --teal: #4ecdc4; --blue: #5b8def; --orange: #ff9f43; --purple: #9b5de5; --green: #7bd389;
  --red: #ff6b6b; --night: #1b1433; --muted: #6d6283;
  --wob: 255px 18px 225px 18px / 18px 225px 18px 255px;
  --wob2: 18px 225px 18px 255px / 255px 18px 225px 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night);
  font-family: var(--font-body); color: var(--ink); user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#ui > * { pointer-events: auto; }
#ui > .passthru { pointer-events: none; }
h1, h2, h3, h4, .chewy { font-family: var(--font-display); font-weight: 400; margin: 0 0 .3em; letter-spacing: .5px; }
h2 { font-size: 30px; } h3 { font-size: 22px; } h4 { font-size: 18px; }
p { margin: .3em 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.big { font-size: 22px; }
.good { color: #1f8a4c; } .bad { color: #d63c4f; } .warn { color: #c7741a; }

/* ---------- overlays & paper ---------- */
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(20, 12, 40, .55); padding: 16px; animation: fadein .18s ease-out; }
.overlay.clear { background: transparent; }
.overlay.still, .overlay.still > * { animation: none; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.paper { background: var(--paper);
  background-image: repeating-linear-gradient(0deg, transparent 0 27px, rgba(91,141,239,.13) 27px 28px);
  border: 3px solid var(--ink); border-radius: var(--wob); box-shadow: 7px 8px 0 rgba(0,0,0,.35);
  padding: 18px 22px; position: relative; animation: popin .22s cubic-bezier(.3,1.6,.6,1); }
@keyframes popin { from { transform: scale(.9) rotate(-1deg); opacity: 0; } to { transform: none; opacity: 1; } }
.tape::before { content: ''; position: absolute; top: -15px; left: 50%; width: 120px; height: 28px;
  transform: translateX(-50%) rotate(-3deg); background: rgba(255,209,102,.8);
  border-left: 3px dashed rgba(0,0,0,.12); border-right: 3px dashed rgba(0,0,0,.12); }
.card { background: #fff; border: 2.5px solid var(--ink); border-radius: var(--wob2); padding: 10px 12px;
  box-shadow: 3px 4px 0 rgba(42,33,64,.25); margin-bottom: 10px; position: relative; }
.card.hl { background: #fff9e8; border-color: var(--orange); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.boil { animation: boil .36s steps(1) infinite; display: inline-block; }
@keyframes boil { 0% { transform: rotate(-.6deg); } 33% { transform: rotate(.5deg) translate(.6px,-.6px); } 66% { transform: rotate(-.2deg) translate(-.6px,.6px); } }
.wiggle { animation: wiggle 1.2s ease-in-out infinite; display: inline-block; }
@keyframes wiggle { 0%,100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }

/* ---------- buttons ---------- */
.btn { font-family: var(--font-display); font-size: 18px; background: var(--yellow); color: var(--ink);
  border: 3px solid var(--ink); border-radius: var(--wob); padding: 6px 16px; cursor: pointer;
  box-shadow: 3px 4px 0 var(--ink); transition: transform .08s; white-space: nowrap; }
.btn:hover:not(:disabled) { transform: translate(-1px,-1px) rotate(-1.2deg); filter: brightness(1.06); }
.btn:active:not(:disabled) { transform: translate(2px,3px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.pink { background: var(--pink); } .btn.teal { background: var(--teal); } .btn.blue { background: var(--blue); color: #fff; }
.btn.red { background: var(--red); } .btn.green { background: var(--green); } .btn.purple { background: var(--purple); color: #fff; }
.btn.white { background: #fff; } .btn.orange { background: var(--orange); }
.btn.small { font-size: 14px; padding: 2px 9px; box-shadow: 2px 2px 0 var(--ink); border-width: 2px; }
.btn.big { font-size: 26px; padding: 10px 28px; }
.btn.wide { width: 100%; }
.btn.sel { background: var(--teal); transform: rotate(-1.5deg); }

/* ---------- title / creator ---------- */
.title-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.logo { font-family: var(--font-display); font-size: clamp(56px, 11vw, 120px); line-height: .9; color: var(--yellow);
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
  text-shadow: 0 0 0 var(--ink), 5px 6px 0 var(--ink), -3px -3px 0 var(--paper), 3px -3px 0 var(--paper), -3px 3px 0 var(--paper), 8px 9px 0 var(--pink); }
.logo-sub { font-family: var(--font-display); font-size: 26px; color: var(--paper); text-shadow: 3px 3px 0 var(--ink); }
.creator { width: min(920px, 96vw); max-height: 94vh; overflow: auto; display: grid; grid-template-columns: 300px 1fr; gap: 18px; }
.creator .preview { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.opt-group { margin-bottom: 10px; }
.opt-group > label { font-family: var(--font-display); font-size: 17px; display: block; margin-bottom: 4px; }
.swatch { width: 30px; height: 30px; border-radius: 50% 45% 55% 48%; border: 3px solid var(--ink); cursor: pointer; display: inline-block; margin: 2px; }
.swatch.sel { outline: 3px dashed var(--ink); outline-offset: 2px; }
input.txt { font-family: var(--font-body); font-size: 20px; padding: 4px 10px; border: 2.5px solid var(--ink);
  border-radius: var(--wob2); background: #fff; width: 100%; color: var(--ink); }
.bg-card { cursor: pointer; flex: 1; min-width: 150px; }
.bg-card.sel { background: #e7fbf9; border-color: var(--teal); transform: rotate(-1deg); }

/* ---------- port ---------- */
.port { width: min(1180px, 97vw); height: min(760px, 95vh); display: grid; grid-template-columns: 250px 1fr; gap: 16px; padding: 16px; }
.port-side { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.port-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.port-content { flex: 1; overflow: auto; padding: 4px 8px 8px 2px; min-height: 0; }
.speech { background: #fff; border: 2.5px solid var(--ink); border-radius: 20px 24px 18px 26px; padding: 8px 10px; position: relative; font-size: 16px; min-height: 48px; }
.speech::after { content: ''; position: absolute; top: -12px; left: 40px; border: 10px solid transparent; border-bottom-color: var(--ink); }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tab { font-family: var(--font-display); font-size: 17px; padding: 4px 12px; border: 2.5px solid var(--ink); border-radius: 14px 14px 4px 4px;
  background: var(--paper2); cursor: pointer; }
.tab.sel { background: var(--yellow); transform: translateY(-2px) rotate(-1deg); box-shadow: 2px 3px 0 var(--ink); }
.tab .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--red); margin-left: 4px; vertical-align: middle; }
.hdr { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.pill { display: inline-block; padding: 1px 9px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; font-size: 14px; }
.pill.blue { background: #dbe7ff; } .pill.red { background: #ffd9d9; } .pill.green { background: #dff7e6; } .pill.yellow { background: #fff1c2; } .pill.purple { background: #efe3ff; }

table.tbl { width: 100%; border-collapse: separate; border-spacing: 0 5px; }
table.tbl th { font-family: var(--font-display); font-weight: 400; text-align: left; font-size: 16px; padding: 0 6px; color: var(--muted); }
table.tbl td { background: #fff; padding: 5px 6px; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); font-size: 17px; }
table.tbl td:first-child { border-left: 2px solid var(--ink); border-radius: 12px 0 0 12px; }
table.tbl td:last-child { border-right: 2px solid var(--ink); border-radius: 0 12px 12px 0; }
table.tbl tr.illegal td { background: #f4e9ff; }
.icon { font-size: 22px; width: 30px; text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.trend-up { color: #d63c4f; font-size: 13px; } .trend-down { color: #1f8a4c; font-size: 13px; }

.bar { height: 14px; border: 2px solid var(--ink); border-radius: 8px; background: #fff; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--pink); }
.bar.teal > i { background: var(--teal); } .bar.yellow > i { background: var(--yellow); } .bar.green > i { background: var(--green); } .bar.red > i { background: var(--red); }
.rep { display: grid; grid-template-columns: 170px 1fr 50px; gap: 8px; align-items: center; margin: 4px 0; }
.rep .track { height: 14px; border: 2px solid var(--ink); border-radius: 8px; background: linear-gradient(90deg, #ffd9d9 50%, #dff7e6 50%); position: relative; }
.rep .track i { position: absolute; top: -5px; width: 8px; height: 20px; background: var(--ink); border-radius: 4px; }

.stat { display: flex; justify-content: space-between; border-bottom: 1.5px dashed rgba(42,33,64,.25); padding: 2px 0; }
.shipcard canvas, .crewcard canvas { display: block; }
.canvas-cell { flex: 0 0 auto; }

/* ---------- dialog ---------- */
.dialog { width: min(720px, 96vw); display: grid; grid-template-columns: 170px 1fr; gap: 16px; }
.dialog .opts { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.dialog .opts .btn { text-align: left; }
.dialog .who { font-family: var(--font-display); font-size: 22px; }

/* ---------- map ---------- */
.mapwrap { width: min(1180px, 97vw); height: min(740px, 95vh); display: grid; grid-template-columns: 1fr 290px; gap: 14px; padding: 14px; }
.mapwrap canvas { width: 100%; height: 100%; border: 3px solid var(--ink); border-radius: 14px; background: #1b1433; cursor: pointer; display: block; }
.map-side { overflow: auto; display: flex; flex-direction: column; gap: 8px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: var(--paper); border: 2.5px solid var(--ink); border-radius: var(--wob); padding: 5px 16px; font-size: 18px;
  box-shadow: 3px 4px 0 rgba(0,0,0,.35); animation: toastin .25s cubic-bezier(.3,1.7,.6,1); max-width: 80vw; text-align: center; }
.toast.out { animation: toastout .4s forwards; }
.toast.good { background: #dff7e6; } .toast.bad { background: #ffd9d9; } .toast.info { background: #dbe7ff; } .toast.gold { background: #fff1c2; }
@keyframes toastin { from { transform: translateY(-20px) scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastout { to { transform: translateY(-14px); opacity: 0; } }

/* ---------- misc ---------- */
.keys { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 17px; }
kbd { font-family: var(--font-display); background: #fff; border: 2px solid var(--ink); border-bottom-width: 4px; border-radius: 6px; padding: 0 7px; font-size: 15px; }
.scroll { overflow: auto; }
.news-item { border-left: 5px solid var(--orange); padding-left: 10px; margin: 8px 0; }
.goal { display: flex; gap: 10px; align-items: center; }
.goal .check { font-size: 26px; }
.close-x { position: absolute; top: 8px; right: 12px; }
.tune-row { display: grid; grid-template-columns: 1fr 210px 84px 34px; gap: 10px; align-items: center; padding: 6px 6px; border-bottom: 1.5px dashed rgba(42,33,64,.2); }
.tune-row.changed { background: #fff1c2; border-radius: 10px; }
.tune-range { width: 100%; accent-color: var(--orange); cursor: pointer; }
.tune-val { font-family: var(--font-display); text-align: right; font-size: 17px; }
textarea.tune-json { width: 100%; height: 90px; font: 13px ui-monospace, Menlo, Consolas, monospace; border: 2px solid var(--ink); border-radius: 10px; padding: 6px; background: #fff; color: var(--ink); }
@media (max-width: 760px) {
  .port { grid-template-columns: 1fr; height: 96vh; }
  .port-side { flex-direction: row; flex-wrap: wrap; }
  .creator { grid-template-columns: 1fr; }
  .mapwrap { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .dialog { grid-template-columns: 1fr; }
  .tune-row { grid-template-columns: 1fr 120px 64px 30px; }
}
