:root {
  --felt: #0d3b2e;
  --felt-deep: #082a20;
  --line: rgba(255, 255, 255, 0.14);
  --text: #f2f6f3;
  --muted: #9fb6ac;
  --accent: #e8b64c;
  --danger: #e06b5a;
  --card-face: #fbf7ec;
  --card-edge: #d9d0b8;
  --radius: 14px;

  --suit-dinari: #d09a12;
  --suit-kupe: #c0392b;
  --suit-spade: #2b6cb0;
  --suit-bastoni: #2e8b52;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: radial-gradient(circle at 50% 20%, #14503d 0%, var(--felt) 45%, var(--felt-deep) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  user-select: none;
  -webkit-user-select: none;
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ------------------------------------------------------------------ home */

.home-inner {
  margin: auto;
  width: 100%;
  max-width: 380px;
  padding: 24px 22px 40px;
  text-align: center;
}

.logo {
  margin: 0;
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.tagline {
  margin: 4px 0 28px;
  color: var(--muted);
  font-size: 15px;
}

.field {
  display: block;
  text-align: left;
  margin-bottom: 12px;
}

.field > span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"] {
  width: 100%;
  padding: 14px 16px;
  font-size: 17px;
  font-family: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

input[type="text"]:focus { border-color: var(--accent); }

#input-code {
  text-transform: uppercase;
  letter-spacing: 0.35em;
  font-weight: 700;
  text-align: center;
}

.btn {
  display: block;
  width: 100%;
  padding: 15px 18px;
  margin-bottom: 10px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.btn:active { transform: scale(0.985); }
.btn, .icon-btn, .card { touch-action: manipulation; }
.btn:disabled { opacity: 0.55; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #2a1f05;
}

.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  font-weight: 500;
  text-decoration: underline;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 13px;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.error {
  margin-top: 14px;
  color: var(--danger);
  font-size: 14px;
}

/* ------------------------------------------------------------ player bars */

.player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  flex: 0 0 auto;
}

.player-bar.opponent { border-bottom: 1px solid var(--line); }
.player-bar.you { border-top: 1px solid var(--line); }

.who { display: flex; align-items: center; gap: 8px; min-width: 0; }

.pname {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}

.series { font-size: 12px; color: var(--muted); }

.meta { display: flex; align-items: center; gap: 10px; }

.points {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 15px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 999px;
  padding: 3px 12px;
  min-width: 46px;
  text-align: center;
}

.points.lead { color: var(--accent); }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf7d;
  flex: 0 0 auto;
}

.dot.off { background: var(--danger); }

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}

/* ------------------------------------------------------------------ board */

.hand {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: 10px 12px;
}

.hand-opponent { padding-top: 12px; }
.hand-you { padding-bottom: 6px; }

.board {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
  padding: 0 12px;
}

.stock {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.stock-cards {
  position: relative;
  width: 54px;
  height: 81px;
}

.stock-cards .card {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* The briškula pokes well out from under the face-down stock. */
.stock-cards .trump-card { transform: rotate(-24deg) translate(-13px, 10px); }
.stock-cards .stock-back { transform: rotate(5deg) translate(9px, -5px); }

.stock-count {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Always-visible copy of the trump suit, since the tucked card is small. */
.trump-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--card-face);
  border: 1px solid var(--card-edge);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.chip-title {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b5f45;
}

.pip-chip { width: 16px; height: 16px; flex: 0 0 auto; }

.chip-suit { font-size: 11px; font-weight: 700; }

.table-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.slot {
  width: 78px;
  height: 117px;
  border-radius: var(--radius);
}

.slot:empty {
  border: 1px dashed rgba(255, 255, 255, 0.12);
}

.slot .card { width: 100%; height: 100%; }

.status {
  flex: 0 0 auto;
  margin: 0;
  padding: 6px 16px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  min-height: 30px;
}

.status.turn { color: var(--accent); font-weight: 600; }

/* ------------------------------------------------------------------ cards */

.card {
  position: relative;
  width: min(26vw, 96px);
  aspect-ratio: 2 / 3;
  background: var(--card-face);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  flex: 0 0 auto;
}

.suit-dinari { color: var(--suit-dinari); }
.suit-kupe { color: var(--suit-kupe); }
.suit-spade { color: var(--suit-spade); }
.suit-bastoni { color: var(--suit-bastoni); }

.card-corner {
  position: absolute;
  top: 4px;
  left: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.card-rank {
  font-size: clamp(11px, 3.6vw, 15px);
  font-weight: 800;
}

.pip-corner { width: clamp(9px, 3vw, 12px); height: clamp(9px, 3vw, 12px); margin-top: 2px; }

.card-face {
  position: absolute;
  inset: 22% 10% 10%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.pip-main { width: 62%; height: auto; }

.card-labels {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  text-align: center;
}

.card-figure {
  font-size: clamp(7px, 2.1vw, 9px);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  opacity: 0.75;
}

.card-suit-name {
  font-size: clamp(8px, 2.5vw, 11px);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* the face-up trump card is small - keep its text from crowding the pip */
.stock-cards .pip-main { width: 56%; }
.stock-cards .card-figure { display: none; }
.stock-cards .card-suit-name { font-size: 7px; }

.card-points {
  position: absolute;
  right: 4px;
  bottom: 4px;
  min-width: 17px;
  padding: 1px 4px;
  border-radius: 999px;
  background: currentColor;
  color: transparent;
  font-size: clamp(9px, 2.8vw, 11px);
  font-weight: 800;
  text-align: center;
  line-height: 1.35;
}

/* the number itself is punched out of the coloured pill */
.card-points {
  -webkit-text-fill-color: var(--card-face);
  color: var(--card-face);
}

.card-back {
  background:
    repeating-linear-gradient(45deg, #123f5c 0 6px, #0e3247 6px 12px);
  border-color: #0a2434;
}

.card-back::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
}

.hand-opponent .card { width: min(16vw, 58px); }

.playable { cursor: pointer; transition: transform 0.12s ease; }
.playable:active { transform: translateY(-6px); }

.hand-you .card:not(.playable) { opacity: 0.55; }

.card.won { outline: 3px solid var(--accent); outline-offset: -3px; }

/* --------------------------------------------------------------- overlays */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 20, 15, 0.86);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.panel {
  width: 100%;
  max-width: 340px;
  background: #0f4436;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px 22px;
  text-align: center;
}

.panel-scroll {
  max-height: 84vh;
  overflow-y: auto;
  text-align: left;
  -webkit-overflow-scrolling: touch;
}

.panel h2 { margin: 0 0 10px; font-size: 22px; }
.panel h3 { margin: 18px 0 8px; font-size: 15px; color: var(--accent); }
.panel p { margin: 0 0 12px; font-size: 14px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

.room-code {
  font-size: 46px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--accent);
  margin: 12px 0 20px;
  padding-left: 0.18em;
}

.end-score {
  font-size: 30px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin: 6px 0 4px;
}

.win #end-title { color: #6fd39a; }
.loss #end-title { color: var(--danger); }

table.rules {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 12px;
}

table.rules th, table.rules td {
  padding: 5px 4px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

table.rules th { color: var(--muted); font-weight: 600; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 40;
  max-width: 88vw;
  text-align: center;
}

/* ------------------------------------------------------- roomier screens */

@media (min-height: 720px) {
  .slot { width: 92px; height: 138px; }
  .stock-cards { width: 64px; height: 96px; }
}

@media (min-width: 560px) {
  .card { width: 110px; }
  .hand-opponent .card { width: 64px; }
}

/* ================================================================== shell */

.view {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ------------------------------------------------------------- game list */

.game-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 4px; }

.game-card {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.game-card:active { transform: scale(0.99); }
.game-emoji { font-size: 28px; line-height: 1; }
.game-text { display: flex; flex-direction: column; min-width: 0; }
.game-name { font-size: 16px; font-weight: 700; }
.game-tagline { font-size: 12px; color: var(--muted); }

.game-mode {
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

/* ============================================================ zastavice */

.view-zastavice { padding: 0 8px 6px; }

.z-flags {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 0;
}

.z-row {
  display: grid;
  grid-template-columns: 1fr 34px 1fr;
  align-items: center;
  gap: 4px;
  padding: 3px 4px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid transparent;
}

.z-row.targetable { border-color: var(--accent); background: rgba(232, 182, 76, 0.12); }
.z-row.won-you { background: rgba(76, 175, 125, 0.18); }
.z-row.won-opp { background: rgba(224, 107, 90, 0.16); }

.z-side { display: flex; flex-direction: column; min-width: 0; }
.z-cards { display: flex; gap: 3px; }
.z-opp .z-cards, .z-opp .z-form { justify-content: flex-end; text-align: right; flex-direction: row-reverse; }

.z-form {
  font-size: 8px;
  line-height: 1.3;
  color: var(--muted);
  height: 11px;
  overflow: hidden;
  white-space: nowrap;
}

.z-flag { text-align: center; font-size: 17px; }

.zc {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 32px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 800;
  color: #17130a;
  background: #ddd;
  flex: 0 0 auto;
}

.zc.empty { background: rgba(255, 255, 255, 0.07); }

.c-r { background: #e8695c; }
.c-o { background: #e79a3c; }
.c-y { background: #e3d04a; }
.c-g { background: #5cbd8a; }
.c-b { background: #5f9fe0; }
.c-p { background: #b189dd; }

.z-hand {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 8px 4px 4px;
  border-top: 1px solid var(--line);
}

.z-hand .zc {
  width: 40px;
  height: 52px;
  font-size: 21px;
  cursor: pointer;
}

.z-hand .zc.picked { outline: 3px solid var(--accent); outline-offset: 2px; transform: translateY(-4px); }

/* ============================================================= stratego */

.view-stratego { padding: 4px 8px 6px; }

.st-wrap { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; min-height: 0; }

.st-board {
  display: grid;
  gap: 3px;
  width: 100%;
  max-width: min(94vw, 420px);
}

.st-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  overflow: hidden;
}

.st-cell.lake { background: rgba(40, 90, 130, 0.45); border-color: rgba(120, 180, 220, 0.25); }
.st-cell.home { background: rgba(255, 255, 255, 0.09); }

.st-cell.mine {
  background: linear-gradient(180deg, #2f7c5f, #226248);
  border-color: rgba(255, 255, 255, 0.25);
}

.st-cell.theirs {
  background: linear-gradient(180deg, #8a3f36, #6d2f28);
  border-color: rgba(255, 255, 255, 0.18);
}

.st-cell b { font-size: clamp(13px, 4.2vw, 19px); font-weight: 800; }
.st-cell i {
  font-style: normal;
  font-size: clamp(6px, 2vw, 8px);
  opacity: 0.75;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.st-cell.picked { outline: 3px solid var(--accent); outline-offset: -3px; }
.st-cell.target::after {
  content: "";
  position: absolute;
  width: 34%;
  height: 34%;
  border-radius: 50%;
  background: rgba(232, 182, 76, 0.75);
}
.st-cell.theirs.target::after { width: 100%; height: 100%; border-radius: 7px; background: rgba(232, 182, 76, 0.3); }
.st-cell.battle { box-shadow: inset 0 0 0 2px #fff; }
.st-cell.moved { border-color: rgba(255, 255, 255, 0.5); }

.st-panel { flex: 0 0 auto; padding-top: 6px; }
.st-note { text-align: center; margin: 8px 0; font-size: 14px; }

.st-tray { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin-bottom: 8px; }

.st-tile {
  position: relative;
  width: 58px;
  padding: 5px 2px 4px;
  font-family: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  cursor: pointer;
}

.st-tile b { font-size: 15px; }
.st-tile i { font-style: normal; font-size: 8px; opacity: 0.75; }
.st-tile.picked { border-color: var(--accent); background: rgba(232, 182, 76, 0.18); }
.st-tile.spent { opacity: 0.35; }

.st-left {
  position: absolute;
  top: -5px;
  right: -3px;
  min-width: 16px;
  font-size: 10px;
  font-weight: 800;
  background: var(--accent);
  color: #2a1f05;
  border-radius: 999px;
  padding: 0 4px;
}

.st-buttons { display: flex; gap: 8px; }
.st-buttons .btn { margin-bottom: 0; padding: 12px 8px; font-size: 14px; }

.st-battle {
  margin: 4px 0 8px;
  text-align: center;
  font-size: 13px;
  color: var(--accent);
}

.st-losses { display: flex; gap: 12px; justify-content: space-between; }
.st-chips { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }

.st-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
}

/* ================================================================ bomba */

.view-bomba { padding: 4px 12px 8px; gap: 8px; }

.bo-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.bo-fuse {
  font-size: clamp(56px, 20vw, 96px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.bo-fuse.calm { color: #6fd39a; }
.bo-fuse.warm { color: var(--accent); }
.bo-fuse.critical { color: var(--danger); animation: bo-pulse 0.6s infinite alternate; }
.bo-fuse.waiting { color: var(--muted); font-size: clamp(40px, 14vw, 64px); }

@keyframes bo-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.07); }
}

.bo-sub { margin: 10px 0 0; font-size: 13px; color: var(--muted); text-align: center; min-height: 34px; }

.bo-round { display: flex; gap: 8px; flex: 0 0 auto; }

.bo-cell {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
}

.bo-cell b { font-size: 17px; font-variant-numeric: tabular-nums; }

.bo-actions { flex: 0 0 auto; }
.bo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }

.bo-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 6px;
  font-family: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.bo-btn b { font-size: 16px; }
.bo-btn span { font-size: 11px; color: var(--muted); }
.bo-btn.off { opacity: 0.4; }
.bo-btn:active { transform: scale(0.98); }

.bo-pass {
  width: 100%;
  padding: 16px;
  font-family: inherit;
  font-size: 18px;
  font-weight: 800;
  color: #2a1f05;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

.bo-pass.off { opacity: 0.4; }
.bo-pass:active { transform: scale(0.99); }

.bo-feed {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  max-height: 46px;
  overflow: hidden;
  padding-top: 6px;
}

.bo-tag {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--muted);
}

.bo-tag.mine { color: var(--text); background: rgba(255, 255, 255, 0.12); }
