/* =========================================================================
   1. THEME & GLOBAL STYLES
   ========================================================================= */

/* Define the color palette, typography, and shared sizing variables for the entire application. */
:root {
  /* Palette */
  --bg: #1a2c38;
  --panel: #213743;
  --panel2: #2f4553;
  --bdr: #557086;
  --text: #d5dceb;
  --muted: #aab3c7;
  --row-alt: #071d2a;
  /* Used for navbar, buttons, and selected tiles */
  --primary: #38bdf8;

  /* Typography */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Shared sizing */
  --tile-gap: 12px;
  --mine-tile: clamp(64px, 7.2vw, 104px);
  --keno-tile: clamp(58px, 6.6vw, 92px);

  /* Plinko specific */
  --plinko-input-col: 300px;
  --plinko-mini-w: 140px;
  --plinko-mini-h: 96px;
}

/* Basic body styles and a global scrollbar hide. */
html,
body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

/* Hide scrollbars globally, but keep scrolling functionality. */
* {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

*::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* =========================================================================
   2. APP LAYOUT & NAVIGATION
   ========================================================================= */

/* Main application container with padding to account for the fixed navbar. */
#app-container {
  padding: 80px 20px 20px;
  transition: opacity .05s ease-in-out;
}

#app-container.fade-out {
  opacity: 0;
}

/* Fixed navigation bar at the top of the page. */
#navbar-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--row-alt);
  border-bottom: 1px solid var(--bdr);
  display: flex;
  justify-content: center;
}

/* Styling for the navigation list and its items. */
#navbar-container nav ul,
#navbar {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0;
}

#navbar-container nav li a,
#navbar li a {
  display: block;
  color: var(--text);
  text-align: center;
  padding: 20px 24px;
  text-decoration: none;
  font-size: 18px;
  transition: background-color .2s;
  border-radius: 0;
}

#navbar-container nav li a:hover,
#navbar-container nav li a.active,
#navbar li a:hover,
#navbar li a.active {
  background: var(--panel2);
}

/* =========================================================================
   3. GENERIC CONTENT & UI COMPONENTS
   ========================================================================= */

/* Styles for generic informational containers (e.g., FAQ, About pages). */
.info-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem;
}

.info-container h2 {
  color: var(--primary);
}

.info-container a {
  color: var(--primary);
  text-decoration: none;
}

.info-container a:hover {
  text-decoration: underline;
}

.info-container .container {
  background: var(--panel);
  padding: 1.5rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  padding-top: 0.1rem;
  /* Safety for long strings */
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
  
}

/* Reusable button styles. */
.sa-btn {
  width: -moz-available;
  width: -webkit-fill-available;
  max-width: 400px;
  cursor: pointer;
  border: 1px solid #0e2230;
  border-radius: .5rem;
  padding: .75rem 1.5rem;
  font-weight: 600;
  background: var(--row-alt);
  color: var(--text);
  transition: transform .02s ease, filter .15s ease;
}

.sa-btn:hover {
  filter: brightness(1.08);
}

.sa-btn:active {
  transform: translateY(1px);
}

.sa-btn:disabled {
  opacity: .6;
  cursor: not-allowed;
}

.sa-btn-lg {
  padding: 1rem 2rem;
  font-size: 1.125rem;
}

.sa-btn-primary {
  background: var(--row-alt);
  color: var(--text);
}

/* Styling for code snippets. */
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* =========================================================================
   4. SEED ANALYZER LAYOUT
   ========================================================================= */

/* Main layout containers and cards for the seed analyzer tool. */
.sa-container {
  max-width: 1200px;
  margin: 0 auto;
}

.sa-card {
  background: var(--panel);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, .1);
}

.sa-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 1.5rem;
}

/* Flexbox layout for the main tool interface. */
.sa-layout-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sa-top-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.sa-seed-panel {
  flex: 1 1 320px;
}

#gamesWrap {
  flex: 2 1 450px;
  display: flex;
  flex-direction: column;
}

/* Columnar layout and styled input boxes. */
.sa-col {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sa-box {
  background: rgba(0, 0, 0, .1);
  border: 1px solid var(--bdr);
  border-radius: .75rem;
  padding: 1.25rem;
}

/* Shared styles for form labels, inputs, and select dropdowns. */
.sa-label {
  display: block;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: .5rem;
  font-size: .875rem;
}

.sa-input,
.sa-select {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--bdr);
  color: var(--text);
  border-radius: .5rem;
  padding: .75rem 1rem;
  font-size: 1rem;
  box-sizing: border-box;
}

/* =========================================================================
   5. GAME-SPECIFIC UI STYLES
   ========================================================================= */

/* --- Game Picker Grid --- */
#gamePickerGridWrap {
  overflow-y: auto;
  flex-grow: 1;
  margin-top: 1rem;
  max-height: 240px;
  padding: .5rem;
  box-sizing: border-box;
}

#gamePickerGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 1rem;
}

.gameCard {
  position: relative;
  width: 100%;
  height: 118px;
  border-radius: .5rem;
  overflow: hidden;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color .2s;
}

.gameCard .bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transition: transform .2s;
}

.gameCard:hover .bg {
  transform: scale(1.05);
}

.gameCard .shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, .9) 0%, rgba(0, 0, 0, 0) 70%);
}

.gameCard .name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: .5rem;
  font-size: .875rem;
  font-weight: 600;
  text-align: center;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, .7);
}

.gameCard.active {
  border-color: var(--primary);
}

.gameCard.disabled {
  cursor: not-allowed;
  filter: grayscale(1) brightness(.6);
}

.gameCard .coming {
  position: absolute;
  top: .5rem;
  right: .5rem;
  background: #f43f5e;
  color: #fff;
  font-size: .7rem;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 700;
  z-index: 2;
}

/* Dim non-selected games when one is active. */
.app-has-selection #gamePickerGrid .gameCard {
  opacity: .55;
  filter: saturate(.9) contrast(.95);
  transition: opacity .2s;
}

.app-has-selection #gamePickerGrid .gameCard.active {
  opacity: 1;
  filter: none;
}

.app-has-selection #gamePickerGrid .gameCard.disabled {
  filter: grayscale(1) brightness(.6);
}

/* --- Generic Game UI Container --- */
/* By default, game containers shrink to their content. */
#game-ui-container {
  width: fit-content;
  max-width: 100%;
}

/* For specific games like Plinko and Dice, allow the container to fill available width. */
#game-ui-container:has(.plinko-dynamic-layout),
#game-ui-container:has(.game-dice-root) {
  width: 100%;
  width: -moz-available;
  /* Firefox */
  width: -webkit-fill-available;
  /* Chrome/Safari */
  max-width: none;
  margin-inline: 0;
  min-width: 0;
  /* Flexbox safety */
}

/* --- Mines & Keno Grids --- */
#gameGrid .grid25,
#gameGrid .grid40 {
  display: grid;
  gap: 12px;
  justify-content: start;
  width: 100%;
  margin-top: 1rem;
}

#gameGrid .grid25 {
  grid-template-columns: repeat(5, clamp(64px, 7.2vw, 104px));
}

#gameGrid .grid40 {
  grid-template-columns: repeat(8, clamp(58px, 6.6vw, 92px));
}

#gameGrid .tile {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel2);
  color: var(--text);
  border-radius: .375rem;
  cursor: pointer;
  font-size: .9rem;
  min-width: 0;
  aspect-ratio: 1 / 1;
  width: auto;
  /* Let grid column width control size */
  height: auto;
}

#gameGrid .tile.on {
  background: var(--row-alt);
}

.mines-footer,
.keno-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 1rem;
  font-size: .875rem;
  color: var(--muted);
}

.mines-footer .mines-stats-row {
  display: flex;
  gap: 16px;
  align-items: center;
  white-space: nowrap;
  overflow-x: auto;
}

.mines-footer .mines-stats-row span {
  white-space: nowrap;
}

.mines-footer .mines-clear,
.keno-footer .keno-clear {
  align-self: flex-start;
}

.keno-row {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: flex-start;
}

.keno-selected {
  white-space: nowrap;
  margin-right: 12px;
}

.keno-multis {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  justify-content: flex-start;
}

.keno-multi {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-width: 48px;
  height: 48px;
  background: var(--panel2);
  border: 1px solid var(--bdr);
  border-radius: 6px;
  text-align: center;
  position: relative;
}

.keno-multi .k-top {
  font-weight: 700;
  font-size: .8rem;
}

.keno-multi .k-bot {
  font-size: .75rem;
  opacity: .9;
}

.keno-multi .tip-i {
  position: absolute;
  top: 0;
  right: 0;
  margin: 0;
  pointer-events: auto;
  z-index: 2;
}

/* --- Dice --- */
.sa-game-inputs.game-dice {
  width: fit-content;
}

.dice-info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--bdr);
  border: 1px solid var(--bdr);
  border-radius: .5rem;
  overflow: hidden;
  margin-top: 1.5rem;
}

.dice-info-box {
  background: var(--panel);
  padding: .75rem 1rem;
}

.dice-info-box .sa-label {
  margin-bottom: .25rem;
}

.sa-input-static {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  padding: .75rem 0;
  font-size: 1rem;
  box-sizing: border-box;
}

.dice-mode-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.dice-mode-btn:hover {
  color: var(--text);
}

.dice-slider-wrap {
  margin-top: .75rem;
}

.dice-scale {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  width: 100%;
  padding: 0 8px;
  margin-bottom: 6px;
  pointer-events: none;
  user-select: none;
}

.dice-track-wrap {
  background: var(--panel2);
  height: 30px;
  border-radius: 999px;
  position: relative;
  user-select: none;
  display: flex;
  align-items: center;
  padding: 0 19px;
}

.dice-track {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 19px;
  right: 19px;
  height: 14px;
  border-radius: 999px;
  background: #32424b;
  overflow: hidden;
}

.dice-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 14px;
  background: transparent;
  outline: none;
  position: relative;
  z-index: 2;
  touch-action: none;
}

.dice-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  margin-top: -5px;
  width: 22px;
  height: 22px;
  background: #071d2a;
  cursor: pointer;
  border-radius: 4px;
  border: none;
  box-shadow: 0 0 0 3px #557086;
}

.dice-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  background: #071d2a;
  cursor: pointer;
  border-radius: 4px;
  border: none;
  box-shadow: 0 0 0 1px #ffffff;
}

.dice-slider::-webkit-slider-runnable-track,
.dice-slider::-moz-range-track {
  background: transparent;
  border: none;
}

/* --- Plinko --- */
.plinko-dynamic-layout {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.plinko-dynamic-layout>.plinko-left-col {
  flex: 0 0 300px;
}

.plinko-dynamic-layout>.sa-game-inputs {
  flex: 0 0 300px;
}

.plinko-left-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.plinko-dynamic-layout>.plinko-board-wrapper {
  flex: 1 1 0;
  /* Allow board to grow and fill space */
  min-width: 0;
  /* Flexbox safety */
}

.plinko-board-col {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
  width: 100%;
  max-width: none;
  /* Allow it to scale with the wrapper */
  margin: 0 auto;
}

.plinko-board-col .plinko-svg {
  width: 100%;
  height: auto;
  display: block;
  margin: 0 auto clamp(-28px, -3.2vw, -14px);
  /* Vertical alignment */
}

.plinko-multi-grid {
  display: grid;
  grid-template-columns: repeat(var(--plinko-cols, 17), minmax(0, 1fr));
  gap: 2px;
}

.plinko-multi-tile {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px 2px;
  border-radius: 4px;
  color: #fff;
  font-size: clamp(8px, 2.8vw, 12px);
  text-shadow: 1px 1px 2px rgba(0, 0, 0, .5);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid #9fb2c1;
}

#resultsTable td.c-result .mini-plinko {
  width: 140px;
  height: 96px;
  flex: 0 0 auto;
}

#resultsTable td.c-result .mini-plinko .plinko-svg {
  width: 100% !important;
  height: 100% !important;
  display: block;
  max-width: none !important;
  max-height: none !important;
  overflow: visible;
}

.plinko-svg .plinko-pin {
  fill: #9fb2c1;
  opacity: .9;
}

.plinko-svg .plinko-path {
  fill: none;
  stroke: #38bdf8;
  stroke-width: 2.5px;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .95;
}

.plinko-svg .plinko-ball {
  fill: #071d2a;
  stroke: #0f1c24;
  stroke-width: 1.5px;
}

.plinko-bucket-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.plinko-bucket-strip .bucket {
  min-width: 48px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  background: var(--panel2);
  border: 1px solid var(--bdr);
  border-radius: 6px;
  font-weight: 700;
  font-size: .875rem;
}

.plinko-bucket-strip .bucket.on {
  outline: 2px solid #fb923c;
}

.plinko-sim-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.plinko-sim-layer .plinko-sim-ball {
  fill: #38bdf8;
  stroke: #071d2a;
  stroke-width: .25px !important;
  filter: drop-shadow(0 .25px .5px rgba(0, 0, 0, .45)) !important;
  opacity: .95;
  transition: opacity .12s linear;
}

/* =========================================================================
   6. TABLES & UTILITIES
   ========================================================================= */

/* Shared styles for results tables. */
.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.table th,
.table td {
  padding: .75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--bdr);
}

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

#resultsTable td.c-result {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* General utility classes. */
.sa-game-inputs,
#gameGrid {
  min-width: 0;
  /* Flexbox safety */
}

/* Remove arrows from number input fields. */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Small tooltip icon style. */
.tip-i {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  width: 14px;
  height: 14px;
  border-radius: 9999px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  color: #c6d6e5;
  background: #1e313c;
  border: 1px solid #3a515c;
  vertical-align: middle;
  user-select: none;
}

/* =========================================================================
   7. RESPONSIVE MEDIA QUERIES
   ========================================================================= */

/* For medium tablets and smaller */
@media (max-width: 860px) {
  .plinko-dynamic-layout {
    flex-direction: column;
    align-items: stretch;
  }

  .plinko-dynamic-layout>.plinko-left-col,
  .plinko-dynamic-layout>.sa-game-inputs {
    flex-basis: auto;
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
  }

  .plinko-dynamic-layout>.plinko-board-wrapper {
    max-width: 500px;
    width: auto;
    margin: 0 auto;
  }
}

/* For small tablets and mobile devices */
@media (max-width: 768px) {

  /* Navbar */
  #navbar-container nav li a,
  #navbar li a {
    padding: 12px 14px;
    font-size: 16px;
  }

  #app-container {
    padding-top: 96px;
  }

  /* Main game container fills the screen width */
  #game-ui-container {
    width: -webkit-fill-available;
    /* Chrome/Safari */
    width: -moz-available;
    /* Firefox */
    width: 100%;
    /* Fallback */
  }

  /* Game Grids */
  .sa-box.sa-game-inputs.game-keno,
  .sa-box.sa-game-inputs.game-mines {
    width: 100%;
    overflow-x: auto;
    box-sizing: border-box;
  }

  #gameGrid .grid25 {
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
  }

  #gameGrid .grid40 {
    grid-template-columns: repeat(8, 1fr);
    gap: 8px;
  }

  #gameGrid .tile {
    font-size: .75rem;
  }

  .keno-row {
    flex-wrap: wrap;
  }

  .keno-multis {
    gap: 6px;
  }

  .keno-multi {
    min-width: 40px;
    height: 40px;
  }

  .keno-multi .k-top {
    font-size: 0.75rem;
  }

  .keno-multi .k-bot {
    font-size: 0.7rem;
  }

  /* UPDATED: Simplified Responsive Table */
  #tableWrapper {
    overflow-x: auto;
  }

  /* 1. Use a more specific selector to override JS styles. */
  /* Use Flexbox for the sticky header for maximum stability. */
  table#resultsTable.table thead tr {
    display: flex;
    width: 100%;
    min-width: 500px;
    /* Set a total width to enable scrolling */
  }

  table#resultsTable.table thead th:nth-child(1) {
    flex: 0 0 80px;
  }

  /* Nonce */
  table#resultsTable.table thead th:nth-child(2) {
    flex: 1 1 auto;
  }

  /* Result */
  table#resultsTable.table thead th:nth-child(3) {
    flex: 0 0 110px;
  }

  /* Multiplier */
  table#resultsTable.table thead th:nth-child(4) {
    flex: 0 0 110px;
  }

  /* Profit */

  /* 2. Use the Grid layout for the body rows. */
  table#resultsTable.table tbody tr {
    /* These values MUST align with the flexbox widths above */
    display: grid;
    grid-template-columns: 80px 1fr 110px 110px;
    min-width: 500px;
  }

  /* 3. General cell styling for mobile */
  table#resultsTable.table th,
  table#resultsTable.table td {
    padding: 10px 8px;
    font-size: 0.9rem;
  }

  table#resultsTable.table td.c-result {
    justify-content: center;
  }
}