:root {
  --bg: #000;
  --panel: #0a0f11;
  --ink: #e6f7ef;
  --ink-dim: rgba(180, 255, 230, 0.75);
  --accent: #00ffff;
  --accent2: #4e6b50;
  --line: rgba(0, 255, 255, 0.2);
  --muted: #071014;
  --r-sm: 10px;
  --r-lg: 18px;
  --card: var(--panel);
  --card-hidden: #06090a; /* ADDED: Distinct background for hidden card */
  --ring: rgba(0, 255, 255, 0.25);
  --shadow: 0 0 14px rgba(0, 255, 255, 0.25);
  /* UPDATED FONT STACK */
  --body: "Optima", "Palatino", "Palatino Linotype", "Book Antiqua", "Georgia",
    serif;

  /* --- Added: Game Feedback Colors --- */
  --success: #3cff60;
  --warning: #ffb83c;
  --error: #ff3c3c;
  /* ----------------------------------- */
}
[data-theme="dark"] {
  --bg: #0f1113;
  --ink: #eaeaea;
  --ink-dim: #a7abb0;
  --line: rgba(255, 255, 255, 0.14);
  --card: #13161a;
  --card-hidden: #101215; /* ADDED: Slightly darker than panel for contrast */
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  --accent: #a7d0b1;
  --accent2: #c8b39a;

  /* --- Added: Dark Mode Colors --- */
  --success: #a7d0b1;
  --warning: #ffb83c;
  --error: #ff3c3c;
  /* ----------------------------------- */
}
[data-theme="light"] {
  --bg: #f7f5ef;
  --ink: #1e2328;
  --ink-dim: #6b6f73;
  --line: rgba(0, 0, 0, 0.12);
  --card: #ffffff;
  --card-hidden: #f0f0f0; /* ADDED: Slightly off-white for distinction */
  --accent: #4e6b50;
  --accent2: #7a5e3e;
  --ring: rgba(78, 107, 80, 0.25);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  color-scheme: light;

  /* --- Added: Light Mode Colors --- */
  --success: #4e9d57;
  --warning: #cc8400;
  --error: #cc0000;
  /* ----------------------------------- */
}
/* Softer link colors for dark theme */
a {
  color: var(--accent2, #4e6b50);
  text-decoration: underline;
  transition: color 0.2s ease;
}

[data-theme="dark"] a {
  color: rgba(0, 255, 255, 0.75); /* softer cyan */
}

[data-theme="dark"] a:hover,
[data-theme="light"] a:hover {
  color: var(--accent, #00ffff);
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.15);
}
.brand {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
}
.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--accent);
  text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}
.brand .sub {
  font-size: 0.8rem;
  color: var(--ink-dim);
}
.tabs {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem 1rem; /* Adjusted padding */
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  overflow-x: auto; /* Scroll horizontally on small screens */
  flex-shrink: 0; /* Prevent vertical shrinking */
}
.tab {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0; /* Prevent tabs from getting too small */
}
.tab.active {
  outline: 2px solid var(--accent);
  box-shadow: var(--shadow);
  transition: 0.2s;
}
main {
  flex: 1 1 auto;
  display: flex;
  padding: 1rem;
  gap: 1rem;
  overflow-y: auto; /* Allow main content to scroll vertically */
  min-height: 0; /* Important for flex container */
}
.panel {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  background: var(--card);
  width: 100%; /* Ensure panels take full width in flex context */
  min-width: 0; /* Allow shrinking */
}
.section {
  padding: 1rem;
}
.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
button {
  font: 0.85rem/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(0, 255, 255, 0.1);
  flex-shrink: 0;
}
button:hover {
  background: var(--muted);
  border-color: var(--accent);
  box-shadow: 0 0 6px var(--ring);
  transition: 0.2s;
}
.pill {
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.72rem;
  color: var(--ink-dim);
  background: var(--bg);
}
footer {
  border-top: 1px solid var(--line);
  padding: 0.8rem 1rem;
  color: var(--ink-dim);
  flex-shrink: 0;
}

/* --- Range Input Styling (ColorBloom Fix) --- */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  width: 100%;
  accent-color: var(--accent); /* Modern browsers */
}

input[type="range"]::-webkit-slider-runnable-track {
  background: var(--line);
  height: 4px;
  border-radius: 2px;
}

input[type="range"]::-moz-range-track {
  background: var(--line);
  height: 4px;
  border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 1px solid var(--ink);
  margin-top: -6px;
}

input[type="range"]::-moz-range-thumb {
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 1px solid var(--ink);
}
/* -------------------------------------------- */

label {
  font-size: 0.9rem;
  color: var(--ink-dim);
}

/* —— Game-specific wrappers (reuse prior) —— */
.mt-wrap {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 1rem;
  width: 100%;
}
.mt-grid {
  display: grid;
  gap: 10px;
  justify-content: center;
  align-content: start;
}
.mt-card {
  width: 72px;
  height: 72px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-hidden); /* MODIFIED TO USE NEW VARIABLE */
  border: 1px solid var(--line);
  font-size: 34px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease, background 0.15s ease;
}
.mt-card:active {
  transform: scale(0.98);
}
.mt-card.revealed,
.mt-card.matched {
  background: rgba(0, 255, 255, 0.06);
}
.mt-card.matched {
  outline: 2px solid var(--accent);
}

.cb-wrap {
  display: grid;
  grid-template-columns: 1fr 260px; /* FIXED: Control panel is now 1fr (wide), Details panel is 260px (narrow) */
  gap: 1rem;
  width: 100%;
}
.cb-swatch {
  height: 100px; /* Reduced height for better fit */
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.cb-dual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}
.cb-stat {
  font: 0.9rem ui-monospace, Menlo, Consolas, monospace;
  color: var(--ink-dim);
}
.fg-wrap {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 1rem;
  width: 100%;
}

/* --- MirrorMaze layout --- */
.mm-wrap {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1rem;
  width: 100%;
}

.mm-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-width: 480px;
  margin: 0 auto;
}

.mm-cell {
  position: relative;
  padding-top: 100%; /* square */
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card-hidden);
  cursor: pointer;
  overflow: hidden;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.mm-cell-inner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
}

.mm-cell.source {
  background: radial-gradient(
    circle at left,
    rgba(0, 255, 255, 0.25),
    var(--card-hidden)
  );
}

.mm-cell.target {
  background: radial-gradient(
    circle at right,
    rgba(167, 208, 177, 0.4),
    var(--card-hidden)
  );
}

.mm-cell.wall {
  background: #15181c;
  border-color: rgba(0, 0, 0, 0.5);
}

.mm-cell.beam {
  box-shadow: 0 0 10px rgba(0, 255, 255, 0.6);
}

.mm-status {
  margin-top: 0.7rem;
  font: 0.9rem ui-monospace, Menlo, Consolas, monospace;
  color: var(--ink-dim);
}

/* Mobile stacking */
@media (max-width: 900px) {
  .mm-wrap {
    grid-template-columns: 1fr;
  }
}

/* Added: Constellation Grid Cell style (to ensure clickable area) */
#constGrid > div {
  background: var(--bg);
  border: 1px solid var(--line);
  cursor: pointer;
}

/* ------------------------------------------------------------------ */
/* 📱 Mobile Responsiveness: Breakpoints Below 900px and 550px */
/* ------------------------------------------------------------------ */

@media (max-width: 900px) {
  main {
    flex-direction: column; /* Stack panels vertically */
    padding: 0.8rem;
    gap: 0.8rem;
  }
  .section {
    padding: 0.8rem;
  }
  .mt-wrap,
  .cb-wrap,
  .fg-wrap {
    grid-template-columns: 1fr; /* Stack side-by-side components */
  }
  .mt-wrap > div:last-child {
    order: -1; /* Move grid/canvas above stats panel on mobile */
  }
}

@media (max-width: 550px) {
  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  .brand .sub {
    display: none; /* Hide subtitle for space */
  }
  .tabs {
    padding: 0.6rem 0.8rem;
  }
  .mt-card {
    width: 50px; /* Smaller cards for 4x4 on small screens */
    height: 50px;
    font-size: 24px;
  }
  .mt-grid {
    gap: 5px;
  }
  /* MemoryTiles Grid size adjustment for max 50px cards */
  .mt-grid[style*="repeat(4"] {
    grid-template-columns: repeat(4, 50px);
  }
  .mt-grid[style*="repeat(6"] {
    grid-template-columns: repeat(6, 50px);
  }
}
/* --- SumLeaves + SequenceForge shared styles --- */
/* SumLeaves: dark-green tiles, theme-adaptive */
.sl-cell {
  min-width: 70px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #f7f7f7;
  background: linear-gradient(145deg, #234c2a, #3c6b3e); /* dark green base */
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

[data-theme="light"] .sl-cell {
  background: linear-gradient(145deg, #4e6b50, #7a8d63);
  color: #f9f9f9;
}

.sl-selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sl-correct {
  background: linear-gradient(145deg, var(--success), #4e6b50);
}

.sl-wrong {
  background: linear-gradient(145deg, #994040, #4e6b50);
}

.sf-option {
  min-width: 64px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* highlight states */
.sl-selected {
  outline: 2px solid var(--accent2);
}

.sl-correct,
.sf-correct {
  background: var(--success);
  border-color: var(--success);
}

.sl-wrong,
.sf-wrong {
  background: rgba(255, 60, 60, 0.16);
  border-color: var(--error);
}
