/* ============================================================
   Kingdom page — layout and card styles
   Uses CSS Grid + aspect-ratio for fluid, responsive layout.
   No fixed pixel widths on cards — everything scales naturally.
   ============================================================ */

/* ---- Page wrapper ----
   Override the global `main { padding: 3em 1.5em }` which shrinks
   every page. Kingdom needs its own tighter padding so cards can
   use the full available viewport width. */
/* Dominion's box art is parchment and gold coins; the page follows it.
   Every accent below reads from these two, so retinting the page is a
   two-line change. */
:root {
  --page-accent: #8a6d3b;
  --page-accent-dark: #4a3822;
}

.kingdom-main {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 1rem 1.25rem;
  box-sizing: border-box;
  text-align: left; /* override global main { text-align: center } */
}

/* ---- Header banner ---- */
.kingdom-header {
  position: relative;
  text-align: center;
  padding: 2.5rem 1.5rem;
  background: var(--page-accent-dark);
  color: white;
  border-radius: 12px;
  margin-bottom: 1.5rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

/* ---- Help button (reopens the intro modal on demand) ---- */
.help-btn {
  /* box-sizing + padding:0 + flex centering: a bare <button> picks up the
     browser's own default padding (uneven side-to-side vs top-to-bottom),
     which on top of content-box sizing made the 34x34 render as an oval,
     not a circle. This makes the declared 34x34 the true, total box. */
  box-sizing: border-box;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.65);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

.help-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.06);
}

.kingdom-header h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  font-weight: 700;
}

.kingdom-intro {
  font-size: clamp(0.95rem, 2vw, 1.15rem);
  margin: 0;
  opacity: 0.92;
}

/* ---- Sidebar + content layout ---- */
#layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* ---- Sidebar ---- */
#sidebar {
  background: #fff;
  padding: 1.5rem;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.09);
  position: sticky;
  top: 1rem;
}

#sidebar h2 {
  color: var(--page-accent);
  font-size: 1.2rem;
  text-align: center;
  border-bottom: 2px solid var(--page-accent);
  padding-bottom: 0.6rem;
  margin-bottom: 1.25rem;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.controls label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  color: #333;
  transition: background 0.15s;
}

.controls label:hover {
  background: #f3f3f3;
}

.controls input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--page-accent);
  cursor: pointer;
  flex-shrink: 0;
}

#generate {
  width: 100%;
  padding: 0.8rem;
  background: var(--page-accent-dark);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 3px 12px rgba(74, 56, 34, 0.25);
}

#generate:hover {
  opacity: 0.93;
  transform: translateY(-1px);
  box-shadow: 0 5px 16px rgba(74, 56, 34, 0.38);
}

#generate:active {
  transform: translateY(0);
}

/* ---- Main content area ---- */
#content {
  min-width: 0; /* critical: prevents grid blowout */
}

.section-title {
  color: var(--page-accent);
  font-size: 1.35rem;
  border-bottom: 2px solid var(--page-accent);
  padding-bottom: 0.4rem;
  margin-bottom: 1.25rem;
}

.kingdom-section,
.bonus-section {
  margin-bottom: 2.5rem;
}

/* ---- Card grids ----
   Kingdom is always exactly 10 cards, so its column count is hardcoded
   (5, or 2 on phones - see the media query below) rather than derived from
   a percentage/auto-fill guess. That guess is what broke into a 6-then-4
   split: auto-fill's column count is a function of continuous width, with
   no idea the row needs to divide evenly into 10. Only divisors of 10 are
   used as column counts here so a row is never left ragged.

   Every card also gets a fixed max-width (below) instead of being allowed
   to stretch to fill its column. Columns are capped the same way (190px,
   not 1fr) - capping the card alone isn't enough, since 1fr columns still
   stretch to fill the full row on a wide screen, which just relocates the
   dead space to between cards instead of removing it. justify-content
   centers the resulting compact block, pushing leftover width to the
   outer margins instead. */
#kingdom-cards {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 190px));
  justify-content: center;
  gap: 0.65rem;
}

/* Bonus/Landscape counts vary each generation, so these flow naturally -
   but with the column track itself capped to the same width as the card
   max-width below (not 1fr), so a half-full row doesn't stretch into
   oversized columns; leftover space centers the whole row instead.
   auto-fit, not auto-fill: auto-fill reserves as many column tracks as
   mathematically fit the container, even ones no card occupies, and
   justify-content:center centers that whole reserved set - so with only
   1-2 cards in a very wide row, the real cards sit near the left edge of
   a mostly-empty invisible block, looking uncentered. auto-fit collapses
   the unused trailing tracks to 0 width, so centering only accounts for
   the tracks actually holding a card. */
.bonus-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 190px));
  justify-content: center;
  gap: 0.65rem;
}

/* ---- Card base ---- */
.card {
  width: 100%;
  max-width: 190px;
  justify-self: center;
  aspect-ratio: 5 / 8;
  border-radius: 10px;
  overflow: hidden;
  background: #f0f0f0;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.14);
  position: relative;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.2);
}

.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Landscape / sideways cards span 2 columns, but at width:100% of that
   span a wide aspect-ratio card ends up with ~1.6x the on-screen area of
   a portrait card (bigger, not just wider). Scaling to 80% of the span
   brings its area back in line with a portrait card's, so it reads as
   "wide" rather than "giant" next to its neighbors.
   max-width needs its own value here (not the general .card 190px) - a
   2-column span capped at 190px each is up to ~390px, and 80% of that is
   ~312px; inheriting the flat 190px cap instead would clamp it down to
   the same width as a portrait card, making it smaller, not comparable. */
.card.sideways {
  width: 80%;
  max-width: 312px;
  aspect-ratio: 8 / 5;
  grid-column: span 2;
  justify-self: center;
}

/* ---- Card overlay (click to show) ---- */
.card-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  border-radius: 10px;
  z-index: 10;
}

.card.active .card-overlay {
  display: flex;
}

.card-controls {
  display: flex;
  gap: 12px;
}

.card-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.95);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.25rem;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
}

.card-btn:hover {
  transform: scale(1.12);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.38);
}

.card-btn.lock-btn  { color: var(--page-accent); }
.card-btn.reroll-btn { color: #e74c3c; }

.card-name {
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
  padding: 0 8px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}

/* ---- Locked state ---- */
.card.locked {
  outline: 3px solid var(--page-accent);
  outline-offset: 2px;
}

.card.locked::after {
  content: "🔒";
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 1rem;
  background: var(--page-accent-dark);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 5;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* ============================================================
   Responsive breakpoints
   ============================================================ */

/* Tablet: collapse sidebar above content */
@media (max-width: 900px) {
  #layout {
    grid-template-columns: 1fr;
  }

  #sidebar {
    position: static;
  }

  .controls {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .controls label {
    flex: 0 1 auto;
  }
}

/* Mobile portrait: tighter gaps, smaller padding */
@media (max-width: 480px) {
  .kingdom-main {
    padding: 0.75rem;
  }

  #kingdom-cards,
  .bonus-grid {
    gap: 0.4rem;
  }

  /* 5 columns gets too cramped below ~480px - 2 still divides 10 evenly,
     so this never leaves a ragged row either. */
  #kingdom-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================================
   Intro / help modal
   ============================================================ */
/* A native <dialog>, opened two ways (see js/modules/intro.js):

   non-modal (first visit) - an in-flow panel under the header band, so
     the nav and the Generate button stay clickable behind nothing at all.
   modal (the "?" button)  - centered over a backdrop, with the browser's
     own focus trap, Escape handling and focus restore. */
.intro-dialog[open] {
  position: relative;
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  margin: 0 0 1.5rem;
  padding: 1.6rem 1.75rem 1.5rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.intro-dialog[open]:modal {
  position: fixed;
  inset: 0;
  margin: auto;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.intro-dialog::backdrop {
  background: rgba(29, 43, 40, 0.55);
}

.intro-dialog h2 {
  margin: 0 0 10px;
  color: #333;
  font-size: 1.4rem;
}

.intro-dialog h3 {
  margin: 20px 0 8px;
  color: var(--page-accent);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.intro-dialog p {
  margin: 0 0 10px;
  color: #444;
  font-size: 0.95rem;
  line-height: 1.55;
}

.intro-dialog dl {
  margin: 0;
}

.intro-dialog dt {
  font-weight: 700;
  color: #333;
  margin-top: 10px;
  font-size: 0.9rem;
}

.intro-dialog dd {
  margin: 2px 0 0;
  color: #555;
  font-size: 0.88rem;
  line-height: 1.4;
}

.intro-close {
  position: absolute;
  top: 12px;
  right: 14px;
  border: none;
  background: none;
  font-size: 1.5rem;
  color: #999;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
}

.intro-close:hover {
  color: #333;
}

.intro-got-it {
  display: block;
  width: 100%;
  margin-top: 22px;
  padding: 0.75rem;
  background: var(--page-accent-dark);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.intro-got-it:hover {
  opacity: 0.92;
}
