/* El Draque: sea-chart paper and brass over a 3D sea (SPEC §12). */
:root {
  color-scheme: light;
  --paper: rgba(242, 234, 214, .9);
  --paper-solid: #f2ead6;
  --edge: rgba(60, 50, 34, .3);
  --ink: #2a2622;
  --dim: #6f6656;
  --red: #a8321f;
  --blue: #2d5f8a;
  --brass: #b08d3c;
  --green: #3f6a34;
  --fell: "IM Fell English", "Cormorant Garamond", Georgia, serif;
  --fellsc: "IM Fell English SC", "IM Fell English", Georgia, serif;
  --serif: "Cormorant Garamond", Georgia, serif;
  --mono: "Courier Prime", "Courier New", ui-monospace, monospace;
  --st: env(safe-area-inset-top, 0px); --sr: env(safe-area-inset-right, 0px); --sb: env(safe-area-inset-bottom, 0px); --sl: env(safe-area-inset-left, 0px);
}
html, body { margin: 0; height: 100%; overflow: hidden; background: #1d2a33; color: var(--ink); font-family: var(--serif); user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
#view, #hud { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#view { touch-action: none; cursor: grab; }
#view:active { cursor: grabbing; }
#hud { pointer-events: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
kbd { font: 700 11px var(--mono); background: rgba(42, 38, 34, .08); border: 1px solid rgba(42, 38, 34, .3); border-radius: 3px; padding: 0 4px; white-space: nowrap; margin: 0 1px; }
.card { box-sizing: border-box; background: var(--paper); border: 1px solid var(--edge); border-radius: 3px; padding: 9px 12px; box-shadow: 0 3px 14px rgba(0, 0, 0, .28); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.k { font: 700 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
.v { font: 700 15px var(--mono); font-variant-numeric: tabular-nums; }
.v.small, .small { font-size: 12px; }
.dim { color: var(--dim); }
.title { font: 20px/1.1 var(--fell); margin-bottom: 4px; }
h1, h2, h3 { font-family: var(--fell); font-weight: 400; margin: 0 0 6px; }
h3 { font-size: 21px; }
.grid { display: grid; grid-template-columns: auto 1fr; gap: 1px 9px; align-items: baseline; }
.bars { display: grid; grid-template-columns: auto 1fr; gap: 3px 8px; align-items: center; margin-top: 6px; }
.bar { height: 6px; background: rgba(42, 38, 34, .15); border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar i { display: block; height: 100%; width: 100%; background: var(--green); transition: width .3s; }
.bar i.low { background: var(--red); }
.bar.water i { background: var(--blue); }
.bar.water i.low { background: var(--red); }
.bar.sus i { background: var(--brass); }
.bar.wide { flex: 1; height: 10px; }
.warn { color: var(--red); font: 700 12px/1.3 var(--mono); margin-top: 4px; }
.warn:empty { display: none; }
.pos { font: italic 600 15px var(--serif); margin-top: 4px; }
.pos.warn { font-family: var(--serif); font-size: 15px; }

/* ---- the play screen ---- */
#top { position: fixed; top: calc(10px + var(--st)); left: 50%; transform: translateX(-50%); text-align: center; pointer-events: none; width: min(640px, 80vw); }
#objective { display: inline-block; font: 19px/1.25 var(--fell); color: #f6efdc; text-shadow: 0 1px 4px rgba(0, 0, 0, .85), 0 0 12px rgba(0, 0, 0, .5); }
#progress { height: 4px; background: rgba(255, 255, 255, .25); margin: 6px auto 0; width: 260px; border-radius: 2px; overflow: hidden; }
#progress i { display: block; height: 100%; background: #e8cf86; width: 0; }
#tide { font: 700 12px var(--mono); color: #dfe9f0; text-shadow: 0 1px 3px #000; margin-top: 4px; }

#ship { position: fixed; left: calc(10px + var(--sl)); bottom: calc(10px + var(--sb)); width: 232px; }
#ship .rudder { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
#ship .track { flex: 1; height: 8px; border-radius: 4px; background: linear-gradient(90deg, rgba(168, 50, 31, .25), rgba(42, 38, 34, .1) 50%, rgba(63, 106, 52, .25)); position: relative; }
#ship .track i { position: absolute; top: -3px; width: 4px; height: 14px; background: var(--ink); border-radius: 2px; transform: translateX(-50%); left: 50%; }
#weather { position: fixed; right: calc(10px + var(--sr)); bottom: calc(10px + var(--sb)); width: 214px; padding: 8px 10px; }
#rose { width: 190px; height: 190px; display: block; margin: 0 auto 4px; }
#guns { position: fixed; bottom: calc(10px + var(--sb)); left: 50%; transform: translateX(-50%); display: flex; gap: 14px; align-items: center; padding: 8px 12px; }
#guns .battery { text-align: center; }
#guns .pips { display: flex; gap: 3px; margin-top: 4px; }
#guns .pips i { width: 11px; height: 22px; border: 1px solid rgba(42, 38, 34, .5); border-radius: 2px; position: relative; overflow: hidden; background: rgba(42, 38, 34, .05); }
#guns .pips i b { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(42, 38, 34, .35); }
#guns .pips i.ready b { background: var(--red); }
#guns .pips i.ready[data-shot="chain"] b { background: var(--brass); }
#guns .pips i.ready[data-shot="grape"] b { background: var(--blue); }
#guns .pips i.dead { border-style: dashed; opacity: .35; }
#guns .battery.ripple .k { color: var(--red); }
#guns .battery.ripple .k::after { content: ' · as she bears'; }
#guns .battery.shut .pips { opacity: .45; }
#guns .mid { text-align: center; min-width: 190px; }
#enemy { position: fixed; top: calc(10px + var(--st)); right: calc(10px + var(--sr)); width: 250px; }
#enemy .state { color: var(--red); font: italic 600 14px var(--serif); }
#enemy .good { color: var(--red); font-weight: 700; }
#e-sus { margin-top: 5px; }
#log { position: fixed; bottom: calc(96px + var(--sb)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 3px; pointer-events: none; width: min(560px, 60vw); }
#log .line { font: 15px/1.3 var(--serif); background: rgba(242, 234, 214, .88); padding: 3px 9px; border-left: 3px solid var(--dim); border-radius: 2px; transition: opacity 1.2s; }
#log .line.enemy, #log .line.bad { border-left-color: var(--red); }
#log .line.good { border-left-color: var(--green); }
#log .line.order { border-left-color: var(--brass); }
#log .line.say { border-left-color: var(--blue); font-style: italic; }
#log .line.old { opacity: 0; }
#boarding { position: fixed; top: 34%; left: 50%; transform: translateX(-50%); width: min(460px, 90vw); text-align: center; }
#boarding .bd { display: flex; gap: 10px; align-items: center; font: 700 12px var(--mono); }
#boarding .bar i { background: var(--green); }
#lesson { position: fixed; top: calc(48px + var(--st)); left: calc(10px + var(--sl)); width: 346px; max-height: calc(100vh - 300px); overflow: auto; }
#lesson canvas { display: block; margin: 6px 0; border: 1px solid var(--edge); border-radius: 2px; background: #efe5cc; max-width: 100%; }
#lesson p { font: 16px/1.4 var(--serif); margin: 6px 0; }
.buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.buttons.col { flex-direction: column; }
.buttons button, #viewbar button, .setting button, .menu button, #touch button {
  background: var(--paper-solid); border: 1px solid rgba(42, 38, 34, .4); border-radius: 3px; padding: 7px 12px; font: 700 13px var(--mono); }
.buttons button.primary, .menu button.primary { background: var(--red); color: #fff; border-color: var(--red); }
.buttons button.primary kbd { color: #fff; border-color: rgba(255, 255, 255, .5); background: rgba(255, 255, 255, .12); }
button:active { transform: translateY(1px); }
#viewbar { position: fixed; top: calc(10px + var(--st)); left: calc(10px + var(--sl)); display: flex; gap: 4px; }
#viewbar button { padding: 5px 9px; font-size: 12px; background: rgba(242, 234, 214, .85); }
#help { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(860px, 94vw); max-height: 88vh; overflow: auto; }
#help .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
#help p { margin: 4px 0; font-size: 15px; }
#chart { position: fixed; inset: 6vh 6vw; background: #efe2c2; border: 1px solid var(--edge); box-shadow: 0 6px 30px rgba(0, 0, 0, .5); border-radius: 3px; }
#chart canvas { width: 100%; height: 100%; display: block; }
#chart .chart-key { position: absolute; bottom: 8px; right: 12px; font: 700 12px var(--mono); color: var(--dim); }
#touch { position: fixed; left: 0; right: 0; bottom: calc(230px + var(--sb)); display: flex; justify-content: space-between; padding: 0 10px; pointer-events: none; }
#touch > div { display: flex; gap: 6px; pointer-events: auto; }
#touch button { padding: 14px 16px; font-size: 15px; background: rgba(242, 234, 214, .8); }

/* ---- the screens ---- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; box-sizing: border-box; overflow: auto; }
.screen.dim-bg { background: rgba(10, 16, 22, .45); }
.panel { width: min(560px, 100%); padding: 18px 22px; max-height: 92vh; overflow: auto; }
.panel.wide { width: min(980px, 100%); }
.panel h2 { font-size: 30px; }
.panel p { font-size: 17px; line-height: 1.45; }
#title { align-items: flex-end; justify-content: flex-start; background: linear-gradient(90deg, rgba(10, 14, 20, .62), rgba(10, 14, 20, .1) 55%, transparent); }
.masthead { max-width: 560px; color: #f4ecd8; padding: 0 0 6vh 4vw; text-shadow: 0 2px 10px rgba(0, 0, 0, .6); }
.masthead .sc { font: 20px var(--fellsc); letter-spacing: .08em; color: #e8cf86; }
.masthead h1 { font-size: clamp(64px, 11vw, 132px); line-height: .9; margin: 2px 0 12px; }
.masthead .sub { font: 20px/1.4 var(--serif); }
.masthead .hint { font: 15px var(--serif); opacity: .85; }
.masthead kbd { color: #f4ecd8; border-color: rgba(255, 255, 255, .4); background: rgba(255, 255, 255, .1); }
.menu { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin: 18px 0; }
.menu button { font: 22px var(--fell); padding: 8px 18px; min-width: 260px; text-align: left; background: rgba(242, 234, 214, .92); }
.voyage { display: grid; grid-template-columns: 1fr 400px; gap: 12px; width: 100%; height: 100%; max-width: 1500px; }
#voyage-cv { width: 100%; height: 100%; border: 1px solid var(--edge); border-radius: 3px; box-shadow: 0 6px 30px rgba(0, 0, 0, .5); cursor: pointer; min-height: 300px; }
.brief { overflow: auto; align-self: center; max-height: 100%; }
.brief h2 { font-size: 32px; }
.brief .place { font: italic 18px var(--serif); color: var(--dim); margin-bottom: 8px; }
.brief p { font: 17px/1.45 var(--serif); margin: 8px 0; }
.setting { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin: 8px 0; }
.setting .k { width: 120px; }
.setting button.on { background: var(--ink); color: var(--paper-solid); border-color: var(--ink); }
#book-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
#book-list .entry { border: 1px solid var(--edge); border-radius: 3px; padding: 8px 10px; background: rgba(255, 255, 255, .25); }
#book-list .entry.unseen { opacity: .42; }
#book-list canvas { max-width: 100%; height: auto !important; }
#book-list p { font-size: 15px; margin: 4px 0; }
.stats { display: grid; grid-template-columns: auto auto; gap: 2px 14px; justify-content: start; font: 14px var(--mono); margin: 8px 0; }
.history { font-style: italic; color: var(--dim); border-top: 1px solid var(--edge); padding-top: 8px; }

@media (max-width: 900px) {
  .voyage { grid-template-columns: 1fr; grid-template-rows: 46vh auto; }
  #lesson { right: 10px; left: 10px; width: auto; top: auto; bottom: calc(240px + var(--sb)); max-height: 40vh; }
  #enemy { width: 200px; font-size: 13px; }
  #guns .mid { min-width: 0; display: none; }
  #weather { width: 150px; }
  #rose { width: 130px; height: 130px; }
  #weather .grid { display: none; }
  #ship { width: 170px; font-size: 12px; }
  #ship .bars, #ship .grid span:nth-child(n+5) { display: none; }
}
