/* Dekataire / Dekauntlet styles (v1.7) */

:root {
  --bg-color: #0f2b1d;
  --board-color: #1b4d3e;
  --slot-bg: #143b2f;
  --slot-border: #286854;
  --card-bg: #f8f9fa;
  --text-main: #f0f4f1;
  --gold: #f39c12;
  --red: #e74c3c;
  --blue-undo: #2980b9;
  --green-club: #3fae6a;
  --blue-diamond: #2f9bd6;
  --purple-joker: #b07cf2;
  --hard-challenge: #e67e22;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 10px;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

.main-layout {
  display: flex;
  gap: 15px;
  max-width: 1500px;
  width: 100%;
  align-items: stretch;
}

/* Mobile First Layout Adjustments */
@media (max-width: 1024px) {
  .main-layout {
    flex-direction: column;
    gap: 10px;
  }

  .sidebar {
    width: 100% !important;
  }

  /* Action buttons stay side-by-side as a compact row */
  .sidebar-actions {
    flex-direction: row !important;
    gap: 10px;
  }

  .sidebar-actions button {
    flex: 1;
    padding: 10px 8px !important;
    font-size: 0.9rem !important;
    min-height: 44px;
  }

  /* Scoring Guide + Undo stay grouped as one flex item within the row,
     so the mobile row layout (Refill / Scoring Guide / Undo) is unchanged.
     (Extra specificity here beats the later, unscoped base rule.) */
  .sidebar-actions .scoring-undo-row {
    flex-direction: row;
    flex: 2;
    gap: 10px;
  }

  .sidebar-info {
    min-height: 70px;
  }

  /* Below-board row stacks vertically on narrow screens */
  .below-board-row {
    flex-direction: column;
  }

  .finish-box {
    flex: 0 0 auto;
    width: 100%;
    min-height: 60px;
  }

  .board-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    padding-bottom: 8px;
    width: 100%;
  }

  #game-grid {
    min-width: 640px; /* Ensures grid columns remain comfortably playable on small screens */
  }

  .submit-btn {
    min-height: 40px;
  }

  .scroll-hint {
    display: block;
  }
}

.board-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.board-wrapper {
  width: 100%;
  min-width: 0;
}

/* Tablet landscape: keep the 3-column layout but give the board more room */
@media (min-width: 1025px) and (max-width: 1400px) {
  .sidebar {
    width: 190px;
  }
  .main-layout {
    gap: 12px;
  }
}

.scroll-hint {
  display: none;
  text-align: center;
  font-size: 0.75rem;
  color: #abd1c6;
  padding: 4px 0 2px;
}

#game-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(5, auto);
  gap: 6px;
  background-color: var(--board-color);
  padding: 10px;
  border-radius: 12px;
  border: 2px solid var(--slot-border);
  width: 100%;
}

.grid-cell {
  aspect-ratio: 1 / 1;
  background-color: var(--slot-bg);
  border: 1px solid var(--slot-border);
  border-radius: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.queue-cell {
  border: 2px dashed var(--gold);
}

.valid-target {
  border: 2px dashed var(--gold) !important;
  background-color: rgba(243, 156, 18, 0.15);
}

.card {
  width: 100%;
  height: 100%;
  background-color: var(--card-bg);
  border-radius: 6px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 3px 4px;
  font-weight: bold;
  cursor: pointer;
  box-sizing: border-box;
  touch-action: manipulation;
}
.card.red { color: var(--red); }
.card.black { color: #000000; }
.card.club { color: var(--green-club); }
.card.diamond { color: var(--blue-diamond); }
.card.joker { color: var(--purple-joker); }
.card.selected {
  outline: 3px solid var(--gold);
  transform: translateY(-4px);
}

.card-corner {
  font-size: 0.95rem;
  line-height: 1;
}
.card-suit {
  font-size: 1.4rem;
  align-self: center;
  line-height: 1;
}

.col-footer {
  grid-column: span 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.hand-indicator {
  font-size: 0.7rem;
  text-align: center;
  color: #abd1c6;
  height: 1.1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.submit-btn {
  padding: 6px 2px;
  font-size: 0.72rem;
  font-weight: bold;
  min-height: 34px;
  touch-action: manipulation;
  background-color: var(--slot-bg);
  color: #7da696;
  border: 1px solid var(--slot-border);
  border-radius: 6px;
  cursor: not-allowed;
  transition: background-color 0.2s, color 0.2s, opacity 0.2s;
}
.submit-btn:not(:disabled) {
  background-color: var(--gold);
  color: #111;
  border-color: var(--gold);
  cursor: pointer;
}
.submit-btn:disabled {
  opacity: 0.6;
}

/* Sidebars Base Layout */
.sidebar {
  width: 230px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Default: Scoring Guide and Undo stack like any other sidebar action.
   Dekauntlet mode (body.dk-theme) overrides this below to place them
   side by side at desktop/tablet widths. */
.scoring-undo-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-info {
  flex: 1;
  min-height: 80px;
}

.sidebar-info .info-value {
  font-size: 2.4rem;
}

.hands-box {
  flex: 1;
  min-height: 0;
  padding: 8px 10px;
}

.hands-list {
  width: 100%;
  margin-top: 6px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-main);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  text-align: center;
}

.hands-list .hand-entry {
  white-space: nowrap;
}

.sidebar button {
  background-color: var(--gold);
  color: #111;
  border: none;
  padding: 12px 14px;
  font-size: 1rem;
  font-weight: bold;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  width: 100%;
  touch-action: manipulation;
}

.sidebar button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.sidebar button:hover:not(:disabled) {
  opacity: 0.9;
}
.sidebar button:active:not(:disabled) {
  transform: scale(0.98);
}

#refill-btn {
  min-height: 100px;
}

.undo-btn {
  background-color: var(--blue-undo) !important;
  color: #fff !important;
}

.restart-btn {
  background-color: #34495e !important;
  color: #ecf0f1 !important;
}

.below-board {
  margin-top: 14px;
}

.below-board-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.info-box, .finish-box {
  background: var(--slot-bg);
  border: 2px solid var(--slot-border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 170px;
}

.info-label {
  font-size: 0.8rem;
  color: #abd1c6;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.info-value {
  font-size: 2.1rem;
  font-weight: bold;
  color: var(--gold);
  margin-top: 4px;
}

.finish-box {
  background-color: var(--gold);
  border-color: var(--gold);
  color: #111;
  font-size: 1.05rem;
  font-weight: bold;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  touch-action: manipulation;
  flex: 0 0 200px;
}
.finish-box:hover { opacity: 0.9; }
.finish-box:active { transform: scale(0.98); }

/* Combined Remaining Cards box: one panel, suits divided by an inner line */
.tracker-box {
  flex: 1;
  min-width: 0;
  justify-content: flex-start;
  padding: 10px 6px;
}

.tracker-box .info-label {
  margin-bottom: 6px;
}

.tracker-suits {
  display: flex;
  flex-direction: row;
  width: 100%;
  flex: 1;
}

.suit-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0 6px;
  border-left: 1px solid var(--slot-border);
}
.suit-col:first-child {
  border-left: none;
}

.suit-col-header {
  font-size: 1.9rem;
  font-weight: bold;
  color: var(--text-main);
  line-height: 1;
}
.suit-col-header.red { color: var(--red); }
.suit-col-header.club { color: var(--green-club); }
.suit-col-header.diamond { color: var(--blue-diamond); }
.suit-col-header.joker { color: var(--purple-joker); }

.suit-list {
  font-size: 1.05rem;
  color: #dfe9e4;
  line-height: 1.4;
  overflow-y: auto;
  max-height: 125px;
  width: 100%;
  text-align: center;
}

.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.85);
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 20px;
}
.modal-content {
  background: var(--slot-bg);
  padding: 24px;
  border-radius: 12px;
  border: 2px solid var(--gold);
  text-align: center;
  max-width: 360px;
  width: 90%;
  position: relative;
}

.modal-close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: auto !important;
  background: transparent !important;
  color: var(--text-main) !important;
  border: none;
  padding: 4px 10px !important;
  font-size: 1.4rem;
  font-weight: bold;
  line-height: 1;
  border-radius: 6px;
  cursor: pointer;
}
.modal-close-btn:hover {
  opacity: 1 !important;
  background: rgba(255,255,255,0.1) !important;
}

.scoring-guide-list {
  text-align: left;
  margin-top: 4px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.hand-summary {
  background: var(--board-color);
  border: 1px solid var(--slot-border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 15px;
  text-align: left;
}

.hand-summary-title {
  font-size: 0.8rem;
  color: #abd1c6;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin-bottom: 6px;
  text-align: center;
}

.hand-summary-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.95rem;
  padding: 2px 0;
}

.hand-summary-row .hand-name {
  color: var(--text-main);
}

.hand-summary-row .hand-count {
  color: var(--gold);
  font-weight: bold;
}

.hand-summary-empty {
  font-size: 0.9rem;
  color: #abd1c6;
  text-align: center;
}
.modal-actions button {
  flex: 1;
}
.modal-content button {
  background-color: var(--gold);
  color: #111;
  border: none;
  padding: 12px 14px;
  font-size: 1rem;
  font-weight: bold;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  touch-action: manipulation;
}
.modal-content button:hover {
  opacity: 0.9;
}
.modal-content button:active {
  transform: scale(0.98);
}

/* ===================== Dekauntlet additions ===================== */

body.dk-theme {
  --bg-color: #1f1330;
  --board-color: #3c2a5e;
  --slot-bg: #291c42;
  --slot-border: #6d4fa8;
}

body.dk-theme .sidebar-info {
  min-height: 46px;
  padding: 6px 8px;
}
body.dk-theme .sidebar-info .info-value {
  font-size: 1.6rem;
  margin-top: 2px;
}
body.dk-theme .hands-box {
  min-height: 46px;
  flex: 0 0 auto;
  padding: 6px 8px;
}
body.dk-theme .hands-list {
  font-size: 0.7rem;
  line-height: 1.3;
  max-height: 60px;
  margin-top: 2px;
}

/* Dekauntlet only: Hands Submitted moves to the bottom of the sidebar,
   below the round/peek/modifiers/challenge panels. Dekataire's sidebar
   (no dk-theme class) is unaffected. */
body.dk-theme .hands-box {
  order: 10;
}

/* Dekauntlet only, desktop/tablet: Scoring Guide + Undo sit side by
   side, shrunk to fit the sidebar's existing width. Below 1024px the
   shared mobile row rule above already handles layout for every mode. */
@media (min-width: 1025px) {
  body.dk-theme .scoring-undo-row {
    flex-direction: row;
    gap: 8px;
  }
  body.dk-theme .scoring-undo-row button {
    flex: 1;
    min-width: 0;
    padding: 10px 6px;
    font-size: 0.82rem;
  }
}

.dk-round-box .info-value {
  font-size: 1.05rem !important;
}

.dk-mini-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  margin-top: 4px;
}
.dk-mini-card {
  width: 32px;
  height: 44px;
  background: var(--card-bg);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: bold;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.dk-mini-card.red { color: var(--red); }
.dk-mini-card.black { color: #000000; }
.dk-mini-card.club { color: var(--green-club); }
.dk-mini-card.diamond { color: var(--blue-diamond); }
.dk-mini-card.joker { color: var(--purple-joker); }

.dk-modifiers-list, .dk-challenge-box {
  font-size: 0.8rem;
  margin-top: 4px;
  width: 100%;
}

.dk-mod-chip {
  position: relative;
  display: inline-block;
  padding: 4px 8px;
  margin: 2px;
  border-radius: 6px;
  border: 2px solid #b8b8b8;
  background: var(--board-color);
  font-weight: bold;
  font-size: 0.75rem;
  cursor: default;
}
.dk-mod-chip.rarity-common { border-color: #b8b8b8; }
.dk-mod-chip.rarity-uncommon { border-color: var(--green-club); }
.dk-mod-chip.rarity-rare { border-color: var(--blue-diamond); }
.dk-mod-chip.rarity-ultra { border-color: var(--gold); }

.dk-mod-tooltip {
  display: none;
  position: absolute;
  bottom: 115%;
  left: 50%;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  border: 1px solid var(--gold);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.68rem;
  font-weight: normal;
  width: 150px;
  text-align: left;
  z-index: 60;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
.dk-mod-chip:hover .dk-mod-tooltip { display: block; }

.dk-empty-note {
  color: #abd1c6;
  font-size: 0.75rem;
  text-align: center;
  margin-top: 4px;
}

.toss-btn {
  background-color: #8e3b3b !important;
  color: #fff !important;
  border-color: #8e3b3b !important;
}
.toss-btn:not(:disabled) { cursor: pointer; opacity: 1; }

.dk-purple-btn {
  background-color: #8a4fd6 !important;
  color: #fff !important;
}

.modal-content.shop-modal {
  max-width: 1000px;
  width: 95vw;
  text-align: left;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 32px;
}
.shop-offer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--board-color);
  border: 2px solid var(--slot-border);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 10px;
}
.shop-offer.rarity-common { border-color: #b8b8b8; }
.shop-offer.rarity-uncommon { border-color: var(--green-club); }
.shop-offer.rarity-rare { border-color: var(--blue-diamond); }
.shop-offer.rarity-ultra { border-color: var(--gold); }
.shop-offer-info { flex: 1; min-width: 0; }
.shop-offer-name { font-weight: bold; font-size: 1.15rem; }
.shop-offer-desc { font-size: 0.92rem; color: #cfc7de; margin-top: 4px; }
.shop-offer-buy {
  min-width: 84px;
  width: auto !important;
  padding: 12px 16px !important;
  font-size: 1.05rem !important;
}
.shop-offer.disabled-offer { opacity: 0.5; }

/* Reroll, Undo pack, and Challenge offers get a background distinct
   from Modifier offers so the two kinds of purchase read apart. */
.shop-offer-utility {
  background: #1f3a52;
  border-color: #2f5f82;
}

.shop-held-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--slot-bg);
  border: 1px solid var(--slot-border);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 1rem;
}
.discard-x {
  background: #8e3b3b !important;
  color: #fff !important;
  border: none;
  border-radius: 4px;
  padding: 3px 9px !important;
  font-size: 0.72rem !important;
  width: auto !important;
}
.shop-section-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #abd1c6;
  margin: 14px 0 6px;
}
#dk-shop-bank {
  float: right;
  font-size: 1.35rem;
  font-weight: bold;
  color: var(--gold);
}

/* Held Modifiers / Challenge as hover chips at the top of the shop */
.shop-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}
.dk-mod-chip-shop {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 2px solid #b8b8b8;
  background: var(--board-color);
  font-weight: bold;
  font-size: 1rem;
  cursor: default;
}
.dk-mod-chip-shop.rarity-common { border-color: #b8b8b8; }
.dk-mod-chip-shop.rarity-uncommon { border-color: var(--green-club); }
.dk-mod-chip-shop.rarity-rare { border-color: var(--blue-diamond); }
.dk-mod-chip-shop.rarity-ultra { border-color: var(--gold); }
.dk-mod-chip-shop.challenge-chip { border-color: var(--gold); }
.dk-mod-chip-shop.hard-challenge-chip { border-color: var(--hard-challenge); }
.shop-offer.hard-challenge-offer { border-color: var(--hard-challenge); }
.info-box.hard-challenge-active { border-color: var(--hard-challenge); }
.dk-mod-chip-shop .dk-mod-tooltip {
  bottom: auto;
  top: 115%;
  width: 210px;
  font-size: 0.78rem;
}
.dk-mod-chip-shop:hover .dk-mod-tooltip { display: block; }
.dk-chip-discard {
  background: #8e3b3b;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}

/* ===================== v1.3 additions ===================== */
.dk-score-sub { font-size: 0.78rem; color: #cfc7de; margin-top: 2px; }
.dk-mod-chip.curse-chip, .dk-mod-chip-shop.curse-chip { border-color: var(--red); background: #3a1f2e; }
.guide-up { color: #6fdc8c !important; }
.guide-down { color: #ff8a80 !important; }
.guide-removed .hand-name, .guide-removed .hand-count { text-decoration: line-through; opacity: 0.55; }
.guide-level { font-size: 0.7rem; color: #abd1c6; margin-left: 6px; }
.modal-content.pick-modal { max-width: 560px; }
.pick-options { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.pick-option {
  text-align: left; background: var(--board-color) !important; color: var(--text-main) !important;
  border: 2px solid var(--slot-border) !important; border-radius: 8px; padding: 12px 14px !important; width: 100%;
}
.pick-option:hover { border-color: var(--gold) !important; }
.pick-option.curse-option { border-color: var(--red) !important; }
.pick-option-name { font-weight: bold; font-size: 1.05rem; }
#scoring-guide-modal { z-index: 200; }
.dk-mod-chip .dk-mod-tooltip, .dk-mod-chip-shop .dk-mod-tooltip { left: 0; transform: none; }
.dk-final-score { font-weight: bold; color: var(--gold); font-size: 1.2rem; margin-top: 10px; }
.dk-final-target { font-size: 0.85rem; color: #abd1c6; margin-bottom: 8px; }
.shop-top-actions { display: flex; justify-content: flex-end; margin-top: 4px; }
.shop-top-actions button { width: auto !important; padding: 8px 14px !important; font-size: 0.9rem !important; }
.pick-option-desc { font-size: 0.88rem; color: #cfc7de; margin-top: 4px; font-weight: normal; }
