:root {
  --navy: #2c3e50;
  --softgray: #e9ecef;
  --teal: #1abc9c;
  --gold: #f1c40f;
  --slate: #556366;
  --coral: #e74c3c;
  --teal-dark: #0d7a63;
  --teal-darker: #0b6e58;
  --coral-dark: #c0392b;
  --coral-darker: #a93226;
  --slate-dark: #556366;
  --white: #ffffff;
  --gray-100: #f7fafc;
  --gray-200: #edf2f7;
  --gray-300: #e2e8f0;
  --max-width: 1120px;
  --container-pad: 16px;
  --radius: 10px;
  --shadow-sm: 0 6px 18px rgba(0, 0, 0, 0.06);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  color: var(--navy);
  background: linear-gradient(135deg, #ecf0f1 0%, #d6dbdf 100%);
  padding: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

li { line-height: 2; }

.page-header {
  text-align: center;
  color: var(--navy);
  padding: 1rem;
  position: relative;
}

.header-left { justify-self: start; }

.header-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.page-title {
  margin: 0;
  justify-self: center;
  font-size: 2rem;
  font-weight: 700;
  font-family: "Montserrat", sans-serif;
}

.header-actions { justify-self: end; }

@media (max-width: 767px) {
  .header-grid {
    grid-template-columns: 1fr;
    grid-auto-flow: row;
    text-align: left;
  }
  .page-title { justify-self: start; }
  .header-actions { justify-self: start; width: 100%; margin-top: 8px; }
}

.cols {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.experiment-area {
  background: var(--gray-100);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 24px;
}

.sim-area {
  background: var(--softgray);
  border-radius: 8px;
  padding: 16px;
  position: relative;
  overflow: auto;
  min-height: 420px;
}

.dice-tray {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 6px;
  align-content: start;
}

.die {
  aspect-ratio: 1 / 1;
  border-radius: 5px;
  background: var(--white);
  border: 2px solid rgba(44, 62, 80, 0.25);
  box-shadow: var(--shadow-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease;
}

.die.rolling {
  animation: die-shake 0.18s ease 2;
}

.die.decayed {
  background: var(--navy);
  border-color: var(--navy);
  cursor: pointer;
}

.die.decayed:hover {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(241, 196, 15, 0.5);
}

.die.removed {
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
}

@keyframes die-shake {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(12deg) scale(1.08); }
  100% { transform: rotate(0deg) scale(1); }
}

.controls {
  background: white;
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.control-group { margin-bottom: 18px; }

.label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--slate);
  font-weight: 600;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.stat-label {
  font-size: 14px;
  color: var(--slate);
  font-weight: 600;
}

.value {
  display: inline-block;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(26, 188, 156, 0.12);
  color: var(--teal);
  min-width: 64px;
  text-align: center;
  font-weight: 700;
}

.select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--softgray);
  background: white;
  color: var(--navy);
  font-weight: 600;
  font-family: inherit;
}

.toggle-row { margin-top: 8px; }

.record-group {
  background: rgba(241, 196, 15, 0.1);
  border: 1px solid rgba(241, 196, 15, 0.4);
  border-radius: 8px;
  padding: 12px;
}

.record-group .range-row { margin-bottom: 8px; }

.record-group input[type='number'] {
  flex: 1;
  min-width: 0;
}

.record-group input.input-error {
  border-color: var(--coral);
  outline: 2px solid rgba(231, 76, 60, 0.2);
}

.btn.small {
  padding: 8px 14px;
  font-size: 14px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--slate);
  font-weight: 600;
}

.toggle input { transform: translateY(1px); }

.button-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 24px;
}

.btn {
  display: inline-block;
  border-radius: 0.375rem;
  text-decoration: none;
  text-align: center;
  transition: all 0.2s;
  cursor: pointer;
  border: 1px solid transparent;
  width: auto;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 24px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.teal-btn {
  background-color: rgba(26, 188, 156, 0.8);
  color: white;
}
.teal-btn:hover {
  background-color: rgba(26, 188, 156, 0.7);
  transform: translateY(-2px);
}

.gold-btn {
  background-color: rgba(241, 196, 15, 1);
  color: var(--navy);
  opacity: 0.9;
}
.gold-btn:hover {
  background-color: rgba(241, 196, 15, 0.5);
  transform: translateY(-2px);
}

.gold-btn.active {
  background-color: rgba(231, 76, 60, 0.8);
  color: white;
}

.coral-btn {
  background-color: rgba(231, 76, 60, 0.8);
  color: white;
}
.coral-btn:hover {
  background-color: rgba(231, 76, 60, 0.7);
  transform: translateY(-2px);
}

.navy-btn {
  background-color: rgba(44, 62, 80, 0.8);
  color: white;
}
.navy-btn:hover {
  background-color: rgba(44, 62, 80, 0.7);
  transform: translateY(-2px);
}

.panel {
  margin-top: 24px;
  background: white;
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.panel h3 {
  margin: 0 0 12px 0;
  font-size: 18px;
}

.graph-wrap {
  overflow-x: auto;
}

.graph-wrap canvas {
  width: 100%;
  height: auto;
  max-width: 900px;
  display: block;
}

.table-wrap { overflow-x: auto; }

.results-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--softgray);
}

.results-table th,
.results-table td {
  border: 1px solid var(--softgray);
  padding: 8px;
  text-align: left;
}

.results-table thead tr { background: var(--softgray); }

.results-table th { font-weight: 700; }

a:focus,
button:focus,
input:focus,
select:focus {
  outline: 3px solid var(--teal-dark);
  outline-offset: 2px;
}

@media (min-width: 768px) {
  body { padding: 24px; }
  .container { padding: 0; }
  .cols { flex-direction: row; }
  .sim-area { flex: 2; margin-right: 24px; }
  .controls { flex: 1; }
  .page-title { font-size: 32px; }
}

/* --------------------------------
   Footer
----------------------------------- */
.site-footer {
  background: #2c3e50;
  color: #fff;
  text-align: center;
  padding: 16px;
  font-size: 0.8rem;
  margin: 32px -16px -16px;
}

.site-footer p {
  margin: 0;
}


/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}


/* Comfortable touch targets on touch devices (excludes in-table data cells) */
@media (pointer: coarse) {
  button:not([class*="cell"]):not([class*="table"]):not(.progress-dot):not(.col-type-badge):not(.col-delete),
  a.btn,
  .btn,
  select:not([class*="cell"]):not([class*="table"]) {
    min-height: 44px;
  }
  .row-delete,
  .col-delete,
  .delete-btn,
  .delete-row-btn,
  .remove-btn {
    min-width: 44px;
    min-height: 44px;
  }
  input[type="range"]::-webkit-slider-thumb { width: 24px; height: 24px; }
  input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; }
}
