:root {
  --bg: #171313;
  --panel: #241d1b;
  --panel2: #332724;
  --ink: #f7efe6;
  --muted: #c7b8aa;
  --accent: #caa55a;
  --danger: #db6666;
  --good: #7cc995;
  --river: #7e2020;
  --line: rgba(255,255,255,.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body { min-height: 100dvh; }
button, input, select { font: inherit; }
button { cursor: pointer; }
#app { min-height: 100dvh; }

.shell { max-width: 980px; margin: 0 auto; padding: 14px 14px calc(18px + env(safe-area-inset-bottom)); }
.brand { text-align: center; padding: 12vh 0 22px; }
.brand h1 { margin: 0; font-family: Georgia, serif; font-size: clamp(2.2rem, 10vw, 4rem); line-height: .95; }
.brand p { color: var(--muted); margin: 12px auto 0; max-width: 500px; }
.card-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 16px; box-shadow: 0 14px 40px rgba(0,0,0,.22); }
.form-grid { display: grid; gap: 12px; }
.form-grid + .form-grid { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
label { display: grid; gap: 6px; color: var(--muted); font-size: .9rem; }
input, select { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 13px; background: #120f0e; color: var(--ink); font-size: 1rem; }
.primary, .secondary, .danger-btn, .choice-btn { border: 0; border-radius: 12px; padding: 12px 14px; font-weight: 750; }
.primary { background: var(--accent); color: #21170b; }
.secondary { background: #4a3933; color: var(--ink); }
.danger-btn { background: #7e2d2d; color: white; }
.choice-btn { background: #4a3933; color: var(--ink); margin: 4px; }
button:disabled { cursor: default; opacity: .45; }

.topbar { position: sticky; top: 0; z-index: 20; margin: -14px -14px 10px; padding: calc(9px + env(safe-area-inset-top)) 14px 9px; background: rgba(23,19,19,.94); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.topbar h1 { font: 700 1.05rem Georgia, serif; margin: 0; }
.room-code { letter-spacing: .16em; font-weight: 900; color: var(--accent); }
.status-dot { font-size: .8rem; color: var(--muted); }

.lobby { padding-top: 18px; }
.lobby-code { font-size: clamp(2.3rem, 14vw, 5rem); letter-spacing: .18em; font-weight: 900; color: var(--accent); text-align: center; margin: 10px 0 18px; }
.player-list { display: grid; gap: 8px; margin: 12px 0 18px; }
.player-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-radius: 12px; background: #181311; }
.lobby-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.scoreboard { display: grid; grid-template-columns: repeat(auto-fit,minmax(145px,1fr)); gap: 8px; margin-bottom: 10px; }
.player-chip { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 9px; min-width: 0; }
.player-chip.active { outline: 2px solid var(--accent); }
.player-chip .name { font-weight: 800; display: flex; justify-content: space-between; gap: 6px; }
.player-chip .meta { color: var(--muted); font-size: .78rem; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.character-icons { display: flex; gap: 5px; margin-top: 7px; }
.character-icon { width: 34px; aspect-ratio: 5/7; object-fit: cover; border-radius: 4px; border: 1px solid rgba(255,255,255,.25); }

.action-panel { background: linear-gradient(145deg,#36291e,#2a201b); border: 1px solid rgba(202,165,90,.4); border-radius: 14px; padding: 11px 12px; margin: 9px 0; }
.action-panel strong { color: var(--accent); }
.action-panel .choices { margin-top: 8px; }
.game-over { font-size: 1.15rem; text-align: center; padding: 16px; }
.game-over.win { border-color: var(--good); }
.game-over.loss { border-color: var(--danger); }

.board { background: var(--river); border-radius: 16px; padding: 12px 8px; overflow: hidden; box-shadow: inset 0 0 35px rgba(0,0,0,.18); }
.board-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 6px 9px; font-size: .86rem; }
.trump { padding: 4px 8px; border-radius: 99px; background: rgba(0,0,0,.22); font-weight: 800; }
.river-scroll { overflow-x: auto; overscroll-behavior-x: contain; padding: 4px 4px 8px; }
.river-track { display: flex; align-items: flex-start; width: max-content; min-width: 100%; min-height: 205px; padding-top: 6px; }
.gap { width: 38px; min-width: 38px; height: 176px; display: grid; place-items: start center; position: relative; }
.gap-button { width: 34px; height: 34px; border-radius: 50%; border: 2px dashed rgba(255,255,255,.9); color: white; background: rgba(0,0,0,.28); font-size: 1.3rem; font-weight: 800; position: absolute; top: 8px; z-index: 3; }
.village { width: 90px; min-width: 90px; min-height: 188px; position: relative; text-align: center; }
.village-stack { width: 90px; height: 170px; position: relative; }
.village-open { position: absolute; z-index: 4; top: 0; left: 4px; width: 82px; border: 0; background: transparent; padding: 0; border-radius: 8px; }
.village-card { width: 82px; aspect-ratio: 5/7; object-fit: cover; border-radius: 8px; box-shadow: 0 7px 12px rgba(0,0,0,.32); border: 1px solid rgba(255,255,255,.25); display: block; }
.boat-card-under, .trump-card-under { position: absolute; left: 4px; width: 82px; aspect-ratio: 5/7; object-fit: cover; border-radius: 8px; box-shadow: 0 7px 12px rgba(0,0,0,.38); border: 1px solid rgba(255,255,255,.3); }
.boat-card-under { top: 24px; z-index: 3; }
.trump-card-under { top: 49px; z-index: 2; outline: 2px solid rgba(202,165,90,.8); outline-offset: -2px; }
.boat-village .village-open { filter: drop-shadow(0 2px 2px rgba(0,0,0,.25)); }
.boat-label, .trump-card-label { position: absolute; z-index: 6; left: 50%; transform: translateX(-50%); padding: 2px 5px; border-radius: 5px; background: rgba(18,15,14,.9); color: white; font-size: .58rem; line-height: 1; font-weight: 900; letter-spacing: .04em; pointer-events: none; }
.boat-label { top: 134px; }
.trump-card-label { top: 158px; color: var(--accent); }
.village-count { position: absolute; right: 1px; top: -7px; min-width: 22px; height: 22px; border-radius: 99px; display: grid; place-items: center; background: #191211; color: white; font-size: .72rem; font-weight: 800; border: 1px solid rgba(255,255,255,.25); }
.stack-btn { position: absolute; left: 6px; right: 6px; bottom: 0; z-index: 8; border: 0; padding: 6px 4px; border-radius: 8px; background: rgba(20,14,10,.9); color: var(--accent); font-weight: 800; font-size: .72rem; }

.trick-area { margin: 10px 0; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px; }
.section-title { margin: 0 0 8px; font-size: .88rem; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.trick-cards { display: flex; justify-content: center; gap: 8px; min-height: 122px; flex-wrap: wrap; }
.played { text-align: center; width: 76px; }
.played img { width: 68px; aspect-ratio: 5/7; border-radius: 7px; object-fit: cover; box-shadow: 0 5px 10px rgba(0,0,0,.35); }
.played .who { font-size: .69rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-trick { color: var(--muted); align-self: center; font-size: .9rem; }

.characters-section { margin: 10px 0; }
.character-row { display: flex; gap: 9px; overflow-x: auto; padding-bottom: 4px; }
.character-tile { min-width: 132px; max-width: 150px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 7px; }
.character-tile img.hero { width: 100%; aspect-ratio: 5/7; object-fit: cover; border-radius: 8px; display: block; }
.character-owner { font-size: .75rem; color: var(--muted); margin: 5px 0 4px; }
.faceup-pile { display: flex; margin-top: 6px; min-height: 44px; }
.faceup-pile img { width: 32px; height: 45px; object-fit: cover; border-radius: 3px; border: 1px solid rgba(255,255,255,.25); margin-left: -10px; }
.faceup-pile img:first-child { margin-left: 0; }
.pile-caption { font-size: .65rem; color: var(--muted); }

.hand-wrap { position: sticky; bottom: 0; z-index: 15; background: linear-gradient(to top, var(--bg) 75%, rgba(23,19,19,0)); padding-top: 15px; padding-bottom: max(4px,env(safe-area-inset-bottom)); }
.hand-head { display: flex; justify-content: space-between; color: var(--muted); font-size: .82rem; padding: 0 3px 5px; }
.hand { display: flex; overflow-x: auto; gap: 5px; padding: 3px 2px 7px; scroll-snap-type: x proximity; }
.hand-card { flex: 0 0 auto; border: 0; padding: 0; background: transparent; border-radius: 8px; scroll-snap-align: center; transition: transform .12s, opacity .12s, filter .12s; }
.hand-card img { display: block; width: clamp(68px, 20vw, 98px); aspect-ratio: 5/7; object-fit: cover; border-radius: 8px; box-shadow: 0 7px 14px rgba(0,0,0,.38); }
.hand-card.legal:hover, .hand-card.legal:active { transform: translateY(-8px); }
.hand-card.illegal { opacity: .34; filter: grayscale(.35); }
.hand-card.legal img { outline: 2px solid rgba(202,165,90,.75); outline-offset: -2px; }
.hand-card.selected { transform: translateY(-11px); }
.hand-card.selected img { outline: 4px solid var(--accent); outline-offset: -4px; box-shadow: 0 10px 22px rgba(0,0,0,.55); }
.play-confirm { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 2px 7px; padding: 8px 9px; border-radius: 11px; background: #2d241e; border: 1px solid rgba(202,165,90,.5); font-size: .82rem; }
.play-confirm > div { display: flex; gap: 6px; }
.small-btn { padding: 7px 9px; min-height: 34px; font-size: .78rem; }
.pending-play { position: relative; opacity: .82; }
.pending-play img { outline: 2px dashed var(--accent); outline-offset: -3px; }
.pending-tag { margin-top: 3px; color: var(--accent); font-size: .55rem; font-weight: 900; letter-spacing: .04em; }

.details { margin: 10px 0 80px; }
details { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
details + details { margin-top: 8px; }
summary { cursor: pointer; color: var(--muted); font-weight: 700; }
.log { margin: 9px 0 0; padding-left: 19px; color: #ded2c8; font-size: .82rem; }
.log li { margin-bottom: 5px; }
.assumptions { color: var(--muted); font-size: .8rem; line-height: 1.45; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(92vw,500px); background: #120f0e; border: 1px solid #a64d4d; color: #ffd7d7; border-radius: 12px; padding: 10px 14px; box-shadow: 0 12px 30px rgba(0,0,0,.5); }
dialog { width: min(92vw,620px); border: 1px solid var(--line); border-radius: 16px; background: #1f1917; color: var(--ink); padding: 14px; }
dialog::backdrop { background: rgba(0,0,0,.7); }
.dialog-close { float: right; background: #493832; color: white; border: 0; border-radius: 8px; padding: 7px 10px; }
.pile-cards { display: flex; flex-wrap: wrap; gap: 7px; clear: both; padding-top: 8px; }
.pile-cards img { width: 88px; aspect-ratio: 5/7; object-fit: cover; border-radius: 7px; }

@media (min-width: 760px) {
  .shell { padding-left: 20px; padding-right: 20px; }
  .game-layout { display: grid; grid-template-columns: minmax(0,1.5fr) minmax(260px,.7fr); gap: 12px; align-items: start; }
  .side-column { position: sticky; top: 64px; }
  .hand-wrap { grid-column: 1 / -1; }
  .details { margin-bottom: 20px; }
}

/* v0.5 compact/resizable play layout */
:root {
  --player-chip-w: 132px;
  --river-card-w: 74px;
  --trick-card-w: 62px;
  --character-card-w: 124px;
  --hand-card-w: 78px;
}

.topbar-right { display: flex; align-items: center; gap: 8px; }
.view-btn { border: 1px solid var(--line); border-radius: 9px; padding: 6px 9px; background: #3a2c27; color: var(--ink); font-size: .76rem; font-weight: 800; }

/* Keep the players in one compact horizontal strip instead of consuming rows. */
.scoreboard { display: flex; overflow-x: auto; overscroll-behavior-x: contain; gap: 7px; margin-bottom: 8px; padding-bottom: 2px; }
.player-chip { flex: 0 0 var(--player-chip-w); padding: 7px 8px; border-radius: 12px; }
.player-chip .name { font-size: .88rem; }
.player-chip .meta { font-size: .7rem; }
.character-icons { gap: 4px; margin-top: 5px; }
.character-icon-btn { border: 0; padding: 0; background: transparent; border-radius: 4px; line-height: 0; }
.character-icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.character-icon { width: clamp(30px, calc(var(--player-chip-w) * .25), 42px); }

/* Compact river. The boat and trump are cropped tabs tucked beneath the village,
   rather than full-height cards extending the board vertically. */
.river-track {
  min-height: calc(var(--river-card-w) * 1.4 + 45px);
  padding-top: 4px;
}
.gap {
  width: clamp(24px, calc(var(--river-card-w) * .42), 38px);
  min-width: clamp(24px, calc(var(--river-card-w) * .42), 38px);
  height: calc(var(--river-card-w) * 1.4 + 38px);
}
.gap-button { width: 32px; height: 32px; font-size: 1.15rem; }
.village {
  width: calc(var(--river-card-w) + 8px);
  min-width: calc(var(--river-card-w) + 8px);
  min-height: calc(var(--river-card-w) * 1.4 + 40px);
}
.village-stack {
  width: calc(var(--river-card-w) + 8px);
  height: calc(var(--river-card-w) * 1.4 + 38px);
}
.village-open { left: 4px; width: var(--river-card-w); }
.village-card { width: var(--river-card-w); }
.boat-card-under, .trump-card-under {
  left: 50%;
  transform: translateX(-50%);
  width: calc(var(--river-card-w) * .72);
  height: clamp(18px, calc(var(--river-card-w) * .31), 30px);
  aspect-ratio: auto;
  object-fit: cover;
  object-position: center 72%;
  border-radius: 5px;
}
.boat-card-under { top: calc(var(--river-card-w) * 1.4 - 7px); }
.trump-card-under { top: calc(var(--river-card-w) * 1.4 + 12px); }
.boat-label, .trump-card-label { font-size: .5rem; padding: 2px 4px; }
.boat-label { top: calc(var(--river-card-w) * 1.4 + 1px); }
.trump-card-label { top: calc(var(--river-card-w) * 1.4 + 20px); }
.village-count { width: 20px; min-width: 20px; height: 20px; font-size: .66rem; }
.stack-btn { font-size: .68rem; padding: 5px 3px; }
.board { padding-top: 9px; padding-bottom: 8px; }
.board-head { padding-bottom: 6px; font-size: .77rem; }
.board .river-scroll + .board-head { padding-top: 2px; padding-bottom: 0; font-size: .68rem; color: rgba(255,255,255,.8); }

/* Independently resizable trick. */
.trick-area { padding: 8px; margin: 8px 0; }
.trick-cards { min-height: calc(var(--trick-card-w) * 1.4 + 23px); gap: 6px; }
.played { width: calc(var(--trick-card-w) + 6px); }
.played img { width: var(--trick-card-w); }
.played .who { font-size: .63rem; }

/* Independently resizable character area. Cards can always be tapped for a full-size view. */
.characters-section { margin: 8px 0; }
.character-row { gap: 7px; }
.character-tile { flex: 0 0 var(--character-card-w); min-width: var(--character-card-w); max-width: none; padding: 6px; }
.hero-button { display: block; width: 100%; border: 0; padding: 0; background: transparent; border-radius: 8px; line-height: 0; }
.hero-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.character-tile img.hero { width: 100%; }
.character-owner { font-size: .7rem; margin: 4px 0 3px; }
.character-power {
  color: #e3d8ce;
  font-size: .67rem;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.faceup-pile { margin-top: 4px; min-height: 38px; }
.faceup-pile img { width: 27px; height: 38px; }
.pile-caption { font-size: .6rem; margin-top: 4px; }

/* Independently resizable hand. */
.hand-card img { width: var(--hand-card-w); }
.hand { gap: 4px; padding-bottom: 5px; }
.hand-wrap { padding-top: 11px; }

/* Display-size controls and readable character power view. */
.view-dialog { width: min(92vw, 520px); }
.dialog-help { color: var(--muted); font-size: .82rem; margin-top: -3px; }
.view-controls { display: grid; gap: 12px; clear: both; margin: 12px 0 16px; }
.view-control { display: grid; grid-template-columns: 1fr auto; gap: 5px 10px; color: var(--ink); }
.view-control output { color: var(--accent); font-weight: 800; font-size: .78rem; }
.view-control input[type="range"] { grid-column: 1 / -1; padding: 0; accent-color: var(--accent); }
.character-dialog { width: min(94vw, 440px); }
.character-dialog-image { display: block; width: min(82vw, 340px); max-height: 64dvh; object-fit: contain; border-radius: 10px; margin: 8px auto 12px; }
.character-dialog-power { clear: both; font-size: 1rem; line-height: 1.45; margin: 0; color: var(--ink); }

@media (min-width: 760px) {
  .scoreboard { display: grid; grid-template-columns: repeat(auto-fit,minmax(var(--player-chip-w),1fr)); overflow: visible; }
}
