:root {
  --paper: #efe6d1;
  --paper2: #e6dbc2;
  --card: #f6f0e1;
  --ink: #2f2317;
  --ink2: #5b4a36;
  --muted: #8a765c;
  --rule: #c9b894;
  --brass: #a27a2f;
  --brass2: #c89b45;
  --walnut: #2b1f16;
  --walnut2: #3d2c1f;
  --sea: #cfdad3;
  --port: #b3362e;
  --stbd: #2e7d4f;
  --hit: #9c2a1f;
  --ok: #2e6b3f;
  --focus: #1f5fa8;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --hand: "Segoe Script", "Bradley Hand", "Snell Roundhand", "URW Chancery L", cursive;
  --mono: "Courier Prime", "Courier New", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--walnut); color: var(--ink); font-family: var(--serif); }
body { overflow: hidden; }
button, select, input { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

#app { display: grid; grid-template-rows: auto 1fr; height: 100vh; height: 100dvh; }
header {
  display: flex; align-items: center; gap: 16px; padding: 6px 14px;
  background: linear-gradient(#3a2a1d, #241a12); color: #eadcb8; border-bottom: 2px solid var(--brass);
  min-height: 46px; flex-wrap: wrap;
}
header h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
header h1 .amp { color: var(--brass2); font-style: italic; }
header .ver { font-size: 12px; font-weight: 400; color: var(--brass2); border: 1px solid #7a5d2a; border-radius: 3px; padding: 1px 5px; margin-left: 6px; vertical-align: 3px; }
#hdrInfo { flex: 1; font-size: 14px; color: #d8c79f; min-width: 160px; }
.hbtns { display: flex; gap: 6px; }
.hbtn { background: #4a3625; border: 1px solid #7a5d2a; color: #f0e2bd; padding: 5px 10px; border-radius: 4px; font-size: 13px; }
.hbtn:hover { background: #5a4230; }

main { display: grid; grid-template-columns: 300px 1fr 310px; min-height: 0; }
aside { background: var(--paper); overflow-y: auto; min-height: 0; }
#left { border-right: 2px solid var(--walnut2); padding: 10px; }
#right { border-left: 2px solid var(--walnut2); display: flex; flex-direction: column; }
#rightScroll { flex: 1; overflow-y: auto; padding: 10px; min-height: 0; }
#rightFoot { padding: 10px; border-top: 1px solid var(--rule); background: var(--paper2); }

.card { background: var(--card); border: 1px solid var(--rule); border-radius: 4px; padding: 9px 10px; margin-bottom: 10px; box-shadow: 0 1px 0 #fff8 inset; }
.card h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--ink2); margin: 0 0 6px; font-weight: 600; border-bottom: 1px solid var(--rule); padding-bottom: 4px; display: flex; justify-content: space-between; align-items: baseline; }
.card h2 small { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

#board { position: relative; background: var(--sea); min-width: 0; min-height: 0; overflow: hidden; touch-action: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#cv.dragging { cursor: grabbing; }
.zoomBox { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 4px; }
.zoomBox button { width: 34px; height: 34px; border-radius: 4px; border: 1px solid #7a5d2a; background: #f6f0e1e8; font-size: 18px; line-height: 1; color: var(--ink); }
#windRose { position: absolute; left: 10px; top: 10px; width: 92px; height: 92px; pointer-events: none; }
#tip { position: absolute; pointer-events: none; background: #fbf6ea; border: 1px solid var(--ink2); padding: 4px 7px; font-size: 12px; border-radius: 3px; display: none; white-space: nowrap; box-shadow: 0 2px 6px #0003; }
#banner { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: #2b1f16e0; color: #f3e5c0; padding: 5px 14px; border-radius: 16px; font-size: 14px; pointer-events: none; white-space: nowrap; border: 1px solid var(--brass); }
#mini { position: absolute; right: 12px; bottom: 12px; width: 220px; height: 145px; border: 2px solid #6d5a3e; border-radius: 5px; background: #d7e1daeb; box-shadow: 0 3px 12px #0005; cursor: crosshair; }

/* gunnery returns — the signature slip */
#returns { position: absolute; left: 12px; right: 56px; bottom: 12px; max-height: 46%; overflow-y: auto; background: #f7f1e2f5; border: 1px solid var(--ink2); border-radius: 4px; padding: 8px 10px; box-shadow: 0 4px 16px #0004; display: none; }
#returns header { all: unset; display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
#returns h3 { margin: 0; font-size: 14px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink2); }
.slips { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.slip { background: #fffdf6; border: 1px solid var(--rule); border-left: 4px solid var(--brass); padding: 6px 8px; font-size: 12px; position: relative; background-image: repeating-linear-gradient(transparent 0 17px, #d8cfb8 17px 18px); }
.slip.port { border-left-color: var(--port); }
.slip.stbd { border-left-color: var(--stbd); }
.slip .who { font-weight: 600; font-size: 13px; }
.slip table { width: 100%; border-collapse: collapse; margin-top: 3px; }
.slip td { padding: 0 2px; height: 18px; }
.slip td.n { text-align: right; font-family: var(--mono); }
.slip .stamp { position: absolute; right: 8px; top: 6px; border: 2px solid var(--hit); color: var(--hit); font-weight: 700; padding: 0 6px; transform: rotate(-6deg); font-size: 15px; background: #fffdf6; }
.slip .stamp.nil { border-color: var(--muted); color: var(--muted); }
.slip .alloc { margin-top: 3px; font-weight: 600; }
.slip .crit { color: var(--hit); font-weight: 700; }
.dice { font-size: 16px; }

/* ship record card */
.shipHead { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.shipName { font-size: 17px; font-weight: 600; }
.flag { display: inline-block; width: 14px; height: 10px; border: 1px solid #0006; margin-right: 5px; vertical-align: 0; }
.rec { display: grid; grid-template-columns: 72px 1fr; gap: 3px 6px; align-items: center; font-size: 12px; margin-top: 6px; }
.rec .lab { color: var(--ink2); }
.boxes { display: flex; flex-wrap: wrap; gap: 2px; }
.bx { width: 9px; height: 9px; border: 1px solid var(--ink2); background: #fffdf6; position: relative; }
.bx.x { background: #c7b99a; }
.bx.x::after { content: ""; position: absolute; left: -1px; right: -1px; top: 3px; height: 1px; background: var(--hit); transform: rotate(-45deg); }
.bx.c { border-radius: 50%; }
.rigRow { display: flex; gap: 2px; margin-bottom: 2px; }
.stat { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip { font-size: 11px; padding: 1px 6px; border-radius: 9px; border: 1px solid var(--rule); background: #fffaf0; white-space: nowrap; }
.chip.bad { border-color: var(--hit); color: var(--hit); }
.chip.good { border-color: var(--ok); color: var(--ok); }

/* battle dashboard */
.fleetGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.fleetSide { border: 1px solid var(--rule); border-radius: 4px; padding: 6px; background: #fffaf0; min-width: 0; }
.fleetSide.you { border-color: var(--brass); box-shadow: 0 0 0 1px #e3c984 inset; }
.fleetSide h3 { margin: 0 0 4px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fleetStat { display: flex; justify-content: space-between; gap: 5px; font-size: 11.5px; margin-top: 2px; }
.meter { height: 6px; border: 1px solid #9c8b6c; border-radius: 4px; background: #d8cfb8; overflow: hidden; margin: 1px 0 3px; }
.meter > span { display: block; height: 100%; background: var(--ok); }
.meter.crew > span { background: #315f89; }
.forecast { margin-top: 7px; border-top: 1px solid var(--rule); padding-top: 6px; font-size: 12px; }
.forecast .result { font-size: 14px; margin: 1px 0; }

/* captain's log */
.log { width: 100%; border-collapse: collapse; font-size: 13px; }
.log th { font-size: 11px; text-align: left; color: var(--ink2); border-bottom: 1px solid var(--ink2); font-weight: 600; }
.log td { border-bottom: 1px solid #d8cdb1; padding: 1px 3px; }
.log td.hand { font-family: var(--hand); font-size: 15px; color: #1d2a55; }
#journal { font-size: 12px; max-height: 260px; overflow-y: auto; }
#journal p { margin: 0 0 3px; line-height: 1.35; }
#journal .k-hit { color: #6d2a1c; }
#journal .k-crit, #journal .k-strike { color: var(--hit); font-weight: 600; }
#journal .k-turn { color: var(--ink2); font-weight: 600; border-top: 1px solid var(--rule); padding-top: 3px; margin-top: 4px; }
#journal .k-wind { color: #2c5a78; font-style: italic; }
#journal .k-board, #journal .k-grapple { color: #5b3a6b; }
.journalReport { max-height: 300px; overflow-y: auto; border: 1px solid var(--rule); background: #fffaf0; padding: 8px 10px; }
.journalReport p { margin: 0 0 5px; line-height: 1.35; }
.fleetMetrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin: 10px 0; }
.fleetMetrics div { border: 1px solid var(--rule); background: #fffaf0; padding: 8px; text-align: center; }
.fleetMetrics b { display: block; font-size: 22px; color: var(--ink2); }
.fleetMetrics span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
@media (max-width: 540px) { .fleetMetrics { grid-template-columns: repeat(2, 1fr); } }
.readinessList { display: grid; gap: 6px; margin: 10px 0; }
.readinessList div { display: grid; grid-template-columns: minmax(110px, .35fr) 1fr; gap: 8px; padding: 7px 9px; border: 1px solid var(--rule); background: #fffaf0; }
.readinessList .danger { border-left: 5px solid var(--hit); }
.readinessList .caution { border-left: 5px solid var(--brass); }
.readinessList .info { border-left: 5px solid var(--ink2); }
.fireBoard { margin-top: 7px; padding: 7px 9px; border: 1px solid var(--rule); background: #fffaf0; }
.fireBoard h4 { display: flex; justify-content: space-between; margin: 0 0 5px; }
.fireRow { padding: 5px 0; border-top: 1px solid #d8cdb1; }
.fireRow > div:first-child { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.fireRow > div:first-child span { color: var(--muted); }
.fireRow.crowded { color: var(--hit); }
.fireMeter { height: 5px; margin: 3px 0; border-radius: 3px; overflow: hidden; background: #ded3b8; }
.fireMeter span { display: block; height: 100%; background: var(--ink2); }
.fireRow.crowded .fireMeter span { background: var(--hit); }
.fireHeld { margin-top: 5px; }

/* controls */
.phase { font-size: 15px; font-weight: 600; }
.instr { font-size: 12.5px; color: var(--ink2); margin-top: 3px; line-height: 1.35; }
.shipList { display: flex; flex-direction: column; gap: 4px; }
.shipBtn { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; background: #fffaf0; border: 1px solid var(--rule); border-radius: 4px; padding: 5px 8px; font-size: 13px; }
.shipBtn.sel { border-color: var(--brass); background: #f3e5c0; box-shadow: 0 0 0 1px var(--brass) inset; }
.shipBtn .tag { font-family: var(--hand); color: #1d2a55; font-size: 14px; }
.shipBtn.dead { opacity: .55; }
.tacticalList { display: flex; flex-direction: column; gap: 4px; }
.tacticalShip { width: 100%; text-align: left; border: 1px solid var(--rule); border-radius: 4px; background: #fffaf0; padding: 5px 7px; }
.tacticalShip.sel { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass) inset; }
.tacticalShip .line { display: flex; justify-content: space-between; gap: 6px; }
.tacticalShip .detail { display: block; margin-top: 2px; font-size: 11.5px; color: var(--ink2); }
#tacticalHelp { margin: 0 0 6px; line-height: 1.35; }
.helm { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 5px; margin: 6px 0; }
.helm button, .btn { background: #fffaf0; border: 1px solid #8f7447; border-radius: 4px; padding: 7px 6px; font-size: 13px; }
.helm button:hover:not(:disabled), .btn:hover:not(:disabled) { background: #f3e5c0; }
.helm button:disabled, .btn:disabled { opacity: .45; cursor: default; }
.helm .port { color: var(--port); font-weight: 600; }
.helm .stbd { color: var(--stbd); font-weight: 600; }
.plotLine { display: flex; justify-content: space-between; align-items: center; gap: 6px; background: #fffdf6; border: 1px dashed var(--ink2); border-radius: 3px; padding: 4px 8px; min-height: 36px; }
.plotLine .hand { font-family: var(--hand); font-size: 22px; color: #1d2a55; }
.warn { color: var(--hit); font-size: 12px; min-height: 16px; margin-top: 2px; }
.seg { display: inline-flex; border: 1px solid #8f7447; border-radius: 4px; overflow: hidden; }
.seg button { border: 0; background: #fffaf0; padding: 4px 9px; font-size: 12.5px; }
.seg button.on { background: var(--walnut2); color: #f3e5c0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 6px 0; font-size: 13px; flex-wrap: wrap; }
.battery { border: 1px solid var(--rule); border-left-width: 4px; border-radius: 3px; padding: 6px 7px; margin-bottom: 7px; background: #fffaf0; font-size: 12.5px; }
.battery.port { border-left-color: var(--port); }
.battery.stbd { border-left-color: var(--stbd); }
.battery h4 { margin: 0 0 4px; font-size: 13px; display: flex; justify-content: space-between; }
.battery select { width: 100%; padding: 4px; border: 1px solid #8f7447; border-radius: 3px; background: #fffdf6; font-size: 12.5px; }
.main-btn { width: 100%; background: linear-gradient(#5a3f25, #3b2918); color: #f5e6bf; border: 1px solid var(--brass); border-radius: 5px; padding: 11px; font-size: 16px; font-weight: 600; letter-spacing: .04em; }
.main-btn:hover:not(:disabled) { background: linear-gradient(#6b4b2c, #45301c); }
.main-btn:disabled { opacity: .5; cursor: default; }
.foot-note { font-size: 11.5px; color: var(--muted); margin-top: 5px; text-align: center; }
.aid-btn { width: 100%; margin: 2px 0 7px; background: #efe0b9; border-color: var(--brass); font-weight: 600; }
.threat { margin-top: 7px; padding: 6px 7px; border: 1px solid var(--rule); border-radius: 3px; background: #fffaf0; }
.threat strong { color: var(--ink2); }
label.chk { display: flex; gap: 6px; align-items: center; font-size: 13px; margin: 4px 0; }

/* modal */
#modal { position: fixed; inset: 0; background: #140e09b8; display: none; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
#modal.on { display: flex; }
.sheet { background: var(--paper); border: 2px solid var(--brass); border-radius: 6px; max-width: 900px; width: 100%; max-height: 92vh; overflow-y: auto; padding: 18px 20px; box-shadow: 0 10px 40px #000a; }
.sheet h2 { margin: 0 0 4px; font-size: 24px; }
.sheet h3 { margin: 14px 0 6px; font-size: 15px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink2); }
.sheet p { line-height: 1.45; }
.scenGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.scen { text-align: left; background: var(--card); border: 1px solid var(--rule); border-radius: 5px; padding: 9px 10px; font-size: 13px; }
.scen.on { border-color: var(--brass); box-shadow: 0 0 0 2px var(--brass) inset; background: #f6ead0; }
.scen b { font-size: 15px; display: block; }
.scen .d { color: var(--muted); font-size: 12px; }
.scen .p { margin-top: 4px; color: var(--ink2); }
.opts { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.sheet .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.sheet table.t { border-collapse: collapse; font-size: 13px; width: 100%; }
.sheet table.t td, .sheet table.t th { border-bottom: 1px solid var(--rule); padding: 3px 6px; text-align: left; }
.result { font-size: 30px; font-weight: 700; margin: 4px 0; }

@media (max-width: 1100px) {
  main { grid-template-columns: 250px 1fr 270px; }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100vh; }
  main { grid-template-columns: 1fr; grid-template-rows: 58vh auto auto; }
  #board { order: 1; height: 58vh; }
  #right { order: 2; border-left: 0; border-top: 2px solid var(--walnut2); }
  #left { order: 3; border-right: 0; border-top: 2px solid var(--walnut2); }
  #rightScroll { overflow: visible; }
  #rightFoot { position: sticky; bottom: 0; }
  aside { overflow: visible; }
  header h1 { font-size: 17px; }
  #returns { right: 12px; max-height: 60%; }
  #windRose { width: 70px; height: 70px; }
  #mini { width: 160px; height: 105px; right: 8px; bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* watch bill — the signature slate of a damaged ship */
.bill { border: 1px solid var(--rule); border-left: 4px solid var(--brass); border-radius: 3px; padding: 6px 8px; margin-top: 8px; background: #fffaf0; }
.bill h4 { margin: 0 0 5px; font-size: 13px; display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.billrow { display: grid; grid-template-columns: 1fr auto; gap: 2px 6px; align-items: center; font-size: 12.5px; padding: 2px 0; border-bottom: 1px dotted #d8cdb1; }
.billrow .d { font-weight: 600; }
.billrow .small { grid-column: 1 / -1; margin-top: -2px; }
.billrow .v { font-family: var(--mono); display: flex; align-items: center; gap: 4px; }
.billrow.urgent .d { color: var(--hit); }
.step { width: 22px; height: 22px; border: 1px solid #8f7447; background: #fffdf6; border-radius: 3px; line-height: 1; font-size: 14px; padding: 0; }
.step:disabled { opacity: .35; cursor: default; }

/* the weight of the broadside, called out the same way in both panels */
.wgood { color: var(--ok); }
.wbad { color: var(--hit); }
/* a fingertip is not a mouse pointer: the steppers and the helm keep their size
   on a touch screen even where the sidebars are narrow */
@media (pointer: coarse) {
  .step { min-width: 34px; min-height: 34px; font-size: 16px; }
  .helm button { min-height: 44px; }
  .seg button { min-height: 34px; }
  .shipBtn { min-height: 38px; }
}
@media (max-width: 860px) {
  .step { min-width: 32px; min-height: 32px; }
  .helm button { min-height: 42px; }
}
