:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, sans-serif;
  color: #30291e;
  background: #eee1c8;
  --ink: #30291e;
  --soft: #eee0be;
  --table: #795231;
  --edge: #aa8555;
  --accent: #704221;
  --paper: #fffaf0;
}
* { box-sizing: border-box; }
body { margin: 0; }
main { max-width: 1152px; margin: auto; padding: 18px; }
header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  min-height: 60px; padding: 10px 14px; border-radius: 12px; background: var(--paper);
  border: 1px solid var(--edge);
}
header h1 { font-size: 1.65rem; line-height: 1.1; margin: 0; }
header p { margin: .25rem 0 0; }
header .actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
#sound-toggle { background: #e8d3a9; border: 2px solid #704221; font-weight: 750; }
#sound-toggle[aria-pressed="false"] { background: var(--paper); }
h2 { font-size: 1.05rem; margin: 0 0 8px; }
p { margin: .5rem 0; }
button, input, select { font: inherit; }
button {
  background: var(--paper); color: var(--ink); border: 1px solid var(--accent);
  border-radius: 7px; padding: .45rem .65rem; min-height: 38px; cursor: pointer;
  touch-action: manipulation;
}
button:hover:not(:disabled) { background: #f5e6ca; }
button:disabled { opacity: .6; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid #073965; outline-offset: 3px;
}
#notice button { color: white; background: var(--accent); }
input, select { background: white; color: var(--ink); padding: 7px; border: 1px solid var(--edge); border-radius: 6px; max-width: 100%; }
label { display: block; }
.buttons { display: flex; flex-wrap: wrap; gap: 7px; margin: 6px 0; }
.panel, .status { background: var(--paper); border: 1px solid var(--edge); border-radius: 10px; padding: 12px; margin-top: 10px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#error:empty, #game-controls:empty { display: none; }
#error { color: #842d16; font-weight: 650; }
#connection { color: #703b17; background: #fff4d9; padding: 6px; border-radius: 6px; font-size: .88rem; }
#home, #lobby, #bidding, #board, #series-ledger, #result { width: 100%; min-width: 0; }
#home > .panel { width: 100%; }
#name, #invitation { width: min(100%, 340px); margin: 4px 0; }
.start-screen { display: grid; gap: 12px; margin-top: 12px; }
.hero { position: relative; min-height: clamp(240px, 42vh, 420px); overflow: hidden;
  display: flex; align-items: end; border: 5px solid #684524; border-radius: 16px;
  background: linear-gradient(90deg, #261707d9 0%, #271b0e88 52%, #271b0e19 100%),
    url('art/biergarten-herbst.png') center / cover;
  box-shadow: inset 0 0 0 2px #c09961, 0 5px 16px #39250d44; }
.hero-copy { padding: clamp(20px,4vw,48px); color: #fff8e8; text-shadow: 0 2px 6px #140b07; }
.hero h2 { font-size: clamp(2.6rem,7vw,5.4rem); line-height: 1; margin: 7px 0; }
.hero p { font-size: clamp(1rem,2vw,1.35rem); }
.eyebrow { text-transform: uppercase; letter-spacing: .13em; font-weight: 750; font-size: .75rem; }
.entry-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.entry-actions button { min-height: 52px; text-align: left; padding: 11px 15px; font-weight: 750; }
.entry-actions button span { display: block; font-size: .8rem; font-weight: 450; margin-top: 3px; }
.primary-action { background: #72411f; color: #fff8e8; border-color: #4a2d18; font-weight: 750; }
.primary-action:hover:not(:disabled) { background: #8d552b; }
#series-form, #join-form { max-width: 760px; margin: 12px auto 0; padding: clamp(16px,3vw,30px); }
#series-form h2, #join-form h2 { font-size: clamp(1.5rem,3vw,2rem); margin: 8px 0; }
.step-heading { display: flex; align-items: center; gap: 12px; }
.step-heading button { min-height: 32px; }
.setup-fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; margin: 18px 0; }
.setup-fields label, #rules-step > label, #join-form > label { font-weight: 650; }
.setup-fields input:not([type=checkbox]), .setup-fields select, #rules-step select,
  #join-form input { display: block; width: 100%; margin-top: 5px; }
.setup-fields .check-label { align-self: end; min-height: 38px; display: flex; align-items: center; gap: 7px; }
.setup-summary { background: #f3e5c9; border: 1px solid var(--edge); border-radius: 9px;
  padding: 10px 12px; margin: 12px 0; }
#rules-step fieldset { border: 1px solid var(--edge); border-radius: 9px; margin: 12px 0; }
#rules-step fieldset label { display: inline-flex; gap: 4px; align-items: center; margin: 5px 12px 5px 0; }
#rules-step #series-tariff { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; }
#rules-step #series-tariff.hidden { display: none; }
#rules-step #series-tariff input { width: 7rem; }
#join-form > label { display: block; margin: 12px 0; }
#seating { display: grid; grid-template-columns: repeat(auto-fit,minmax(170px,1fr)); gap: 8px; }
.settings-seat { background: #f5ecd9; padding: 10px; border: 1px solid var(--edge); border-radius: 8px; overflow-wrap: anywhere; }
.settings-seat label { margin-top: 6px; }
.settings-seat select { display: block; width: 100%; }
.settings-seat p { font-size: .85rem; }
.status { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px 8px; align-items: center; }
.status > div { flex: 1; min-width: 0; font-size: .78rem; }
.status strong { display: block; font-size: .94rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status .called-ace { grid-column: 1 / -1; width: fit-content; max-width: 100%; padding: 3px 8px;
  border: 1px solid #356b9e; border-radius: 6px; background: #e8f4ff; color: #123954;
  font-size: .92rem; font-weight: 750; }
.table {
  height: clamp(340px,52vh,470px);
  background: linear-gradient(#291b0f55,#291b0f55), url('art/biergarten-herbst.png') center / cover,
    var(--table); display: grid;
  grid-template-columns: minmax(0,1fr) minmax(132px,2fr) minmax(0,1fr);
  grid-template-rows: auto minmax(0,1fr) auto; align-items: center; gap: 5px;
  border: 5px solid #684524; box-shadow: inset 0 0 0 2px #c09961, 0 4px 12px #39250d44;
}
.seat {
  padding: 5px; border-radius: 8px; text-align: center; background: #fff5dded;
  font-size: .87rem; line-height: 1.16; min-width: 0; overflow-wrap: anywhere;
  position: relative; z-index: 1; border: 1px solid #a87b49;
}
.seat.active { color: white; background: var(--accent); outline: 2px solid #093967; font-weight: 700; }
.seat.winner { background: #fff3cc; outline: 2px solid #8a5b11; font-weight: 700; }
.seat small { display: block; font-size: .88em; }
.seat-identity { display: flex; align-items: center; justify-content: center; gap: 5px; }
.seat-identity strong { min-width: 0; }
.avatar { width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%;
  border: 2px solid #855b2f; box-shadow: 0 1px 3px #24160788; }
.avatar-heiner, .avatar-walter, .avatar-alfred, .avatar-papa {
  background-image: url('art/bot-portraits.png'); background-size: 200% 200%;
}
.avatar-heiner { background-position: left top; }
.avatar-walter { background-position: right top; }
.avatar-alfred { background-position: left bottom; }
.avatar-papa { background-position: right bottom; }
.avatar-human { background: #825e3f; color: #fff4d8; display: grid; place-items: center; font-size: 1.3rem; }
.speech-bubble { display: block; position: absolute; z-index: 4; left: 50%; bottom: calc(100% + 3px);
  transform: translateX(-50%); min-width: min(160px, 42vw); max-width: min(230px, 55vw);
  padding: 5px 8px; background: #fffdf5; color: #30291e; border: 2px solid #875a31;
  border-radius: 10px; box-shadow: 0 2px 6px #24160799; font-size: .82rem; font-weight: 650;
  line-height: 1.15; pointer-events: none; }
.north .speech-bubble { bottom: auto; top: calc(100% + 3px); }
.table .speech-bubble, .bid-seats .speech-bubble { position: static; transform: none;
  min-width: 0; max-width: none; box-shadow: none; margin-top: 3px; }
.bid-seats { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 5px; margin: 8px 0; }
.north { grid-area: 1 / 2; }
.west { grid-area: 2 / 1; }
.east { grid-area: 2 / 3; }
.south { grid-area: 3 / 2; }
#trick {
  grid-area: 2 / 2; display: grid; grid-template-columns: repeat(3,minmax(0,1fr));
  grid-template-rows: repeat(3,minmax(0,1fr)); height: 100%; align-items: center; justify-items: center;
}
.trick-slot { display: grid; place-items: center; min-width: 0; min-height: 0; }
.trick-slot small { display: none; }
.position-2 { grid-area: 1 / 2; align-self: start; }
.position-1 { grid-area: 2 / 1; }
.position-3 { grid-area: 2 / 3; }
.position-0 { grid-area: 3 / 2; align-self: end; }
.card {
  padding: 0; min-height: 0; display: block; overflow: hidden; background: white;
  border: 1px solid #7d8fa1; border-radius: 6px; box-shadow: 0 2px 3px #183c5b20;
}
.card img { display: block; width: 100%; height: auto; user-select: none; pointer-events: none; }
.card.legal { outline: 2px solid #07508a; outline-offset: 1px; border-color: #07508a; }
.card.legal:hover { outline-width: 3px; }
.played .card { width: clamp(50px,11vh,100px); }
.played.winner .card { outline: 2px solid #8a5b11; outline-offset: 1px; }
#trick.collecting .played { animation: collect-trick .42s ease-in var(--collect-delay, 1550ms) both; }
@keyframes collect-trick { to { transform: translate(var(--collect-x), var(--collect-y)) scale(.55); opacity: .45; } }
@media (prefers-reduced-motion: reduce) {
  #trick.collecting .played { animation: none; }
}
#hand { min-height: 0; background: var(--soft); }
#cards {
  display: grid; grid-template-columns: repeat(8,minmax(0,1fr)); gap: 7px;
  justify-items: center; align-items: center;
}
#cards .card { width: 100%; max-width: 66px; }
#bid-cards { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 5px; }
#bid-cards .card { width: 100%; max-width: 66px; }
#bidding { min-width: 0; }
#bidding .buttons button { min-height: 38px; }
.bid-actions { display: grid; justify-items: start; }
.bid-kinds, .bid-modes { width: 100%; }
.bid-kinds button[aria-pressed="true"], .bid-ace[aria-pressed="true"] {
  background: #d7edff; outline: 2px solid #073965;
}
.bid-selection { width: 100%; }
.bid-suits { display: flex; flex-wrap: wrap; gap: 8px; }
.bid-ace { display: grid; justify-items: center; gap: 2px; padding: 5px; min-width: 72px; }
.bid-ace img { display: block; width: 46px; height: auto; border-radius: 4px; }
.bid-ace span { font-size: .75rem; }
#notice { background: #fff8e6; }
#notice button { margin-left: 8px; }
#history-panel summary { cursor: pointer; }
#history div { padding: .25rem 0; border-top: 1px solid var(--soft); font-size: .85rem; }
#series-form label, #series-tariff label { display: block; margin: .4rem 0; }
#series-form input[type="number"] { width: 7rem; }
#series-ledger { overflow-x: auto; }
#series-ledger table { width: 100%; border-collapse: collapse; font-size: .88rem; }
#series-ledger th, #series-ledger td { border-bottom: 1px solid #d5dfe6; padding: .4rem; text-align: left; }
#series-ledger tr:has(td[colspan]) td { font-size: .78rem; color: #43515a; }
@media (orientation:portrait) and (max-width:620px) {
  main { padding: 10px; }
  .hero { min-height: 250px; }
  .entry-actions, .setup-fields { grid-template-columns: 1fr; }
  .entry-actions button { min-height: 54px; }
  #rules-step #series-tariff { grid-template-columns: 1fr; }
  .table { grid-template-columns: minmax(0,1fr) minmax(190px,2.4fr) minmax(0,1fr); height: 310px; }
  .played .card { width: 48px; }
  #cards { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .seat { font-size: .74rem; }
  .avatar { width: 28px; height: 28px; flex-basis: 28px; }
  .west .seat-identity, .east .seat-identity { flex-direction: column; }
  .west .seat-identity strong, .east .seat-identity strong { overflow-wrap: normal; }
  .west small, .east small { display: none; }
  .bid-seats { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (orientation:landscape) and (max-height:520px) {
  main:not(.playing) { padding: 8px; }
  main:not(.playing) header { min-height: 42px; padding: 4px 10px; }
  main:not(.playing) header h1 { font-size: 1.15rem; }
  main:not(.playing) header p { display: none; }
  .start-screen { grid-template-columns: minmax(0,1fr) minmax(230px, .7fr); }
  .hero { min-height: 178px; }
  .hero-copy { padding: 14px; }
  .hero h2 { font-size: 2rem; }
  .hero p { font-size: .85rem; }
  .entry-actions { grid-template-columns: 1fr; align-content: start; }
  .entry-actions button { min-height: 40px; padding: 5px 10px; }
  .entry-actions button span { font-size: .72rem; }
  #series-form, #join-form { max-width: 100%; }
}
@media (orientation:landscape) and (max-height:520px) {
  main.playing {
    height: 100vh; height: 100dvh; display: grid; grid-template-rows: 28px minmax(0,1fr);
    gap: 4px; max-width: none; overflow: hidden; position: relative;
    padding: max(4px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(5px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  .playing header { min-height: 0; padding: 2px 6px; }
  .playing header h1 { font-size: 1rem; }
  .playing header p { display: none; }
  .playing header button { font-size: .75rem; min-height: 23px; padding: 1px 5px; }
  .playing #sound-toggle { min-width: 90px; }
  .playing #series-ledger { display: none; }
  .playing #error { position: absolute; z-index: 1; top: 26px; right: 12px; background: #fff8e6; }
  .playing #board {
    display: grid; min-height: 0; min-width: 0; gap: 5px;
    grid-template-columns: minmax(0,1fr) minmax(172px,28%);
    grid-template-rows: 33px minmax(0,1fr) clamp(70px,24dvh,111px);
    grid-template-areas: "status status" "table controls" "hand hand";
  }
  .playing #board.called-ace-game { grid-template-rows: 52px minmax(0,1fr) clamp(70px,24dvh,111px); }
  .playing #board.called-ace-game .status { row-gap: 0; }
  .playing #board .panel, .playing .status { margin: 0; padding: 4px 6px; }
  .playing .status { grid-area: status; }
  .playing .status > div { font-size: .66rem; }
  .playing .status strong { font-size: .80rem; }
  .playing .status .called-ace { font-size: .72rem; padding: 1px 5px; }
  .playing .table {
    grid-area: table; height: auto; width: 100%; min-height: 0;
    grid-template-columns: minmax(0,1fr) minmax(100px,1.75fr) minmax(0,1fr);
    gap: 3px;
  }
  .playing #trick {
    display: block; position: relative;
  }
  .playing #trick .trick-slot {
    position: absolute; top: 0; width: 25%; height: 100%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
  }
  .playing #trick .trick-slot small { display: block; font-size: 9px; line-height: 1; }
  .playing #trick .position-0 { left: 0; }
  .playing #trick .position-1 { left: 25%; }
  .playing #trick .position-2 { left: 50%; }
  .playing #trick .position-3 { left: 75%; }
  .playing .seat { padding: 3px 4px; font-size: .70rem; }
  .playing .seat small { display: none; }
  .playing .avatar { width: 24px; height: 24px; flex-basis: 24px; }
  .playing .speech-bubble { min-width: 110px; max-width: 155px; font-size: .68rem;
    padding: 3px 5px; }
  .playing #game-controls { grid-area: controls; overflow-wrap: anywhere; align-self: stretch;
    min-height: 0; overflow-y: auto; }
  .playing #bidding { margin: 0; padding: 4px 6px; font-size: .73rem; }
  .playing #bidding p { margin: 3px 0; }
  .playing #bidding h2 { font-size: .85rem; margin-bottom: 3px; }
  .playing #bidding .buttons button { min-height: 32px; padding: 3px 5px; }
  .playing #chooser h2 { font-size: .84rem; margin: 0; }
  .playing #chooser p, .playing #notice p { margin: 3px 0; font-size: .74rem; }
  .playing #suits { display: grid; grid-template-columns: repeat(2,1fr); gap: 3px; margin: 3px 0 0; }
  .playing #suits button { min-height: 33px; padding: 2px 4px; }
  .playing #notice strong { font-size: .81rem; }
  .playing #notice button { margin: 3px 0 0; min-height: 38px; padding: 4px; font-size: .79rem; }
  .playing #connection { font-size: .73rem; margin: 0 0 3px; }
  .playing #hand { grid-area: hand; min-height: 0; }
  .playing #cards { height: 100%; grid-template-columns: repeat(8,minmax(0,1fr)); gap: 4px; }
  .playing #cards .card { height: 100%; width: auto; max-width: 100%; aspect-ratio: 3/5; }
  .playing #cards img { height: 100%; width: 100%; object-fit: contain; }
  .playing .played .card { width: clamp(34px,14dvh,52px); }
  .playing #history-panel { display: none; }
}

@media (min-height:521px) and (max-height:800px) {
  main { padding-block: 10px; }
  header { min-height: 48px; padding-block: 6px; }
  .table { height: clamp(280px,44vh,360px); }
  #cards .card, #bid-cards .card { max-width: 64px; }
  .played .card { width: clamp(48px,10vh,78px); }
}
@media (min-height:700px) and (max-height:800px) {
  .table { height: clamp(385px,55vh,430px); }
  .played .card { width: 96px; }
}
