:root {
  --parch: #e9d6a8;
  --parch-dark: #c9ad72;
  --ink: #3a2312;
  --blood: #8e1b10;
  --gold: #f1c35a;
  --brass: #b98a34;
  --sea: #0d1b26;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--parch); font-family: 'IM Fell English', Georgia, serif; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
.hidden { display: none !important; }

/* ---------- loading & title ---------- */
#loading { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; background: radial-gradient(circle, #1b1410, #000); z-index: 20; font-size: 22px; }
#loading .wheel { font-size: 84px; color: var(--gold); animation: spin 3s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#title { position: fixed; inset: 0; display: grid; place-items: center; z-index: 10;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.75) 75%); }
.title-inner { text-align: center; max-width: 620px; padding: 16px; animation: rise 1.2s ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }
.crest { font-size: 64px; color: var(--parch); text-shadow: 0 0 30px rgba(255,160,60,0.5); animation: bob 3.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-4deg); } }
h1 { font-family: 'Pirata One', serif; font-weight: 400; font-size: clamp(64px, 12vw, 132px); margin: 0; line-height: 0.95; letter-spacing: 2px;
  background: linear-gradient(180deg, #fff1c2 0%, #f1c35a 45%, #a0661c 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 #3a1a08) drop-shadow(0 10px 24px rgba(0,0,0,0.8)); }
.sub { font-style: italic; font-size: 24px; margin: 6px 0 26px; color: #f3e2b8; text-shadow: 0 2px 8px #000; }
.btn { font-family: 'Pirata One', serif; font-size: 34px; padding: 10px 46px 12px; color: #fff1d0; cursor: pointer; border: 3px solid #2a150a; border-radius: 10px;
  background: linear-gradient(180deg, #8a4a22, #5a2a12 60%, #3d1b0a); box-shadow: inset 0 2px 0 rgba(255,220,160,0.35), 0 6px 0 #1d0c04, 0 10px 30px rgba(0,0,0,0.6);
  text-shadow: 0 2px 0 #1d0c04; transition: transform 0.12s, box-shadow 0.12s, filter 0.2s; }
.btn:hover { filter: brightness(1.15); transform: translateY(-2px); }
.btn:active { transform: translateY(3px); box-shadow: inset 0 2px 0 rgba(255,220,160,0.35), 0 2px 0 #1d0c04; }
.howto { margin-top: 30px; padding: 18px 22px; color: var(--ink); text-align: left; font-size: 17px; line-height: 1.45; border-radius: 6px;
  background: linear-gradient(135deg, #efdcae, #d8bd83); box-shadow: 0 10px 30px rgba(0,0,0,0.6), inset 0 0 40px rgba(120,70,20,0.35); transform: rotate(-0.6deg); }
.howto p { margin: 0 0 10px; }
.howto ul { margin: 0; padding-left: 18px; columns: 2; column-gap: 26px; }
.howto li { margin: 2px 0; break-inside: avoid; }
kbd { font-family: 'IM Fell English SC', serif; background: #3a2312; color: var(--parch); border-radius: 4px; padding: 0 6px; font-size: 14px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.card { position: absolute; top: 16px; min-width: 250px; padding: 10px 16px 12px; color: var(--ink); border-radius: 6px;
  background: linear-gradient(135deg, #efdcae, #cfb277); box-shadow: 0 6px 20px rgba(0,0,0,0.55), inset 0 0 30px rgba(120,70,20,0.35);
  border: 2px solid #5a3616; transition: transform 0.3s, box-shadow 0.3s, opacity 0.3s; opacity: 0.78; }
.card.left { left: 16px; transform: rotate(-0.8deg); }
.card.right { right: 16px; transform: rotate(0.8deg); text-align: right; }
.card.active { opacity: 1; box-shadow: 0 0 0 3px var(--gold), 0 0 28px rgba(241,195,90,0.7), 0 6px 20px rgba(0,0,0,0.55); }
.card.left.active { transform: rotate(-0.8deg) scale(1.04); }
.card.right.active { transform: rotate(0.8deg) scale(1.04); }
.card .name { font-family: 'Pirata One', serif; font-size: 28px; line-height: 1; }
.card .group { font-style: italic; font-size: 15px; opacity: 0.8; margin: 2px 0 6px; }
.chips { display: flex; gap: 4px; min-height: 24px; }
.card.right .chips { justify-content: flex-end; }
.chip { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font: bold 10px Georgia, serif; color: #1b1612;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.6), transparent 40%), var(--c); box-shadow: inset 0 -3px 4px rgba(0,0,0,0.35), 0 1px 2px rgba(0,0,0,0.5); position: relative; }
.chip::after { content: ''; position: absolute; inset: 7px; border-radius: 50%; background: #f3ead6; z-index: 0; }
.chip { z-index: 0; }
.chip.stripe { background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.6), transparent 40%), linear-gradient(180deg, #f3ead6 26%, var(--c) 26%, var(--c) 74%, #f3ead6 74%); }
.chip { color: transparent; }
.chip.gone { opacity: 0.2; filter: grayscale(1); }
.chip.eight { --c: #121212; margin-left: 6px; }
.chip.eight.locked { opacity: 0.35; }
.chip.eight.hot { box-shadow: 0 0 0 2px var(--gold), 0 0 12px var(--gold); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 2px var(--gold), 0 0 22px var(--gold); } }

#banner { position: absolute; top: 18%; left: 50%; transform: translate(-50%, -10px) scale(0.96); text-align: center; opacity: 0; transition: opacity 0.35s, transform 0.35s; }
#banner.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
#banner-title { font-family: 'Pirata One', serif; font-size: clamp(34px, 5vw, 60px); color: #fff1d0; text-shadow: 0 3px 0 #3a1a08, 0 0 30px rgba(0,0,0,0.9); white-space: nowrap; }
#banner-sub { font-style: italic; font-size: 20px; color: #f3e2b8; text-shadow: 0 2px 6px #000; }

#rogue { position: absolute; top: 28%; left: 50%; transform: translateX(-50%); font-family: 'Pirata One', serif; font-size: clamp(30px, 4vw, 48px);
  color: #ffdd9a; background: rgba(120,15,5,0.85); padding: 6px 28px; border: 3px solid #ffb36a; border-radius: 8px; opacity: 0; transition: opacity 0.3s; white-space: nowrap; }
#rogue.show { opacity: 1; animation: alarm 0.6s steps(2) infinite; }
@keyframes alarm { 50% { background: rgba(200,40,10,0.95); } }

#quip { position: absolute; bottom: 118px; left: 50%; transform: translate(-50%, 10px); max-width: min(560px, 80vw); padding: 10px 18px; color: var(--ink);
  background: linear-gradient(135deg, #f3e3bc, #d9bf88); border-radius: 18px; border: 2px solid #5a3616; box-shadow: 0 6px 18px rgba(0,0,0,0.5);
  font-size: 19px; opacity: 0; transition: opacity 0.3s, transform 0.3s; text-align: center; }
#quip.show { opacity: 1; transform: translate(-50%, 0); }
#quip-who { display: block; font-family: 'Pirata One', serif; font-size: 16px; color: var(--blood); letter-spacing: 1px; }

.panel { position: absolute; color: var(--ink); background: linear-gradient(135deg, #efdcae, #cfb277); border: 2px solid #5a3616; border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.55), inset 0 0 30px rgba(120,70,20,0.35); }
#swell { left: 16px; bottom: 16px; width: 284px; padding: 8px 12px 6px; }
#swell canvas { width: 260px; height: 90px; display: block; }
#swell .label { font-family: 'Pirata One', serif; font-size: 19px; }
#seastate { color: var(--blood); }
#swell .legend { display: flex; gap: 10px; font-size: 12px; margin-top: 2px; }
.l1 { color: #5a200e; } .l2 { color: #1e466e; } .l3 { color: #a02a1a; }

#incl { position: absolute; right: 16px; bottom: 16px; width: 130px; text-align: center; }
#incl canvas { width: 120px; height: 120px; filter: drop-shadow(0 6px 12px rgba(0,0,0,0.7)); }
#incl .label { font-family: 'Pirata One', serif; font-size: 19px; color: #f3e2b8; text-shadow: 0 2px 4px #000; }
#incl .label.warn { color: #ff9a6a; animation: pulse2 0.6s ease-in-out infinite; }
@keyframes pulse2 { 50% { opacity: 0.6; } }

#power { position: absolute; right: 40px; bottom: 180px; width: 44px; text-align: center; opacity: 0; transition: opacity 0.2s; }
#power.active { opacity: 1; }
#power .track { height: 200px; width: 26px; margin: 0 auto; border-radius: 14px; border: 3px solid #b98a34; background: rgba(10,6,4,0.7); position: relative; overflow: hidden;
  box-shadow: 0 0 0 2px #3a2312, 0 6px 16px rgba(0,0,0,0.7); }
#power-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: linear-gradient(0deg, #f1c35a, #f07a28 60%, #c01c10); box-shadow: 0 0 16px #f07a28; }
#power .label { font-family: 'Pirata One', serif; color: #f3e2b8; text-shadow: 0 2px 4px #000; margin-top: 4px; }

#hint { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); font-size: 17px; color: #f3e2b8; text-shadow: 0 2px 6px #000, 0 0 2px #000; white-space: nowrap; }
#hint b { color: var(--gold); font-weight: normal; font-family: 'IM Fell English SC', serif; }
#mute { pointer-events: auto; position: absolute; top: 120px; right: 22px; width: 38px; height: 38px; border-radius: 50%; border: 2px solid #b98a34; background: rgba(20,12,6,0.7);
  color: var(--gold); font-size: 18px; cursor: pointer; }
#topview { pointer-events: auto; position: absolute; top: 166px; right: 22px; width: 38px; height: 38px; border-radius: 50%; border: 2px solid #b98a34; background: rgba(20,12,6,0.7);
  color: var(--gold); font-size: 18px; cursor: pointer; }
#lever { display: none; pointer-events: auto; touch-action: none; position: absolute; right: 14px; top: 50%; transform: translateY(-50%); width: 64px; text-align: center; opacity: 0.45; transition: opacity 0.2s; }
#lever.ready { opacity: 1; }
#lever .track { position: relative; height: 38vh; min-height: 150px; width: 30px; margin: 0 auto; border-radius: 16px; border: 3px solid #b98a34; background: rgba(10,6,4,0.75);
  box-shadow: 0 0 0 2px #3a2312, 0 6px 16px rgba(0,0,0,0.7); }
#lever-fill { position: absolute; left: 0; right: 0; top: 0; height: 0; border-radius: 12px; background: linear-gradient(180deg, #f1c35a, #f07a28 60%, #c01c10); }
#lever-knob { position: absolute; left: 50%; top: 0; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%; border: 3px solid #2a150a;
  background: radial-gradient(circle at 35% 30%, #fff1c2, #d4a441 45%, #7a4f18); box-shadow: 0 4px 10px rgba(0,0,0,0.7); }
#lever .label { font-family: 'Pirata One', serif; color: #f3e2b8; text-shadow: 0 2px 4px #000; margin-top: 10px; font-size: 15px; line-height: 1.05; }
body.touch #lever { display: block; }
body.touch #power { display: none; }
.touch-help { display: none; }
body.touch .touch-help { display: block; }
body.touch .howto ul:not(.touch-help) { display: none; }
#mute.off { color: #666; text-decoration: line-through; }

#gameover { position: fixed; inset: 0; display: grid; place-items: center; z-index: 15; background: radial-gradient(circle, rgba(0,0,0,0.25), rgba(0,0,0,0.8)); animation: fade 0.8s both; }
@keyframes fade { from { opacity: 0; } }
.go-inner { text-align: center; padding: 30px 50px; }
#go-title { font-family: 'Pirata One', serif; font-weight: 400; font-size: clamp(70px, 11vw, 130px); margin: 0;
  background: linear-gradient(180deg, #fff1c2, #f1c35a 45%, #a0661c); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 #3a1a08) drop-shadow(0 10px 24px rgba(0,0,0,0.8)); }
#gameover.lose #go-title { background: linear-gradient(180deg, #ffd0c0, #d0402a 50%, #6a0e06); -webkit-background-clip: text; background-clip: text; }
#go-text { font-size: 24px; font-style: italic; margin: 6px 0 28px; text-shadow: 0 2px 8px #000; }

@media (max-width: 760px) {
  .card { min-width: 0; padding: 6px 10px; }
  .card .name { font-size: 20px; }
  .chip { width: 16px; height: 16px; }
  #swell { transform: scale(0.8); transform-origin: bottom left; }
  #incl { transform: scale(0.7); transform-origin: bottom right; }
  #lever .track { height: 30vh; }
  #hint { font-size: 13px; white-space: normal; width: 90vw; text-align: center; bottom: 150px; }
  .howto ul { columns: 1; }
}
