:root {
  --card-w: clamp(62px, 11.5vw, 108px);
  --card-h: calc(var(--card-w) * 1.278);
  /* visible sliver of a covered card: padding + ~3 lines of the name */
  --overlap: calc(var(--card-w) * 0.38 + 10px);
  --navy: #0a2f5c;
  --navy-dark: #071f3d;
  --red: #b3122b;
  --gold: #d4af37;
  --felt: #12513a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Verdana, sans-serif;
  background: var(--felt);
  color: #f2f2f2;
  min-height: 100vh;
}

.app-header {
  background: var(--navy-dark);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  border-bottom: 3px solid var(--gold);
}

.app-header h1 {
  font-size: 1.3rem;
  margin: 0;
  color: var(--gold);
  white-space: nowrap;
}

.controls button {
  background: var(--navy);
  color: #fff;
  border: 1px solid var(--gold);
  border-radius: 4px;
  padding: 6px 12px;
  margin-right: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.controls button:hover { background: var(--red); }

.stats {
  margin-left: auto;
  display: flex;
  gap: 16px;
  font-variant-numeric: tabular-nums;
}

.help-panel {
  position: fixed;
  top: 70px;
  right: 20px;
  width: min(360px, 90vw);
  max-height: calc(100vh - 90px);
  display: flex;
  flex-direction: column;
  background: #fff;
  color: #111;
  border-radius: 8px;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.help-panel.hidden { display: none; }
.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 10px;
  border-bottom: 1px solid #ddd;
}
.help-head h2 { margin: 0; color: var(--navy); }
.help-x {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: #555;
  padding: 0 4px;
}
.help-x:hover { color: var(--red); }
.help-body { overflow-y: auto; padding: 4px 20px 16px; }
.help-panel li { margin-bottom: 8px; font-size: 0.9rem; }

#cheat-panel { width: min(430px, 92vw); }
.cheat-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.cheat-table td { padding: 3px 6px; border-bottom: 1px solid #eee; vertical-align: top; }
.cheat-table .cnum { color: var(--red); font-weight: bold; text-align: right; width: 2em; }
.cheat-table .cname { color: var(--navy); font-weight: 600; }
.cheat-table .cyears { color: #444; white-space: nowrap; }

.board {
  padding: 20px 10px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  max-width: 100vw;
}

.top-row {
  display: flex;
  justify-content: space-between;
  gap: 30px;
  flex-wrap: wrap;
}

.cell-group {
  display: flex;
  gap: clamp(4px, 1vw, 12px);
  flex-wrap: wrap;
}

.cascade-row {
  display: flex;
  gap: clamp(4px, 1vw, 12px);
  justify-content: center;
  flex-wrap: nowrap;
}

.pile {
  width: var(--card-w);
  min-height: var(--card-h);
  border: 2px dashed rgba(255,255,255,0.35);
  border-radius: 8px;
  position: relative;
  z-index: 0;
}

/* Invisible wings widen each pile's hit/drop area sideways, so a drop in
   the gap between two piles lands on a pile instead of missing entirely.
   Negative z-index keeps it behind the cards inside the pile. */
.pile::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -8px;
  right: -8px;
  z-index: -1;
}

.pile.cascade {
  min-height: var(--card-h);
  padding-bottom: 10px;
}

.pile.valid-target {
  border-color: var(--gold);
  box-shadow: 0 0 10px 2px var(--gold);
}

.card {
  width: var(--card-w);
  height: var(--card-h);
  background: linear-gradient(160deg, #ffffff, #e8ecf3);
  border: 1px solid #999;
  border-radius: 8px;
  color: #111;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
  position: relative;
  overflow: hidden;
}

.cascade .card:not(:first-child) {
  margin-top: calc(-1 * (var(--card-h) - var(--overlap)));
}

.card .run-arrow {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: calc(var(--card-w) * 0.12);
  line-height: 1;
  color: var(--red);
}

.card.has-arrow .name {
  padding-right: calc(var(--card-w) * 0.16);
}

.card .name {
  font-size: calc(var(--card-w) * 0.115);
  font-weight: 600;
  line-height: 1.1;
  margin-top: 2px;
  color: var(--navy);
}

.card .num {
  font-size: calc(var(--card-w) * 0.11);
  font-weight: bold;
  color: var(--red);
}

.card .fact {
  font-size: calc(var(--card-w) * 0.105);
  font-style: italic;
  color: #555;
  line-height: 1.2;
  margin: auto 0;
}

.card .foot {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 8px;
}

.card .years {
  font-size: calc(var(--card-w) * 0.105);
  color: #444;
}

.card.selected {
  outline: 3px solid var(--gold);
  outline-offset: -3px;
  transform: translateY(-6px);
  box-shadow: 0 6px 10px rgba(0,0,0,0.5);
}

.card.dragging { opacity: 0.4; }

.pile-label {
  position: absolute;
  bottom: -18px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.65rem;
  color: rgba(255,255,255,0.6);
}

.homecell .card, .freecell .card {
  position: absolute;
  top: 0;
  left: 0;
}

.homecell .count-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--gold);
  color: #111;
  border-radius: 11px;
  min-width: 22px;
  padding: 0 4px;
  height: 22px;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  z-index: 2;
}

.stuck-banner {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--navy-dark);
  color: #fff;
  border: 2px solid var(--gold);
  border-radius: 8px;
  padding: 8px 14px;
  z-index: 60;
  box-shadow: 0 6px 18px rgba(0,0,0,0.5);
}
.stuck-banner.hidden { display: none; }
.stuck-banner button:not(.help-x) {
  background: var(--navy);
  color: #fff;
  border: 1px solid var(--gold);
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.85rem;
}
.stuck-banner button:not(.help-x):hover { background: var(--red); }
.stuck-banner .help-x { color: #ccc; }
.stuck-banner .help-x:hover { color: var(--gold); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 4vh;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }

/* Start/finish dialog, styled after the BzzWordsPlus game cards (styles/bzzwords.css) */
.start-content {
  --bz-blue: #356d9f;
  --bz-blue-deep: #214e78;
  --bz-muted: #6b6256;
  --bz-line: rgba(79, 58, 25, 0.14);
  --bz-shadow-sm: 0 4px 14px rgba(75, 53, 20, 0.09);
  --bz-radius: 22px;
  display: grid;
  gap: 1rem;
  width: min(92vw, 560px);
  max-height: 92vh;
  overflow-y: auto;
  padding: 1rem;
  border-radius: var(--bz-radius);
  background: #fff9ec;
  box-shadow: 0 18px 45px rgba(75, 53, 20, 0.35);
  animation: modalSlideIn 0.3s ease-out;
}

.start-card {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--bz-line);
  border-radius: var(--bz-radius);
  background: #fff;
  box-shadow: var(--bz-shadow-sm);
  text-align: left;
}

.start-art {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.start-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 1rem;
}

.start-body h2 {
  margin: 0 0 0.45rem 0;
  color: var(--bz-blue-deep);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
  text-align: center;
}

.start-body p {
  margin: 0 0 0.65rem 0;
  color: var(--bz-muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.start-body .start-stats {
  color: var(--red);
  font-weight: 700;
  text-align: center;
}
.start-body .start-stats.hidden { display: none; }

.start-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: auto;
}

.arcade-link,
.start-button {
  display: inline-flex;
  align-items: center;
  min-height: 46px;
  padding: 0.65rem 1.1rem;
  border: none;
  border-radius: 999px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.arcade-link {
  box-shadow: inset 0 0 0 2px var(--bz-blue-deep);
  color: var(--bz-blue-deep);
  background: transparent;
}
.arcade-link:hover {
  color: #fff;
  background: var(--bz-blue-deep);
  transform: translateY(-2px);
}

.start-button {
  color: #fff;
  background: var(--bz-blue-deep);
}
.start-button:hover {
  background: var(--bz-blue);
  transform: translateY(-2px);
}
.start-button.hidden { display: none; }

.ad-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  padding: 0.65rem;
  border: 1px solid var(--bz-line);
  border-radius: var(--bz-radius);
  background: rgba(255, 255, 255, 0.58);
  box-shadow: var(--bz-shadow-sm);
}

.ad-label {
  margin-bottom: 0.35rem;
  color: #7d756b;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
}

.ad-card .adsbygoogle {
  min-height: 250px;
  border-radius: 8px;
  background: rgba(236, 232, 223, 0.55);
}

@media (max-width: 600px) {
  .start-card { grid-template-columns: 1fr; }
  .start-art { height: 110px; }
}

@media (max-height: 600px) {
  .start-content {
    width: min(92vw, 720px);
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }
  .ad-card .adsbygoogle { width: 300px; }
}

@media (max-height: 600px) and (max-width: 720px) {
  .start-content { grid-template-columns: 1fr; }
  .ad-card .adsbygoogle { width: auto; }
}

@keyframes modalSlideIn {
  from { transform: translateY(-50px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
