:root{color-scheme:dark;--page-bg:#10151a;--panel-bg:#1b252d;--panel-border:#344553;--text:#f1f5f8;--muted:#b9c7d1;--accent:#e9b949}*{box-sizing:border-box}html,body{margin:0;min-height:100%;background:radial-gradient(circle at top,#24313b 0,var(--page-bg) 58%);color:var(--text);font-family:Arial,Helvetica,sans-serif}.game-shell{width:min(1080px,100vw);margin:0 auto;padding:18px}.game-header{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;margin-bottom:12px}.game-header h1{margin:0 0 6px;color:var(--accent);letter-spacing:.03em}.game-header p,.controls{margin:0;color:var(--muted)}.fullscreen-button{flex:0 0 auto;padding:10px 14px;border:1px solid rgba(255,255,255,.2);border-radius:10px;background:#263746;color:var(--text);font-weight:700;cursor:pointer;box-shadow:0 8px 22px rgba(0,0,0,.24)}.fullscreen-button:hover{background:#30485a}.canvas-wrap{position:relative;width:100%;overflow:auto;padding:12px;background:var(--panel-bg);border:1px solid var(--panel-border);border-radius:14px;box-shadow:0 18px 48px rgba(0,0,0,.35)}canvas{display:block;max-width:100%;height:auto;margin:0 auto;background:#f5f5eb;border:2px solid #0d1114;border-radius:10px;cursor:crosshair}#hud{position:absolute;top:24px;left:24px;min-width:270px;padding:11px 12px;background:rgba(12,16,20,.78);border:1px solid rgba(255,255,255,.18);border-radius:12px;color:#fff;font-size:15px;line-height:1.45;pointer-events:none;text-shadow:0 1px 2px rgba(0,0,0,.55);box-shadow:0 12px 28px rgba(0,0,0,.28)}#hud .hud-title{margin-bottom:6px;padding-bottom:6px;border-bottom:1px solid rgba(255,255,255,.18);color:#ffe08a;font-weight:700;letter-spacing:.03em}#hud .hud-row{display:flex;justify-content:space-between;gap:18px;margin:2px 0}#hud .hud-row span{color:#d7e3ea}#hud .health strong,#hud .health{color:#ff6b6b}#hud .score strong,#hud .score{color:#8ef0a4}#hud .carrying strong,#hud .carrying{color:#82c9ff}#hud .ship strong,#hud .ship{color:#ffe08a}#hud .pirate strong,#hud .pirate{color:#ff9f6e}#hud .health-meter{height:9px;margin:4px 0 8px;overflow:hidden;background:rgba(255,255,255,.16);border-radius:999px}#hud .health-meter div{height:100%;background:linear-gradient(90deg,#f87171,#facc15,#4ade80);border-radius:inherit}.controls{margin-top:12px;padding:12px 14px;background:rgba(27,37,45,.72);border:1px solid var(--panel-border);border-radius:12px}.game-shell:fullscreen{width:100vw;height:100vh;padding:10px;display:flex;flex-direction:column;background:radial-gradient(circle at top,#24313b 0,var(--page-bg) 58%)}.game-shell:fullscreen .canvas-wrap{flex:1;min-height:0;overflow:hidden;display:flex;align-items:center;justify-content:center}.game-shell:fullscreen canvas{width:auto;height:min(100%,calc(100vh - 145px));max-width:100%;max-height:100%}.game-shell:fullscreen .controls{font-size:13px}

#hud .powerup strong,#hud .powerup{color:#90cdf4}
#hud .level strong,#hud .level{color:#c4b5fd}
#hud .beer strong,#hud .beer{color:#fbbf24}

/* Layout upgrade: keep HUD beside the playfield instead of over the canvas. */
html, body {
  min-height: 100%;
}
body {
  background-image:
    linear-gradient(rgba(16, 21, 26, 0.84), rgba(16, 21, 26, 0.92)),
    var(--episode-watermark, url('/static/keg_favicon.png')),
    radial-gradient(circle at top, #24313b 0, var(--page-bg) 58%);
  background-repeat: no-repeat, no-repeat, no-repeat;
  background-position: center center, right 32px bottom 32px, center top;
  background-size: cover, min(36vw, 420px) auto, cover;
  background-attachment: fixed, fixed, fixed;
}
.game-shell {
  width: min(1420px, 100vw);
}
.canvas-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1024px) minmax(285px, 340px);
  gap: 14px;
  align-items: start;
  overflow: visible;
}
canvas {
  width: 100%;
  max-width: 1024px;
}
#hud {
  position: static;
  min-width: 0;
  width: 100%;
  pointer-events: auto;
}
.game-shell:fullscreen .canvas-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  align-items: start;
}
.game-shell:fullscreen canvas {
  height: min(100%, calc(100vh - 145px));
  width: auto;
  max-width: 100%;
}
@media (max-width: 1220px) {
  .canvas-wrap {
    grid-template-columns: 1fr;
  }
  #hud {
    order: -1;
  }
}

.high-score-box {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,.18);
}
.high-score-title {
  margin-top: 0;
}
.high-score-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin: 3px 0;
  font-size: 14px;
}
.high-score-row span {
  color: #d7e3ea;
}
.high-score-row strong {
  color: #8ef0a4;
}
.high-score-note {
  margin-top: 6px;
  color: #b9c7d1;
  font-size: 13px;
  line-height: 1.35;
}


.total-score {
  margin-bottom: 6px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(142, 240, 164, 0.10);
  font-size: 18px;
}
.total-score strong {
  font-size: 21px;
}
#hud small {
  color: rgba(215, 227, 234, 0.72);
  font-size: 11px;
  font-weight: 400;
}
.hud-subtitle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 10px 0 5px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,.14);
  color: #c4b5fd;
  font-size: 13px;
  font-weight: 700;
}
.hud-mini-button {
  padding: 3px 7px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 999px;
  background: rgba(38,55,70,.9);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.hud-dev-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  color: #b9c7d1;
  font-size: 12px;
}
.hud-dev-section .hud-row {
  font-size: 13px;
}

@media (max-width: 760px), (pointer: coarse) {
  .game-shell {
    padding: 8px;
  }
  .game-header {
    gap: 8px;
    margin-bottom: 8px;
  }
  .game-header h1 {
    font-size: 22px;
    margin-bottom: 2px;
  }
  .game-header p {
    display: none;
  }
  .fullscreen-button {
    padding: 8px 10px;
    font-size: 12px;
  }
  .canvas-wrap {
    gap: 8px;
    padding: 8px;
  }
  #hud {
    padding: 8px 9px;
    font-size: 12px;
    line-height: 1.25;
  }
  #hud .hud-title {
    margin-bottom: 4px;
    padding-bottom: 4px;
    font-size: 13px;
  }
  #hud .hud-row {
    margin: 1px 0;
    gap: 8px;
  }
  #hud .health-meter {
    height: 6px;
    margin: 2px 0 4px;
  }
  .total-score {
    font-size: 14px;
    padding: 4px 6px;
  }
  .total-score strong {
    font-size: 16px;
  }
  .hud-dev-toggle,
  .hud-dev-section,
  .high-score-box .high-score-row:nth-of-type(n+6),
  .controls {
    display: none;
  }
  .high-score-box {
    margin-top: 6px;
    padding-top: 6px;
  }
  .high-score-row,
  .high-score-note {
    font-size: 11px;
  }
}


/* Dedicated mobile wrapper and controls. Desktop keeps the full HUD. */
.mobile-controls {
  display: none;
}
@media (max-width: 760px), (pointer: coarse) {
  body {
    background-attachment: scroll, scroll, scroll;
  }
  .canvas-wrap {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  canvas {
    order: 1;
    width: 100%;
    max-height: 62vh;
    object-fit: contain;
    touch-action: none;
  }
  #hud {
    order: 2;
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 10px;
    row-gap: 2px;
  }
  #hud .hud-title,
  #hud .total-score,
  #hud .health-meter {
    grid-column: 1 / -1;
  }
  #hud .hud-row {
    min-width: 0;
  }
  #hud .hud-row span,
  #hud .hud-row strong {
    white-space: nowrap;
  }
  #hud .carrying,
  #hud .pirate,
  #hud .loaded-kegs,
  #hud .high-score-box {
    display: none;
  }
  .mobile-controls {
    display: grid;
    grid-template-columns: minmax(120px, 40%) 1fr;
    gap: 10px;
    position: sticky;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    z-index: 5;
    margin-top: 4px;
    margin-bottom: 16px;
    padding: 9px;
    background: rgba(27,37,45,.82);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    touch-action: none;
    user-select: none;
  }
  .mobile-pad {
    display: grid;
    grid-template-columns: repeat(3, minmax(36px, 1fr));
    grid-template-rows: repeat(3, 42px);
    gap: 5px;
  }
  .mobile-pad [data-mobile-control="up"] { grid-column: 2; grid-row: 1; }
  .mobile-pad [data-mobile-control="left"] { grid-column: 1; grid-row: 2; }
  .mobile-pad [data-mobile-control="down"] { grid-column: 2; grid-row: 2; }
  .mobile-pad [data-mobile-control="right"] { grid-column: 3; grid-row: 2; }
  .mobile-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(72px, 1fr));
    gap: 6px;
  }
  .mobile-controls button {
    border: 1px solid rgba(255,255,255,.22);
    border-radius: 12px;
    background: #263746;
    color: var(--text);
    font-weight: 800;
    font-size: 13px;
    box-shadow: 0 6px 16px rgba(0,0,0,.22);
  }
  .mobile-controls button.is-active,
  .mobile-controls button:active {
    transform: translateY(1px);
    background: #38576c;
  }
}
@media (max-width: 430px), (pointer: coarse) and (max-width: 430px) {
  #hud {
    grid-template-columns: 1fr;
  }
  #hud .powerup {
    display: none;
  }
  canvas {
    max-height: 54vh;
  }
  .mobile-controls {
    grid-template-columns: 1fr;
  }
}


/* Sound controls */
.header-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.sound-button.is-sound-off,
.mobile-actions [data-audio-toggle].is-sound-off {
  opacity: .72;
}
.mobile-actions [data-audio-toggle] {
  min-width: 94px;
}
@media (max-width: 720px) {
  .header-buttons {
    width: 100%;
    justify-content: flex-start;
  }
  .sound-button {
    padding: 8px 10px;
  }
}


/* Patch 14: version badge and three-state audio controls */
.version-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 7px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,255,255,.08);
  font-size: 13px;
  vertical-align: middle;
  letter-spacing: 0;
}
.sound-button.is-sound-fx,
.mobile-actions [data-audio-toggle].is-sound-fx {
  background: #2e4a5f;
}
.sound-button.is-sound-off,
.mobile-actions [data-audio-toggle].is-sound-off {
  opacity: .72;
  background: #3d4650;
}
@media (max-width: 720px) {
  .version-badge {
    margin-left: 4px;
    padding: 2px 6px;
    font-size: 11px;
  }
}


/* Patch 16: in-game AJAX-style prompt overlay. Avoid browser alert/confirm boxes. */
.game-prompt[hidden] {
  display: none !important;
}
.game-prompt {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background:
    radial-gradient(circle at center, rgba(233, 185, 73, 0.12), transparent 42%),
    rgba(4, 8, 12, 0.72);
  backdrop-filter: blur(4px);
}
.game-prompt-card {
  position: relative;
  width: min(460px, calc(100vw - 30px));
  padding: 24px 22px 18px;
  border: 2px solid rgba(233, 185, 73, 0.55);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(33, 47, 57, 0.98), rgba(13, 18, 24, 0.98));
  color: var(--text);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.62), inset 0 1px 0 rgba(255,255,255,.08);
  text-align: center;
}
.game-prompt-card::before {
  content: "Keg Runner - Beer Shipyard";
  display: block;
  margin-bottom: 9px;
  color: #ffe08a;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.game-prompt-title {
  margin: 2px 28px 8px;
  color: var(--accent);
  font-size: 26px;
  font-weight: 900;
  line-height: 1.1;
}
.game-prompt-message {
  margin: 0 auto 16px;
  max-width: 360px;
  color: #d7e3ea;
  font-size: 15px;
  line-height: 1.45;
}
.game-prompt-input-label {
  display: block;
  margin-bottom: 6px;
  color: #b9c7d1;
  font-size: 13px;
  font-weight: 700;
}
.game-prompt-input {
  width: 118px;
  margin: 0 auto 14px;
  padding: 10px 12px;
  border: 2px solid rgba(255,255,255,.18);
  border-radius: 12px;
  background: rgba(255,255,255,.92);
  color: #10151a;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: .22em;
  text-align: center;
  text-transform: uppercase;
}
.game-prompt-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.game-prompt-button {
  min-width: 118px;
  padding: 11px 16px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 12px;
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0,0,0,.28);
}
.game-prompt-button.primary {
  background: linear-gradient(180deg, #3b82a8, #1f5f82);
}
.game-prompt-button.secondary {
  background: #263746;
}
.game-prompt-button:hover,
.game-prompt-button:focus-visible {
  transform: translateY(-1px);
  outline: 2px solid rgba(233,185,73,.45);
}
.game-prompt-easter-egg {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: rgba(255,255,255,.28);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.game-prompt-easter-egg:hover {
  color: #ffe08a;
  background: rgba(255,255,255,.08);
}
.game-prompt-secret {
  min-height: 18px;
  margin: -4px 0 10px;
  color: #ffe08a;
  font-size: 12px;
  font-weight: 700;
}
@media (max-width: 520px) {
  .game-prompt-card {
    padding: 21px 16px 16px;
  }
  .game-prompt-title {
    font-size: 22px;
  }
  .game-prompt-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
  .game-prompt-button {
    width: 100%;
  }
}

/* Patch 19: cinematic intro, credits, and shared gameplay configuration. */
.game-media-stack {
  position: relative;
  width: 100%;
  max-width: 1024px;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 10px;
}
.game-media-stack canvas {
  width: 100%;
  max-width: none;
  margin: 0;
}
.intro-splash[hidden] {
  display: none;
}
.intro-splash {
  position: absolute;
  inset: 2px;
  z-index: 8;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  overflow: hidden;
  border-radius: 8px;
  background:
    radial-gradient(circle at 72% 22%, rgba(245, 189, 73, .30), transparent 30%),
    linear-gradient(145deg, #2c3b45 0%, #17242d 42%, #071117 100%);
}
.intro-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #101820;
}
.intro-splash.no-video .intro-video {
  display: none;
}
.intro-scrim {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(5, 10, 14, .88) 0%, rgba(5, 10, 14, .62) 42%, rgba(5, 10, 14, .12) 75%),
    linear-gradient(0deg, rgba(5, 10, 14, .82) 0%, transparent 55%);
}
.intro-content {
  position: relative;
  z-index: 2;
  width: min(590px, 78%);
  margin: 0 0 8% 7%;
  padding: 22px 24px;
  border-left: 5px solid var(--accent);
  background: rgba(8, 15, 20, .70);
  backdrop-filter: blur(5px);
  text-shadow: 0 3px 8px rgba(0,0,0,.72);
}
.intro-kicker {
  color: #ffd66e;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .22em;
  text-transform: uppercase;
}
.intro-title {
  margin-top: 3px;
  color: #fff6d7;
  font-size: clamp(38px, 6vw, 72px);
  line-height: .95;
  font-weight: 900;
  letter-spacing: -.025em;
}
.intro-subtitle {
  margin-top: 8px;
  color: var(--accent);
  font-size: clamp(24px, 3.7vw, 42px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: .04em;
}
.intro-content p {
  max-width: 520px;
  margin: 16px 0 18px;
  color: #e7eef2;
  font-size: 18px;
}
.intro-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.intro-actions button {
  padding: 12px 18px;
  border: 1px solid rgba(255,255,255,.30);
  border-radius: 10px;
  background: var(--accent);
  color: #15130d;
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
}
.intro-actions button.secondary {
  background: rgba(31, 51, 64, .92);
  color: #f5f8fa;
}
.intro-actions button:hover,
.intro-actions button:focus-visible {
  filter: brightness(1.12);
  transform: translateY(-1px);
}
.intro-hint {
  margin-top: 12px;
  color: #c8d3da;
  font-size: 13px;
}
.game-prompt-message {
  white-space: pre-line;
}
.game-shell:fullscreen .game-media-stack {
  width: auto;
  height: min(100%, calc(100vh - 145px));
  max-width: 100%;
}
.game-shell:fullscreen .game-media-stack canvas {
  width: auto;
  height: 100%;
  max-width: 100%;
}
@media (max-width: 720px) {
  .intro-content {
    width: calc(100% - 28px);
    margin: 0 14px 16px;
    padding: 16px;
  }
  .intro-content p {
    margin: 10px 0 13px;
    font-size: 14px;
  }
  .intro-actions button {
    flex: 1 1 135px;
    padding: 10px 12px;
    font-size: 14px;
  }
  .intro-hint {
    display: none;
  }
}

/* Patch 21: compact top-left cinematic title and difficulty selector. */
.intro-splash {
  align-items: flex-start;
  justify-content: flex-start;
}
.intro-scrim {
  background:
    linear-gradient(90deg, rgba(3, 8, 12, .56) 0%, rgba(3, 8, 12, .18) 48%, rgba(3, 8, 12, .04) 76%),
    linear-gradient(180deg, rgba(3, 8, 12, .34) 0%, transparent 48%, rgba(3, 8, 12, .26) 100%);
}
.intro-content {
  width: min(430px, calc(100% - 36px));
  margin: 20px 0 0 20px;
  padding: 16px 18px 15px;
  border-left: 4px solid var(--accent);
  border-top: 1px solid rgba(255, 255, 255, .18);
  border-right: 1px solid rgba(255, 255, 255, .11);
  border-bottom: 1px solid rgba(255, 255, 255, .11);
  border-radius: 0 14px 14px 0;
  background: rgba(6, 13, 18, .50);
  -webkit-backdrop-filter: blur(7px) saturate(1.05);
  backdrop-filter: blur(7px) saturate(1.05);
  box-shadow: 0 16px 42px rgba(0, 0, 0, .27);
  text-shadow: 0 2px 7px rgba(0, 0, 0, .72);
}
.intro-kicker {
  font-size: 12px;
  letter-spacing: .20em;
}
.intro-title {
  margin-top: 2px;
  font-size: clamp(34px, 5vw, 52px);
  line-height: .96;
}
.intro-subtitle {
  margin-top: 5px;
  font-size: clamp(22px, 3.2vw, 31px);
}
.intro-content p {
  max-width: 390px;
  margin: 10px 0 12px;
  font-size: 15px;
  line-height: 1.35;
}
.intro-difficulty {
  margin: 0 0 13px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, .14);
}
.intro-difficulty-heading {
  margin-bottom: 7px;
  color: #ffe08a;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.intro-difficulty-choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.intro-difficulty-choices button {
  min-height: 36px;
  padding: 7px 6px;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 9px;
  background: rgba(31, 51, 64, .78);
  color: #eef4f7;
  font-size: 12px;
  font-weight: 850;
  line-height: 1.12;
  cursor: pointer;
}
.intro-difficulty-choices button:hover,
.intro-difficulty-choices button:focus-visible {
  border-color: rgba(255, 224, 138, .72);
  background: rgba(46, 75, 92, .90);
  outline: 2px solid rgba(233, 185, 73, .30);
}
.intro-difficulty-choices button.is-selected,
.intro-difficulty-choices button[aria-pressed="true"] {
  border-color: #ffd66e;
  background: rgba(233, 185, 73, .94);
  color: #17130a;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .10);
}
.intro-difficulty-description {
  min-height: 31px;
  margin-top: 6px;
  color: #d5e0e6;
  font-size: 12px;
  line-height: 1.3;
}
.intro-actions button {
  padding: 10px 15px;
  font-size: 14px;
}
.intro-hint {
  margin-top: 8px;
  font-size: 11px;
}
#hud .difficulty strong,
#hud .difficulty {
  color: #ffd66e;
}

@media (max-width: 720px) {
  .intro-content {
    width: calc(100% - 20px);
    margin: 10px;
    padding: 13px 14px 12px;
    background: rgba(6, 13, 18, .66);
  }
  .intro-title {
    font-size: clamp(31px, 10vw, 43px);
  }
  .intro-subtitle {
    font-size: clamp(20px, 7vw, 27px);
  }
  .intro-content p {
    display: none;
  }
  .intro-difficulty {
    margin-bottom: 9px;
    padding-top: 8px;
  }
  .intro-difficulty-choices {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .intro-difficulty-choices button {
    min-height: 31px;
    padding: 6px 8px;
  }
  .intro-difficulty-description {
    display: none;
  }
}


/* Patch 22: lighter cinematic overlay, dropdown difficulty, and Dev HUD actions. */
.intro-scrim {
  background:
    linear-gradient(90deg, rgba(3, 8, 12, .28) 0%, rgba(3, 8, 12, .08) 38%, transparent 68%),
    linear-gradient(180deg, rgba(3, 8, 12, .18) 0%, transparent 42%, rgba(3, 8, 12, .16) 100%);
}
.intro-content {
  width: min(318px, calc(100% - 24px));
  margin: 12px 0 0 12px;
  padding: 11px 13px 12px;
  border-left-width: 3px;
  border-radius: 0 11px 11px 0;
  background: rgba(6, 13, 18, .34);
  -webkit-backdrop-filter: blur(3px) saturate(1.02);
  backdrop-filter: blur(3px) saturate(1.02);
  box-shadow: 0 9px 24px rgba(0, 0, 0, .18);
}
.intro-kicker { font-size: 10px; }
.intro-title { font-size: clamp(29px, 4vw, 40px); }
.intro-subtitle { margin-top: 2px; font-size: clamp(18px, 2.6vw, 24px); }
.intro-content p { margin: 7px 0 8px; font-size: 12px; line-height: 1.3; }
.intro-difficulty { margin-bottom: 9px; padding-top: 7px; }
.intro-difficulty-heading { display: block; margin-bottom: 4px; font-size: 10px; }
.intro-difficulty-select {
  width: 100%;
  padding: 7px 30px 7px 9px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 8px;
  background: rgba(21, 38, 49, .86);
  color: #f7fafc;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}
.intro-difficulty-select:focus-visible {
  outline: 2px solid rgba(233, 185, 73, .70);
  outline-offset: 2px;
}
.intro-difficulty-description { min-height: 0; margin-top: 4px; font-size: 10px; }
.intro-actions button { width: 100%; padding: 9px 12px; font-size: 13px; }
.intro-hint { margin-top: 5px; font-size: 10px; }
.hud-dev-actions { display: flex; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,.12); }

@media (max-width: 720px) {
  .intro-content {
    width: min(284px, calc(100% - 16px));
    margin: 8px;
    padding: 10px 11px;
    background: rgba(6, 13, 18, .46);
  }
  .intro-title { font-size: clamp(27px, 9vw, 36px); }
  .intro-subtitle { font-size: clamp(17px, 6vw, 22px); }
  .intro-difficulty-description { display: block; }
}

/* Patch 23: achievement toast and one-use power-up inventory. */
.achievement-toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(390px, calc(100vw - 28px));
  padding: 12px 15px;
  border: 1px solid rgba(255, 224, 138, .62);
  border-radius: 13px;
  background: rgba(8, 17, 23, .94);
  color: #f8fbfd;
  box-shadow: 0 16px 42px rgba(0, 0, 0, .42);
  transform: translate(-50%, -18px);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.achievement-toast.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
}
.achievement-toast-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #1a160c;
  font-size: 22px;
  font-weight: 900;
}
.achievement-toast-kicker {
  color: #ffe08a;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.achievement-toast-title {
  margin-top: 2px;
  font-size: 17px;
  font-weight: 900;
}
.achievement-toast-description {
  margin-top: 2px;
  color: #cad7df;
  font-size: 12px;
  line-height: 1.3;
}
#hud .inventory strong,
#hud .inventory {
  color: #ffe08a;
}
#hud .achievement-progress strong,
#hud .achievement-progress {
  color: #c4b5fd;
}

@media (max-width: 720px) {
  .achievement-toast {
    top: 8px;
    width: calc(100vw - 16px);
    padding: 10px 12px;
  }
  .achievement-toast-icon {
    width: 36px;
    height: 36px;
    font-size: 19px;
  }
  .achievement-toast-title {
    font-size: 15px;
  }
}

/* Patch 24 daily challenge */
.intro-difficulty-select:disabled { opacity: .65; cursor: not-allowed; }
#hud .challenge-mode strong, #hud .daily-seed strong { color: #f6c453; }
#hud .daily-seed strong { font-size: 12px; letter-spacing: .02em; }
.intro-select-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 9px; }
.intro-select-field { min-width: 0; }
.intro-select-field .intro-difficulty-heading { display: block; margin-bottom: 5px; }
.intro-option-notes { display: grid; gap: 2px; margin-top: 5px; }
.intro-option-notes .intro-difficulty-description { min-height: 0; margin-top: 0; }
@media (max-width: 520px) { .intro-select-grid { grid-template-columns: 1fr; gap: 6px; } }

/* Patch 26: long Pirate Guide / achievement text stays inside the in-game modal. */
.game-prompt-message {
  max-height: min(54vh, 520px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

/* Patch 27: permanent game tools, first-shift tutorial, and accessibility settings. */
.hud-tools-box {
  margin-top: 11px;
  padding-top: 9px;
  border-top: 1px solid rgba(255,255,255,.18);
}
.hud-tools-box .hud-subtitle {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
  color: #ffe08a;
}
.hud-tools-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.hud-tools-actions .hud-mini-button {
  width: 100%;
  min-height: 31px;
  padding: 6px 7px;
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.15;
}
.hud-tools-actions .hud-mini-button:focus-visible {
  outline: 3px solid rgba(255, 224, 138, .85);
  outline-offset: 2px;
}

.game-prompt.is-document .game-prompt-card {
  width: min(620px, calc(100vw - 30px));
}
.game-prompt.is-document .game-prompt-message {
  max-width: none;
  white-space: pre-wrap;
  text-align: left;
  line-height: 1.5;
}

.settings-overlay[hidden] {
  display: none !important;
}
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(3, 7, 11, .78);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}
.settings-card {
  width: min(620px, calc(100vw - 28px));
  max-height: min(88vh, 760px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px;
  border: 2px solid rgba(233, 185, 73, .55);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(29, 42, 51, .99), rgba(9, 15, 20, .99));
  color: var(--text);
  box-shadow: 0 28px 80px rgba(0,0,0,.64);
}
.settings-card h2 {
  margin: 3px 0 8px;
  color: var(--accent);
  font-size: 27px;
  line-height: 1.12;
}
.settings-kicker {
  color: #ffe08a;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.settings-intro {
  margin: 0 0 15px;
  color: var(--muted);
  line-height: 1.45;
}
.settings-options {
  display: grid;
  gap: 8px;
  margin-bottom: 15px;
}
.settings-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 11px;
  align-items: start;
  padding: 10px 11px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 11px;
  background: rgba(255,255,255,.035);
  cursor: pointer;
}
.settings-option:hover {
  background: rgba(255,255,255,.065);
}
.settings-option input {
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  accent-color: var(--accent);
}
.settings-option strong,
.settings-option small {
  display: block;
}
.settings-option strong {
  color: #f7fafc;
  font-size: 15px;
}
.settings-option small {
  margin-top: 2px;
  color: #b9c7d1;
  font-size: 12px;
  line-height: 1.35;
}
.settings-secondary-actions {
  display: flex;
  justify-content: flex-start;
  margin: 4px 0 10px;
}
.settings-status {
  min-height: 20px;
  margin-bottom: 8px;
  color: #8ef0a4;
  font-size: 13px;
}

.tutorial-card {
  width: min(590px, calc(100vw - 28px));
}
.tutorial-progress {
  float: right;
  margin-top: 1px;
  padding: 4px 8px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  color: #d7e3ea;
  background: rgba(255,255,255,.06);
  font-size: 11px;
  font-weight: 800;
}
.tutorial-body {
  min-height: 94px;
  margin: 12px 0;
  color: #d7e3ea;
  font-size: 17px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.tutorial-keys {
  min-height: 42px;
  margin-bottom: 18px;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  background: rgba(233, 185, 73, .08);
  color: #ffe08a;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.4;
  white-space: pre-wrap;
}
.tutorial-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.tutorial-nav-actions {
  display: flex;
  gap: 8px;
}

/* Accessibility modes are browser-local and never change scoring. */
html.keg-large-text body {
  font-size: 18px;
}
html.keg-large-text #hud {
  font-size: 17px;
  line-height: 1.55;
}
html.keg-large-text #hud .hud-row,
html.keg-large-text .high-score-row {
  font-size: 16px;
}
html.keg-large-text .hud-mini-button,
html.keg-large-text .fullscreen-button,
html.keg-large-text .mobile-controls button {
  font-size: 14px;
}
html.keg-large-text .game-prompt-message,
html.keg-large-text .settings-card,
html.keg-large-text .tutorial-body {
  font-size: 18px;
}

html.keg-high-contrast {
  --page-bg: #000;
  --panel-bg: #071019;
  --panel-border: #dbeafe;
  --text: #fff;
  --muted: #e2e8f0;
  --accent: #ffd84d;
}
html.keg-high-contrast .canvas-wrap,
html.keg-high-contrast #hud,
html.keg-high-contrast .game-prompt-card,
html.keg-high-contrast .settings-card {
  border-color: #fff;
}
html.keg-high-contrast #hud {
  background: #050a0f;
  text-shadow: none;
}
html.keg-high-contrast button:focus-visible,
html.keg-high-contrast select:focus-visible,
html.keg-high-contrast input:focus-visible {
  outline: 4px solid #ffd84d !important;
  outline-offset: 3px !important;
}

html.keg-reduced-motion *,
html.keg-reduced-motion *::before,
html.keg-reduced-motion *::after {
  scroll-behavior: auto !important;
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
}
html.keg-no-intro-video .intro-video {
  display: none !important;
}
html.keg-no-intro-video .intro-splash {
  background:
    radial-gradient(circle at 72% 28%, rgba(233,185,73,.25), transparent 24%),
    linear-gradient(145deg, #183247, #07131c 64%);
}

@media (max-width: 760px), (pointer: coarse) {
  .hud-tools-box {
    grid-column: 1 / -1;
  }
  .hud-tools-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .settings-overlay {
    padding: 8px;
    align-items: flex-end;
  }
  .settings-card {
    width: 100%;
    max-height: 92vh;
    padding: 17px 14px;
    border-radius: 17px 17px 8px 8px;
  }
  .settings-card h2 {
    font-size: 23px;
  }
  .tutorial-body {
    font-size: 15px;
  }
  .tutorial-actions,
  .tutorial-nav-actions {
    width: 100%;
  }
  .tutorial-actions > button,
  .tutorial-nav-actions button {
    flex: 1;
  }
}

@media (max-width: 430px), (pointer: coarse) {
  .hud-tools-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  html.keg-large-text #hud {
    font-size: 14px;
  }
}

/* Patch 28: optional contracts, combo/streak HUD emphasis. */
.intro-contract-field {
  margin-top: 8px;
}
.intro-contract-field .intro-difficulty-heading {
  display: block;
  margin-bottom: 5px;
}
.intro-option-notes {
  display: grid;
  gap: 3px;
}
#hud .combo strong,
#hud .clean-streak strong {
  color: #facc15;
}
#hud .contract strong {
  color: #c4b5fd;
}
#hud .contract-complete strong {
  color: #8ef0a4;
}
.hud-contract-box {
  margin-top: 9px;
  padding: 8px;
  border: 1px solid rgba(196, 181, 253, .28);
  border-radius: 10px;
  background: rgba(124, 58, 237, .08);
}
.hud-contract-progress {
  height: 7px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
}
.hud-contract-progress > div {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #a78bfa, #facc15);
}
.hud-contract-note {
  margin-top: 4px;
  color: #b9c7d1;
  font-size: 11px;
  line-height: 1.3;
}
@media (max-width: 760px), (pointer: coarse) {
  .intro-contract-field { margin-top: 6px; }
  #hud .hud-contract-box { grid-column: 1 / -1; }
  .hud-contract-note { display: none; }
}

/* Patch 29: wide, shallow shift briefing and weather/event HUD labels. */
.intro-content {
  width: min(720px, calc(100% - 28px));
  margin: 14px 0 0 14px;
  padding: 12px 15px 11px;
  border-left-width: 4px;
  border-radius: 0 12px 12px 0;
  background: rgba(5, 13, 18, .30);
  -webkit-backdrop-filter: blur(4px) saturate(1.05);
  backdrop-filter: blur(4px) saturate(1.05);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .16);
}
.intro-kicker {
  font-size: 12px;
  letter-spacing: .14em;
}
.intro-briefing {
  margin: 6px 0 9px;
  max-width: none;
  color: #edf4f7;
  font-size: 13px;
  line-height: 1.3;
}
.intro-difficulty {
  margin: 0;
  padding-top: 8px;
}
.intro-select-grid-three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.intro-select-field .intro-difficulty-description {
  min-height: 28px;
  margin-top: 4px;
  font-size: 10px;
  line-height: 1.25;
}
.intro-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 8px;
}
.intro-footer-row .intro-hint {
  margin: 0;
}
.intro-footer-row .intro-actions {
  flex: 0 0 auto;
}
.intro-footer-row .intro-actions button {
  width: auto;
  min-width: 190px;
  padding: 10px 18px;
}
#hud .weather strong,
#hud .weather {
  color: #90cdf4;
}
#hud .special-event strong,
#hud .special-event {
  color: #f6c453;
}
#hud .special-event.is-negative strong {
  color: #ff9f6e;
}

@media (max-width: 760px) {
  .intro-content {
    width: min(520px, calc(100% - 16px));
    margin: 8px;
    padding: 10px 11px;
    background: rgba(5, 13, 18, .48);
  }
  .intro-select-grid-three {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .intro-select-field .intro-difficulty-description {
    min-height: 0;
  }
  .intro-footer-row {
    align-items: stretch;
    flex-direction: column-reverse;
    gap: 5px;
  }
  .intro-footer-row .intro-actions,
  .intro-footer-row .intro-actions button {
    width: 100%;
  }
  .intro-briefing {
    display: block;
    margin-bottom: 6px;
    font-size: 11px;
  }
}

/* Patch 30: browser-local Dock Reputation and Captain's Locker. */
#hud .progression strong,
#hud .progression {
  color: #f6c453;
}
.hud-progression-bar {
  height: 7px;
  margin: 3px 0 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
}
.hud-progression-bar > div {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f6c453, #4ade80);
}
.locker-card {
  width: min(660px, 100%);
}
.locker-rank-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid rgba(246,196,83,.34);
  border-radius: 12px;
  background: rgba(246,196,83,.08);
}
.locker-rank-card > div {
  display: grid;
  gap: 2px;
}
.locker-rank-level {
  color: #f6c453;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.locker-rank-card strong {
  font-size: 20px;
}
.locker-progress {
  height: 10px;
  margin-top: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
}
.locker-progress > div {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #e9b949, #4ade80);
  transition: width .25s ease;
}
.locker-next-rank {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}
.locker-preview {
  position: relative;
  min-height: 102px;
  margin: 15px 0;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  background:
    linear-gradient(rgba(255,255,255,.04), rgba(255,255,255,.01)),
    repeating-linear-gradient(90deg, transparent 0 38px, rgba(255,255,255,.035) 39px 40px);
}
.locker-preview-forklift {
  --locker-paint: #f08a24;
  position: absolute;
  top: 31px;
  left: 50%;
  width: 72px;
  height: 38px;
  transform: translateX(-50%);
  border: 3px solid #161616;
  border-radius: 8px;
  background: var(--locker-paint);
}
.locker-preview-forklift::before {
  content: '';
  position: absolute;
  top: -5px;
  right: -17px;
  width: 18px;
  height: 46px;
  border: 3px solid #161616;
  border-left: 0;
  background: #4b5563;
}
.locker-preview-wheel {
  --locker-rim: #9ca3af;
  position: absolute;
  bottom: -14px;
  left: 7px;
  width: 18px;
  height: 18px;
  border: 5px solid #111;
  border-radius: 50%;
  background: var(--locker-rim);
}
.locker-preview-wheel.second {
  left: 45px;
}
.locker-preview-badge {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff7d6;
  font-size: 20px;
  text-shadow: 0 1px 2px #000;
}
.locker-preview-trail {
  position: absolute;
  top: 43px;
  left: calc(50% - 122px);
  width: 90px;
  color: #b9e6ff;
  font-size: 11px;
  font-weight: 700;
  text-align: right;
}
.locker-preview-trail[data-trail='bubbles']::after { content: ' ○  ◌  ○'; }
.locker-preview-trail[data-trail='foam']::after { content: ' ●  ◦  ●'; color: #fff7d6; }
.locker-preview-trail[data-trail='sparks']::after { content: ' ✦  ×  ✦'; color: #ffd24a; }
.locker-preview-trail[data-trail='confetti']::after { content: ' ▪  ◆  ▪'; color: #f472b6; }
.locker-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.locker-field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.locker-field select {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--panel-border);
  border-radius: 9px;
  background: #17242e;
  color: var(--text);
  font: inherit;
}
.locker-field option:disabled {
  color: #7c8790;
}
@media (max-width: 620px), (pointer: coarse) {
  .locker-grid { grid-template-columns: 1fr; }
  .locker-preview { min-height: 88px; }
  .locker-rank-card strong { font-size: 17px; }
}
.locker-backup {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.12);
}
.locker-backup label {
  color: var(--text);
  font-size: 13px;
}
.locker-backup textarea {
  width: 100%;
  min-height: 76px;
  resize: vertical;
  padding: 9px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 9px;
  background: #0d171e;
  color: var(--text);
  font: 12px/1.35 monospace;
}
.locker-backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}


/* Patch 32: shared episode shell and playfield-first mobile layout. */
@media (max-width: 900px), (pointer: coarse) {
  .game-shell {
    width: 100%;
    min-width: 0;
    padding: 6px;
  }
  .game-header {
    align-items: center;
    flex-wrap: wrap;
  }
  .game-header > div:first-child {
    min-width: 0;
    flex: 1 1 220px;
  }
  .game-header h1 {
    font-size: clamp(18px, 5.4vw, 25px);
    line-height: 1.05;
  }
  .version-badge {
    margin-left: 4px;
    padding: 2px 5px;
    font-size: 10px;
  }
  .canvas-wrap,
  .game-shell:fullscreen .canvas-wrap {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 7px;
    min-height: 0;
    overflow: visible;
    padding: 6px;
  }
  .game-media-stack,
  .game-shell:fullscreen .game-media-stack {
    order: 1 !important;
    display: block;
    flex: 0 0 auto;
    width: 100% !important;
    height: auto !important;
    min-width: 0;
    min-height: 210px;
    max-width: 100% !important;
    aspect-ratio: 4 / 3;
    margin: 0;
  }
  .game-media-stack canvas,
  .game-shell:fullscreen .game-media-stack canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: none !important;
    object-fit: contain;
  }
  #hud {
    order: 2 !important;
    width: 100%;
    max-height: 190px;
    overflow: hidden;
    overscroll-behavior: contain;
  }
  .game-shell[data-game-state="start"] #hud {
    display: none !important;
  }
  .game-shell.mobile-hud-expanded #hud {
    display: grid !important;
    max-height: min(62vh, 620px);
    overflow-y: auto;
    scrollbar-gutter: stable;
  }
  .game-shell:not(.mobile-hud-expanded) #hud .hud-tools-box,
  .game-shell:not(.mobile-hud-expanded) #hud .high-score-box,
  .game-shell:not(.mobile-hud-expanded) #hud .hud-contract-box,
  .game-shell:not(.mobile-hud-expanded) #hud .hud-dev-section,
  .game-shell:not(.mobile-hud-expanded) #hud .hud-dev-toggle,
  .game-shell:not(.mobile-hud-expanded) #hud .progression,
  .game-shell:not(.mobile-hud-expanded) #hud .hud-progression-bar,
  .game-shell:not(.mobile-hud-expanded) #hud .weather,
  .game-shell:not(.mobile-hud-expanded) #hud .special-event,
  .game-shell:not(.mobile-hud-expanded) #hud .combo,
  .game-shell:not(.mobile-hud-expanded) #hud .clean-streak,
  .game-shell:not(.mobile-hud-expanded) #hud .achievement-progress,
  .game-shell:not(.mobile-hud-expanded) #hud .powerup,
  .game-shell:not(.mobile-hud-expanded) #hud .inventory,
  .game-shell:not(.mobile-hud-expanded) #hud .pirate,
  .game-shell:not(.mobile-hud-expanded) #hud .beer,
  .game-shell:not(.mobile-hud-expanded) #hud .carrying {
    display: none !important;
  }
  .mobile-controls {
    position: sticky;
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    z-index: 20;
    margin-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  }
  .mobile-actions {
    grid-template-columns: repeat(3, minmax(66px, 1fr));
  }
  .intro-content {
    max-height: calc(var(--mobile-viewport-height, 100vh) - 150px);
    overflow-y: auto;
  }
}

@media (max-width: 430px), (pointer: coarse) {
  .game-media-stack,
  .game-shell:fullscreen .game-media-stack {
    min-height: 190px;
  }
  #hud {
    max-height: 168px;
    grid-template-columns: 1fr 1fr;
  }
  .game-shell.mobile-hud-expanded #hud {
    grid-template-columns: 1fr;
  }
  .mobile-actions {
    grid-template-columns: repeat(2, minmax(72px, 1fr));
  }
}

/* Patch 34: monetization is kept outside the gameplay canvas. */
.support-button { text-decoration: none; background: #6f4d18; }
.support-button:hover { background: #8b651f; }
.sponsor-panel[hidden] { display: none !important; }
.sponsor-panel {
  display: grid;
  grid-template-columns: auto 54px minmax(0,1fr) auto;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 11px 13px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(27,37,45,.86);
}
.sponsor-panel img { width: 54px; height: 54px; object-fit: contain; border-radius: 8px; background: #fff; }
.sponsor-panel .sponsor-disclosure { color: #ffe08a; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.sponsor-panel .sponsor-copy { display: grid; gap: 3px; }
.sponsor-panel .sponsor-copy span { color: var(--muted); font-size: 13px; }
.sponsor-panel a { color: #ffe08a; font-weight: 700; }
.game-footer-links { display: flex; flex-wrap: wrap; gap: 14px; padding: 12px 2px 0; font-size: 13px; }
.game-footer-links a { color: #b9dfff; }
@media (max-width: 720px) {
  .header-buttons .support-button { display: none; }
  .sponsor-panel { grid-template-columns: auto 1fr; }
  .sponsor-panel img { display: none; }
  .sponsor-panel a { grid-column: 1 / -1; }
}

/* Patch 34: illustrated pirate handbook. */
.pirate-guide-grid { display: grid; gap: 12px; }
.pirate-guide-card { display: grid; grid-template-columns: 118px minmax(0,1fr); gap: 14px; padding: 12px; border: 1px solid rgba(255,255,255,.16); border-radius: 12px; background: rgba(13,20,26,.72); }
.pirate-guide-card img { width: 118px; height: 118px; object-fit: cover; border-radius: 12px; border: 1px solid rgba(255,255,255,.2); }
.pirate-guide-card h3 { margin: 0 0 4px; color: #ffe08a; }
.pirate-guide-card h3 span { color: #9fd7ff; font-size: 12px; }
.pirate-guide-card p { margin: 4px 0; }
.pirate-guide-card ul { margin: 7px 0 0; padding-left: 18px; }
.pirate-guide-card li { margin: 3px 0; }
.pirate-guide-role { color: #d5e5ee; font-weight: 700; }
@media (max-width: 560px) { .pirate-guide-card { grid-template-columns: 76px minmax(0,1fr); gap: 9px; padding: 9px; } .pirate-guide-card img { width: 76px; height: 76px; } .pirate-guide-card ul { grid-column: 1 / -1; } }

/* Patch 37: controller remapping and mobile control polish. */
.controls-settings-card {
  width: min(820px, calc(100vw - 28px));
}
.controller-status {
  margin: 0 0 13px;
  padding: 9px 11px;
  border: 1px solid rgba(130, 201, 255, .35);
  border-radius: 10px;
  background: rgba(35, 86, 120, .15);
  color: #d8efff;
  font-size: 13px;
  line-height: 1.4;
}
.controller-status.is-connected {
  border-color: rgba(142, 240, 164, .48);
  background: rgba(33, 111, 60, .18);
  color: #baf6c8;
}
.controls-remap-head,
.controls-remap-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.1fr) minmax(150px, .95fr) minmax(180px, 1.15fr);
  gap: 9px;
  align-items: center;
}
.controls-remap-head {
  padding: 0 10px 6px;
  color: #9fb1bd;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.controls-remap-grid {
  display: grid;
  gap: 6px;
  margin-bottom: 15px;
}
.controls-remap-row {
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  background: rgba(255,255,255,.035);
}
.controls-remap-label strong,
.controls-remap-label small {
  display: block;
}
.controls-remap-label small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}
.controls-key-button,
.controls-gamepad-select {
  width: 100%;
  min-height: 38px;
  border: 1px solid rgba(255,255,255,.19);
  border-radius: 9px;
  background: #233746;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}
.controls-key-button {
  padding: 7px 9px;
  cursor: pointer;
}
.controls-key-button.is-capturing {
  border-color: var(--accent);
  background: rgba(233,185,73,.18);
  color: #ffe08a;
}
.controls-gamepad-select {
  padding: 6px 8px;
}
.controls-gamepad-fixed {
  color: #c9d6df;
  font-size: 12px;
  line-height: 1.3;
}
.controls-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.controls-option {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 7px 10px;
  align-items: center;
  padding: 10px 11px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 11px;
  background: rgba(255,255,255,.035);
}
.controls-option span,
.controls-option strong,
.controls-option small {
  display: block;
}
.controls-option small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}
.controls-option output {
  color: #ffe08a;
  font-weight: 900;
}
.controls-option input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--accent);
}

@media (max-width: 900px), (pointer: coarse) {
  body {
    overscroll-behavior-y: contain;
  }
  .game-media-stack,
  .game-shell:fullscreen .game-media-stack {
    contain: layout paint;
  }
  .mobile-controls {
    position: relative;
    inset: auto;
    bottom: auto;
    z-index: 8;
    margin: 4px 0 max(10px, env(safe-area-inset-bottom, 0px));
    padding-bottom: 0;
  }
  .game-shell:fullscreen .mobile-controls {
    position: sticky;
    bottom: max(4px, env(safe-area-inset-bottom, 0px));
    z-index: 30;
  }
  .mobile-controls button {
    min-height: 48px;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
  }
  .mobile-pad button {
    touch-action: none;
  }
  .game-shell:not(.mobile-hud-expanded) #hud {
    max-height: 156px;
  }
  .game-shell.mobile-hud-expanded #hud {
    max-height: min(55dvh, 560px);
  }
  .controls-remap-head {
    display: none;
  }
  .controls-remap-row {
    grid-template-columns: 1fr 1fr;
  }
  .controls-remap-label {
    grid-column: 1 / -1;
  }
  .controls-options-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .controls-settings-card {
    padding: 15px;
  }
  .controls-remap-row {
    grid-template-columns: 1fr;
  }
  .controls-remap-label,
  .controls-key-button,
  .controls-gamepad-select,
  .controls-gamepad-fixed {
    grid-column: 1;
  }
  .mobile-actions {
    gap: 6px;
  }
  .mobile-actions button {
    min-width: 0;
    padding-inline: 7px;
    font-size: 12px;
  }
}

@media (orientation: landscape) and (max-height: 560px) and (pointer: coarse) {
  .game-header p,
  .controls,
  .game-footer-links {
    display: none;
  }
  .game-shell {
    padding: 3px 6px;
  }
  .game-header {
    margin-bottom: 4px;
  }
  .game-media-stack,
  .game-shell:fullscreen .game-media-stack {
    max-height: calc(100dvh - 146px);
    min-height: 180px;
  }
  .mobile-controls {
    margin-top: 2px;
  }
}

/* Patch 38: Account / Service HUD foundation. */
.service-card {
  width: min(860px, calc(100vw - 28px));
}
.service-account-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  margin: 12px 0;
  padding: 13px 14px;
  border: 1px solid rgba(142,240,164,.28);
  border-radius: 12px;
  background: rgba(31,91,56,.14);
}
.service-account-card strong,
.service-account-card small,
.service-label {
  display: block;
}
.service-account-card strong {
  color: #c9f7d4;
  font-size: 20px;
}
.service-account-card small,
.service-label,
.service-note {
  color: var(--muted);
  font-size: 12px;
}
.service-label {
  margin-bottom: 3px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.service-account-id {
  text-align: right;
}
.service-account-id code {
  color: #b9dfff;
  font-size: 12px;
}
.service-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.service-section {
  padding: 12px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 11px;
  background: rgba(255,255,255,.035);
}
.service-section h3 {
  margin: 0 0 6px;
  color: #ffe08a;
  font-size: 15px;
}
.service-section p {
  margin: 5px 0;
  line-height: 1.4;
}
.service-actions,
.service-footer-actions,
.service-footer-right {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.service-actions {
  margin-top: 10px;
}
.service-footer-actions {
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}
.service-entitlements {
  margin: 7px 0;
  padding-left: 20px;
}
.service-entitlements li {
  margin: 4px 0;
  color: #d8efff;
}
.service-coming-soon {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 8px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  color: #b9c7d1;
  background: rgba(255,255,255,.05);
  font-size: 11px;
  font-weight: 800;
}
.service-status.is-online strong { color: #8ef0a4; }
.service-status.is-offline strong { color: #ffb37a; }
.settings-status.is-error { color: #ff9a9a; }
.settings-status.is-success { color: #8ef0a4; }

/* Patch 38: mobile summary must always expose health and avoid duplicate controls. */
@media (max-width: 900px), (pointer: coarse) {
  /* The top header remains the single Sound / Fullscreen control location. */
  .mobile-actions [data-audio-toggle],
  .mobile-actions [data-mobile-control="fullscreen"] {
    display: none !important;
  }
  .mobile-actions {
    grid-template-columns: repeat(2, minmax(82px, 1fr));
  }

  /* Input and difficulty details are desktop/expanded-development information. */
  #hud .input-status,
  #hud .difficulty {
    display: none !important;
  }

  /* Whitelist a compact, predictable mobile HUD so health never falls below a clip. */
  .game-shell:not(.mobile-hud-expanded) #hud {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    max-height: none !important;
    overflow: visible !important;
    padding: 7px 9px;
  }
  .game-shell:not(.mobile-hud-expanded) #hud > * {
    display: none !important;
  }
  .game-shell:not(.mobile-hud-expanded) #hud > .total-score,
  .game-shell:not(.mobile-hud-expanded) #hud > .level,
  .game-shell:not(.mobile-hud-expanded) #hud > .challenge-mode,
  .game-shell:not(.mobile-hud-expanded) #hud > .health {
    display: flex !important;
  }
  .game-shell:not(.mobile-hud-expanded) #hud > .total-score,
  .game-shell:not(.mobile-hud-expanded) #hud > .health,
  .game-shell:not(.mobile-hud-expanded) #hud > .health-meter {
    grid-column: 1 / -1;
  }
  .game-shell:not(.mobile-hud-expanded) #hud > .health-meter {
    display: block !important;
    margin-bottom: 1px;
  }
  .game-shell:not(.mobile-hud-expanded) #hud > .total-score {
    margin-bottom: 2px;
  }
  .game-shell:not(.mobile-hud-expanded) #hud > .health {
    margin-top: 2px;
  }
  .game-shell.mobile-hud-expanded #hud .service-status {
    display: flex;
  }

  .service-card {
    max-height: min(86dvh, 760px);
    overflow-y: auto;
  }
  .service-grid {
    grid-template-columns: 1fr;
  }
  .service-account-card {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .service-account-id {
    text-align: left;
  }
  .service-footer-actions {
    align-items: stretch;
  }
  .service-footer-actions > button,
  .service-footer-right,
  .service-footer-right button {
    flex: 1 1 auto;
  }
}
