:root {
  --bg: #efece4;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #66625a;
  --line: #d9d4c8;
  --accent: #1a4f8b;
  --accent-ink: #ffffff;
  --up: #1b7a2b;
  --down: #b00020;
  --highlight: #fff1a8;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; overflow-x: hidden; }
.panel { min-width: 0; }
[hidden] { display: none !important; }

h1, h2, h3, h4 { margin: 0; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .5rem; }

button, select, input { font: inherit; color: inherit; }
button {
  background: #f7f5ef; border: 1px solid #c9c3b4; border-radius: 8px;
  padding: .5rem .8rem; cursor: pointer; transition: background .15s, border-color .15s;
}
button:hover:not(:disabled) { background: #ece8dd; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover:not(:disabled) { background: #15406f; }
button.big { padding: .7rem 1.3rem; font-size: 1rem; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid #7aa7e0; outline-offset: 1px; }
select, input[type=number], input[type=text] {
  border: 1px solid #c9c3b4; border-radius: 8px; padding: .45rem .55rem; background: #fff;
}
kbd {
  font-family: inherit; font-size: .72em; border: 1px solid currentColor; border-radius: 4px;
  padding: 0 .3em; opacity: .7; margin-left: .3em;
}

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; }
.hint { color: var(--muted); font-size: .85rem; margin: .4rem 0 0; }
.center { text-align: center; }
.error { color: var(--down); font-size: .88rem; min-height: 1.1em; margin: .4rem 0 0; }
.error:empty { min-height: 0; margin: 0; }

/* ------------------------------------------------------------ Start */
.setup { max-width: 720px; margin: 0 auto; padding: 2rem 1rem 3rem; display: grid; gap: 1rem; }
.logo { text-align: center; font-size: clamp(2rem, 7vw, 3.2rem); letter-spacing: .08em; font-weight: 800; }
.subtitle { text-align: center; color: var(--muted); margin: -.6rem 0 .4rem; }
.inline { display: inline-flex; align-items: center; gap: .5rem; }
.player-rows { display: grid; gap: .5rem; margin-top: .8rem; }
.player-row { display: grid; grid-template-columns: 5.5rem 1fr auto; gap: .6rem; align-items: center; }
.player-row input[type=text] { width: 100%; }
.check { display: flex; gap: .5rem; align-items: flex-start; }
.range { display: grid; gap: .3rem; margin-top: .9rem; }
.range-row { display: flex; gap: .6rem; align-items: center; }
.range-row input { flex: 1; max-width: 280px; }
.setup-actions { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: center; }

/* ------------------------------------------------------------ Spiel */
.game { padding: .8rem 1rem 1.2rem; max-width: 1400px; margin: 0 auto; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.2rem; margin-bottom: .8rem; }
.topbar h1 { font-size: 1.35rem; flex: 1 1 auto; }
.deck { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--muted); }
.deck progress { width: 140px; height: .7rem; accent-color: var(--accent); }
.top-buttons { display: flex; gap: .4rem; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: .9rem; align-items: start; }
.col-main, .col-side { display: grid; gap: .9rem; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  border-top-width: 6px; padding: .55rem .75rem .6rem; cursor: pointer; text-align: left;
  display: grid; gap: .1rem; transition: box-shadow .15s;
}
.tile:hover { box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.tile.selected { box-shadow: 0 0 0 2px var(--accent) inset; }
.tile .name { font-weight: 700; font-size: .95rem; }
.tile .price { font-size: clamp(1.3rem, 2.6vw, 1.9rem); font-weight: 800; font-variant-numeric: tabular-nums; }
.tile .delta { font-size: .82rem; font-weight: 700; color: #888; }
.tile .delta.up { color: var(--up); }
.tile .delta.down { color: var(--down); }
.tile .bank { font-size: .75rem; color: var(--muted); }
.tile.flash { animation: flash .9s ease-out; }
@keyframes flash { from { background: #fff6c2; } to { background: var(--panel); } }

#chart { width: 100%; height: 170px; display: block; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .92rem; }
th, td { padding: .35rem .5rem; border-bottom: 1px solid #eee9de; white-space: nowrap; }
th { font-size: .75rem; color: var(--muted); text-align: right; font-weight: 600; }
td { text-align: right; }
th:first-child, td:first-child { text-align: left; }
tr.current td { background: var(--highlight); font-weight: 600; }
td .cpu { color: var(--muted); font-weight: 400; font-size: .8em; }

.log { height: 220px; overflow-y: auto; font-size: .88rem; line-height: 1.45; background: #fbfaf6; border-radius: 6px; padding: .4rem .6rem; }
.log div { white-space: pre-wrap; }
.log .turn { color: var(--accent); font-weight: 700; margin-top: .5rem; }
.log .phase { color: #7a1f1f; font-weight: 700; }
.log .risk { color: #b35c00; font-weight: 700; }
.log .play { font-weight: 700; }
.log .up { color: var(--up); }
.log .down { color: var(--down); }
.log .money { color: var(--muted); }
.log .trade { color: #5b2a86; }

.phase-hint { margin: 0 0 .7rem; white-space: pre-line; line-height: 1.4; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.trade-row { display: flex; gap: .5rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.trade-row select { flex: 1 1 140px; }
.trade-row input { width: 4.5rem; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin-top: .6rem; }
#trade-info { white-space: pre-line; }

.hand { display: grid; gap: .4rem; }
.card {
  display: flex; gap: .6rem; align-items: center; text-align: left; width: 100%;
  border-radius: 8px; padding: .55rem .7rem; border: 1px solid rgba(0,0,0,.15);
  box-shadow: 0 1px 0 rgba(0,0,0,.06);
}
.card .no { font-weight: 800; opacity: .55; min-width: 1em; }
.card .txt { flex: 1; }
.card .new { font-size: .75rem; font-weight: 700; color: var(--accent); white-space: nowrap; }
.card:disabled { opacity: .8; cursor: default; }
.card:not(:disabled):hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0,0,0,.12); }
.k-up_down { background: #fff4cc; }   .k-up_down:hover:not(:disabled) { background: #ffeeb0; }
.k-up_all { background: #ffe9b3; }    .k-up_all:hover:not(:disabled) { background: #ffe199; }
.k-any_up { background: #dcefd8; }    .k-any_up:hover:not(:disabled) { background: #cbe7c5; }
.k-double { background: #c8e6c9; }    .k-double:hover:not(:disabled) { background: #b4dcb6; }
.k-any_down { background: #f8d7da; }  .k-any_down:hover:not(:disabled) { background: #f3c4c9; }
.k-half { background: #f3c1c6; }     .k-half:hover:not(:disabled) { background: #eeadb4; }

/* ------------------------------------------------------------ Dialoge */
dialog {
  border: none; border-radius: 14px; padding: 1.2rem 1.3rem; max-width: min(560px, 94vw);
  box-shadow: 0 20px 60px rgba(0,0,0,.3); color: var(--ink);
}
dialog::backdrop { background: rgba(20, 22, 26, .45); }
dialog h3 { margin-bottom: .8rem; font-size: 1.1rem; line-height: 1.35; white-space: pre-line; }
.dialog-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
.choice-buttons { display: grid; gap: .4rem; }
.choice-buttons button { display: flex; justify-content: space-between; gap: 1rem; text-align: left; }
.choice-buttons button small { color: var(--muted); }
.result-list { margin: 0; padding-left: 1.4rem; line-height: 1.8; font-variant-numeric: tabular-nums; }
.rules { max-height: 88vh; overflow-y: auto; }
.rules h4 { margin: 1rem 0 .3rem; }
.rules p, .rules li { line-height: 1.45; }
.rules ul, .rules ol { padding-left: 1.3rem; margin: .2rem 0; }

.cover {
  position: fixed; inset: 0; background: rgba(26, 79, 139, .96); color: #fff;
  display: grid; place-items: center; z-index: 50; padding: 1rem;
}
.cover-box { text-align: center; }
.cover-box p { font-size: 1.5rem; font-weight: 700; margin: 0 0 1.2rem; }
.cover .primary { background: #fff; color: var(--accent); }
.cover .primary:hover { background: #e8eef7; }

/* ------------------------------------------------------------ Schmale Bildschirme */
@media (max-width: 900px) {
  .layout { display: flex; flex-direction: column; align-items: stretch; }
  .col-main, .col-side { display: contents; }
  .layout .panel, .layout .tiles { width: 100%; min-width: 0; }
  .panel-tiles { order: 1; }
  .p-turn { order: 2; }
  .p-hand { order: 3; }
  .p-trade { order: 4; }
  .p-chart { order: 5; }
  .p-players { order: 6; }
  .p-log { order: 7; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar h1 { font-size: 1.1rem; flex-basis: 100%; }
  kbd { display: none; }
}
@media (max-width: 420px) {
  .player-row { grid-template-columns: 1fr auto; }
  .player-row .lbl { display: none; }
}
