:root {
  --win-gray: #c0c0c0;
  --win-light: #ffffff;
  --win-mid: #dfdfdf;
  --win-dark: #808080;
  --win-black: #111111;
  --win-blue: #000080;
  --felt: #087767;
  --felt-dark: #04594d;
  --cream: #fffdf1;
  --red: #b31325;
  --shadow: rgba(0, 30, 25, 0.38);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: #111;
  font-family: Tahoma, "MS Sans Serif", Arial, sans-serif;
  font-size: 14px;
  background:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,.06) 0 1px, transparent 2px),
    radial-gradient(circle at 75% 80%, rgba(0,0,0,.06) 0 1px, transparent 2px),
    linear-gradient(145deg, var(--felt), var(--felt-dark));
  background-size: 9px 9px, 13px 13px, auto;
}

button, input, select, textarea { font: inherit; }
button { color: #111; }

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px dotted #111;
  outline-offset: 2px;
}

.desktop {
  min-height: 100vh;
  padding: 22px;
  display: grid;
  place-items: center;
}

.desktop.game-desktop { display: block; padding: 12px; }

.window {
  background: var(--win-gray);
  border: 2px solid;
  border-color: var(--win-light) var(--win-black) var(--win-black) var(--win-light);
  box-shadow: 4px 5px 0 rgba(0, 0, 0, .3);
}

.home-window { width: min(760px, 100%); }
.join-window { width: min(470px, 100%); }

.titlebar {
  min-height: 31px;
  margin: 2px;
  padding: 4px 5px 4px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: white;
  font-weight: 700;
  letter-spacing: .15px;
  background: linear-gradient(90deg, #000080, #1084d0);
}

.titlebar-icon {
  width: 19px;
  height: 19px;
  display: grid;
  place-items: center;
  color: #111;
  font-size: 12px;
  background: white;
  border: 1px solid #ddd;
}

.titlebar-text { flex: 1; }

.window-controls { display: flex; gap: 3px; }
.window-control {
  width: 22px;
  height: 20px;
  padding: 0;
  display: grid;
  place-items: center;
  font-weight: 900;
  line-height: 1;
  background: var(--win-gray);
  border: 2px solid;
  border-color: #fff #333 #333 #fff;
}

.menubar {
  min-height: 28px;
  padding: 4px 10px;
  display: flex;
  align-items: center;
  gap: 20px;
  border-bottom: 1px solid var(--win-dark);
}

.menubar span::first-letter { text-decoration: underline; }

.hero {
  min-height: 455px;
  padding: 42px 44px 38px;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(260px, .9fr);
  align-items: center;
  gap: 44px;
  background:
    linear-gradient(rgba(4,92,78,.92), rgba(3,82,70,.96)),
    repeating-linear-gradient(45deg, rgba(255,255,255,.05) 0 1px, transparent 1px 6px);
  border: 2px solid;
  border-color: #777 #fff #fff #777;
}

.brand-kicker {
  margin: 0 0 11px;
  color: #d1f0e6;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.7px;
  font-size: 11px;
}

.hero h1 {
  max-width: 470px;
  margin: 0;
  color: var(--cream);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(43px, 7vw, 72px);
  line-height: .92;
  letter-spacing: -2.8px;
  text-shadow: 3px 3px 0 #033e36;
}

.hero-copy {
  max-width: 460px;
  margin: 20px 0 0;
  color: #e8fff7;
  font-size: 16px;
  line-height: 1.55;
}

.suit-line {
  margin-top: 26px;
  display: flex;
  gap: 13px;
  font-family: Georgia, serif;
  font-size: 25px;
  color: #fff;
}
.suit-line .red { color: #ffb3b3; }

.dialog-panel {
  padding: 18px;
  background: var(--win-gray);
  border: 2px solid;
  border-color: #fff #555 #555 #fff;
  box-shadow: 5px 6px 0 rgba(0,0,0,.23);
}

.dialog-panel h2 { margin: 0 0 5px; font-size: 18px; }
.dialog-help { margin: 0 0 18px; color: #333; line-height: 1.4; }

.form-field { display: block; margin-bottom: 15px; }
.form-field > span { display: block; margin-bottom: 6px; }
.required { color: #880000; }

.win-input, .win-select, .win-textarea {
  width: 100%;
  padding: 9px 10px;
  color: #111;
  background: #fff;
  border: 2px solid;
  border-color: #555 #fff #fff #555;
  border-radius: 0;
}

.win-textarea { min-height: 82px; resize: vertical; line-height: 1.4; }

.win-button {
  min-height: 36px;
  padding: 7px 17px;
  background: var(--win-gray);
  border: 2px solid;
  border-color: #fff #222 #222 #fff;
  box-shadow: inset 1px 1px #dfdfdf;
  cursor: pointer;
}

.win-button:active:not(:disabled), .win-button.pressed {
  padding: 8px 16px 6px 18px;
  border-color: #222 #fff #fff #222;
  box-shadow: none;
}

.win-button:disabled { color: #777; text-shadow: 1px 1px #fff; cursor: not-allowed; }
.win-button.primary { font-weight: 700; box-shadow: inset 0 0 0 1px #111, inset 2px 2px #fff; }
.win-button.wide { width: 100%; }
.win-button.small { min-height: 29px; padding: 4px 11px; font-size: 12px; }


.statusbar {
  min-height: 28px;
  padding: 3px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
}

.status-cell {
  padding: 4px 7px;
  border: 1px solid;
  border-color: #777 #fff #fff #777;
}

.join-body { padding: 24px; }
.join-body h1 { margin: 0 0 8px; font-size: 22px; }
.join-code { color: #000080; font-family: "Courier New", monospace; letter-spacing: 1px; }
.join-actions { display: flex; justify-content: flex-end; gap: 9px; }

.game-window { min-height: calc(100vh - 24px); display: flex; flex-direction: column; }
.game-toolbar { padding: 5px 7px; display: flex; gap: 7px; border-bottom: 1px solid #777; }
.toolbar-spacer { flex: 1; }

.game-grid {
  flex: 1;
  min-height: 0;
  padding: 10px;
  display: grid;
  grid-template-columns: 215px minmax(360px, 1fr) 420px;
  grid-template-rows: minmax(330px, 1fr) auto;
  gap: 10px;
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,.055) 0 1px, transparent 2px),
    linear-gradient(140deg, #087767, #075f53);
  background-size: 8px 8px, auto;
  border: 2px solid;
  border-color: #666 #fff #fff #666;
}

.panel {
  min-width: 0;
  background: var(--win-gray);
  border: 2px solid;
  border-color: #fff #333 #333 #fff;
}

.panel-heading {
  min-height: 27px;
  padding: 5px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: white;
  font-weight: 700;
  font-size: 12px;
  background: #000080;
}

.players-panel { grid-row: 1; }
.player-list { margin: 0; padding: 7px; list-style: none; }
.player-item {
  margin-bottom: 5px;
  padding: 8px;
  display: grid;
  grid-template-columns: 12px minmax(0,1fr) auto;
  gap: 7px;
  align-items: center;
  background: #dfdfdf;
  border: 1px solid;
  border-color: #fff #777 #777 #fff;
}
.player-item.current { color: white; background: #000080; }
.player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-meta { font-size: 11px; opacity: .9; }
.connection-dot { width: 8px; height: 8px; background: #16823c; border: 1px solid #004b1b; }
.connection-dot.offline { background: #888; border-color: #555; }
.ready-mark { color: #0b671e; font-weight: 700; }
.player-item.current .ready-mark { color: white; }

.table-zone {
  position: relative;
  min-height: 330px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  color: white;
  text-align: center;
  border: 2px solid rgba(0,0,0,.22);
  box-shadow: inset 0 0 35px rgba(0,0,0,.19);
}

.table-watermark {
  position: absolute;
  inset: 15px;
  border: 1px solid rgba(255,255,255,.15);
  pointer-events: none;
}

.turn-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 12px;
  color: #111;
  white-space: nowrap;
  background: #ffffd4;
  border: 2px solid;
  border-color: #fff #444 #444 #fff;
}
.turn-banner.yours { color: #fff; background: #000080; }

.empty-table { max-width: 350px; color: #d9fff2; line-height: 1.5; }
.empty-table-symbol { display: block; margin-bottom: 8px; font: 48px Georgia, serif; opacity: .65; }

.played-cards { min-height: 145px; display: flex; justify-content: center; align-items: center; padding-left: 28px; }
.played-cards .card { margin-left: -28px; transform: rotate(var(--tilt, 0deg)); }

.story-bubble {
  position: relative;
  max-width: 540px;
  margin-top: 22px;
  padding: 13px 18px;
  color: #111;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.42;
  background: #fffde9;
  border: 2px solid;
  border-color: #fff #333 #333 #fff;
  box-shadow: 3px 4px 0 rgba(0,0,0,.2);
}
.story-author { display: block; margin-top: 7px; color: #555; font: 11px Tahoma, sans-serif; }

.history-panel { grid-row: 1; display: flex; min-height: 0; flex-direction: column; }
.history-split {
  flex: 1;
  min-height: 0;
  padding: 5px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}
.history-column, .pile-column { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.subpanel-title {
  min-height: 25px;
  padding: 5px 7px;
  font-size: 11px;
  font-weight: 700;
  background: #dfdfdf;
  border: 1px solid;
  border-color: #fff #777 #777 #fff;
}
.history-title { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.history-speak-button { min-height: 21px; padding: 2px 7px; font-size: 11px; white-space: nowrap; }
.history-list { flex: 1; min-height: 0; max-height: calc(100vh - 175px); overflow: auto; padding: 8px; background: #fff; border: 2px solid; border-color: #666 #fff #fff #666; }
.history-split .history-list { max-height: none; }
.history-empty { padding: 30px 14px; color: #666; text-align: center; line-height: 1.45; }
.history-item { position: relative; padding: 10px 8px 10px 29px; border-bottom: 1px dotted #999; }
.history-number { position: absolute; left: 4px; top: 10px; color: #777; font: 11px "Courier New", monospace; }
.history-author { margin-bottom: 4px; color: #000080; font-weight: 700; font-size: 11px; }
.history-text { margin: 0; line-height: 1.4; overflow-wrap: anywhere; }
.history-cards { margin-top: 5px; color: #666; font-size: 11px; }

.pile-column { background: #777; border: 2px solid; border-color: #555 #fff #fff #555; }
.pile-column .subpanel-title { flex: 0 0 auto; color: #111; }
.played-pile {
  position: relative;
  flex: 1;
  min-height: 250px;
  overflow: hidden;
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,.08) 0 1px, transparent 2px),
    #087767;
  background-size: 9px 9px;
  box-shadow: inset 0 0 24px rgba(0,0,0,.24);
}
.pile-card {
  position: absolute;
  z-index: var(--pile-z);
  left: 50%;
  top: 50%;
  display: block;
  transform: translate(calc(-50% + var(--pile-x)), calc(-50% + var(--pile-y))) rotate(var(--pile-r));
  transform-origin: center;
}
.pile-card .card { width: 72px; height: 104px; box-shadow: 2px 3px 0 rgba(0,0,0,.3); }
.pile-card .card-corner { top: 5px; left: 5px; font-size: 16px; }
.pile-card .card-corner.bottom { inset: auto 5px 5px auto; }
.pile-card .card-suit { font-size: 14px; }
.pile-card .card-center { font-size: 33px; }
.pile-count {
  position: absolute;
  z-index: 100;
  right: 8px;
  bottom: 8px;
  min-width: 29px;
  padding: 5px 7px;
  color: white;
  font-weight: 700;
  text-align: center;
  background: #000080;
  border: 2px solid;
  border-color: #fff #222 #222 #fff;
}
.pile-empty {
  flex: 1;
  min-height: 250px;
  padding: 24px 12px;
  display: grid;
  place-content: center;
  gap: 8px;
  color: #d9fff2;
  text-align: center;
  line-height: 1.45;
  background: #087767;
}
.pile-empty span { font-size: 43px; opacity: .75; }

.hand-panel { grid-column: 1 / -1; min-width: 0; }
.hand-body { padding: 10px; display: grid; grid-template-columns: minmax(0,1fr) 340px; gap: 12px; }
.hand-scroll { min-width: 0; overflow-x: auto; padding: 18px 42px 9px 8px; background: #8b8b8b; border: 2px solid; border-color: #555 #fff #fff #555; }
.hand { min-width: max-content; height: 142px; display: flex; align-items: flex-end; }
.hand .card { margin-right: -36px; transition: transform .12s ease, margin .12s ease; }
.hand .card:last-child { margin-right: 0; }
.hand .card:hover { transform: translateY(-8px); }
.hand .card.selected { margin-right: -28px; transform: translateY(-18px); box-shadow: 0 0 0 3px #ffff00, 4px 5px 0 rgba(0,0,0,.35); }

.card {
  position: relative;
  width: 86px;
  height: 124px;
  flex: 0 0 auto;
  padding: 0;
  color: #151515;
  font-family: Georgia, "Times New Roman", serif;
  background: #fffefa;
  border: 1px solid #222;
  border-radius: 5px;
  box-shadow: 3px 4px 0 rgba(0,0,0,.28);
  user-select: none;
}
button.card { cursor: pointer; }
.card.red { color: var(--red); }
.card-corner { position: absolute; top: 6px; left: 7px; display: flex; flex-direction: column; align-items: center; font-size: 20px; font-weight: 700; line-height: .92; }
.card-corner.bottom { inset: auto 7px 6px auto; transform: rotate(180deg); }
.card-suit { font-size: 17px; }
.card-center { position: absolute; inset: 0; display: grid; place-items: center; font-size: 40px; }

.composer { min-width: 0; }
.composer-label { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.char-count { color: #666; font-size: 11px; }
.composer-actions { margin-top: 7px; display: flex; justify-content: space-between; align-items: center; gap: 7px; }
.selected-count { color: #444; font-size: 11px; }
.action-pair { display: flex; gap: 7px; }

.lobby-card {
  align-self: stretch;
  max-width: 570px;
  padding: 22px;
  color: #111;
  text-align: left;
  background: var(--win-gray);
  border: 2px solid;
  border-color: #fff #333 #333 #fff;
  box-shadow: 4px 5px 0 rgba(0,0,0,.23);
}
.lobby-card h2 { margin: 0 0 7px; font-size: 18px; }
.lobby-card p { margin: 0 0 15px; line-height: 1.4; }
.invite-row { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.invite-link { min-width: 0; padding: 9px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: #fff; border: 2px solid; border-color: #555 #fff #fff #555; font: 12px "Courier New", monospace; }
.lobby-progress { margin: 16px 0 10px; }
.progress-track { height: 19px; padding: 2px; background: #fff; border: 2px solid; border-color: #555 #fff #fff #555; }
.progress-value { height: 100%; background: repeating-linear-gradient(90deg, #000080 0 12px, #fff 12px 14px); }
.lobby-actions { margin-top: 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.waiting-note { color: #444; font-size: 11px; }

.finished-box { max-width: 500px; padding: 24px; color: #111; background: #ffffe8; border: 2px solid; border-color: #fff #333 #333 #fff; }
.finished-box h2 { margin: 0 0 8px; }
.finished-box p { line-height: 1.45; }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: 24px;
  max-width: min(520px, calc(100% - 30px));
  padding: 10px 16px;
  color: white;
  background: #111;
  border: 2px solid;
  border-color: #fff #555 #555 #fff;
  box-shadow: 4px 5px 0 rgba(0,0,0,.3);
  transform: translate(-50%, 30px);
  opacity: 0;
  pointer-events: none;
  transition: .18s ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 1050px) {
  .game-grid { grid-template-columns: 190px minmax(320px,1fr); grid-template-rows: minmax(360px,1fr) auto auto; }
  .history-panel { grid-column: 1 / span 2; grid-row: 3; }
  .history-split { min-height: 310px; }
  .history-list { max-height: 280px; }
  .history-split .history-list { max-height: 280px; }
  .played-pile, .pile-empty { min-height: 280px; }
  .hand-panel { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  .desktop { padding: 8px; }
  .desktop.game-desktop { padding: 0; }
  .hero { padding: 28px 18px; grid-template-columns: 1fr; gap: 28px; }
  .hero h1 { font-size: 50px; }
  .game-window { min-height: 100vh; }
  .titlebar { min-height: 34px; }
  .game-grid { padding: 6px; display: flex; flex-direction: column; }
  .players-panel { order: 2; }
  .table-zone { order: 1; min-height: 355px; padding: 55px 14px 22px; }
  .hand-panel { order: 3; }
  .history-panel { order: 4; }
  .hand-body { grid-template-columns: 1fr; }
  .hand-scroll { padding-right: 47px; }
  .composer { padding-top: 3px; }
  .player-list { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 5px; }
  .player-item { margin: 0; }
  .history-list, .history-split .history-list { max-height: 280px; }
  .history-split { grid-template-columns: minmax(0, 1fr) minmax(145px, .8fr); }
  .game-toolbar .toolbar-hide-mobile { display: none; }
  .invite-row { grid-template-columns: 1fr; }
}

@media (max-width: 410px) {
  .hero h1 { font-size: 43px; }
  .dialog-panel { padding: 15px; }
  .player-list { grid-template-columns: 1fr; }
  .composer-actions { align-items: stretch; flex-direction: column; }
  .action-pair { display: grid; grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
