/*
 * shared.css — Common styles shared across all MagiBot solver pages.
 * Included by: harvest.html, chest.html, quest.html, trace.html, live.html
 *
 * Key shared components:
 *   .solver-card  — three-column board|history|right-panel layout
 *   .mode-btn     — Solver/Simulator/Simple/Details toggle buttons
 *   .sim-new-btn  — "New game" button in simulator mode
 *   .phase-badge  — colored pill for game phase (quest/trace)
 */

/* ---- Base reset ---- */
* { box-sizing: border-box; }
body {
  font-family: monospace;
  font-size: 14px;
  background: #1a1a1a;
  color: #e8e8e8;
  margin: 0;
  padding: 16px;
}
h1 { color: #f0f0f0; margin-bottom: 4px; font-size: 22px; }

/* ---- Nav bar ---- */
.nav-bar {
  font-size: 13px;
  color: #777;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.nav-bar a {
  color: #aaa;
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid #444;
  border-radius: 4px;
}
.nav-bar a:hover { color: #fff; border-color: #777; background: #2a2a2a; }

/* ---- Collapsible details blocks ---- */
.details-block {
  max-width: 900px;
  margin-bottom: 6px;
  border: 1px solid #333;
  border-radius: 5px;
  background: #1e1e1e;
}
.details-block[open] { border-color: #444; }
.details-block summary {
  cursor: pointer;
  padding: 8px 14px;
  font-size: 13px;
  color: #aaa;
  list-style: none;
  user-select: none;
}
.details-block summary::-webkit-details-marker { display: none; }
.details-block summary::before { content: "▶ "; font-size: 9px; color: #666; }
.details-block[open] summary::before { content: "▼ "; }
.details-block summary:hover { color: #ddd; }
.details-block .details-body {
  padding: 4px 16px 14px 16px;
  font-size: 13px;
  color: #999;
  line-height: 1.65;
  border-top: 1px solid #2e2e2e;
}
.details-block .details-body p { margin: 8px 0 0 0; }
.details-block .details-body p:first-child { margin-top: 0; }
.details-block .details-body strong { color: #ddd; }
.details-block .details-body a { color: #7ab4ff; }
.details-block .details-body code { background: #2a2a2a; padding: 1px 4px; border-radius: 3px; color: #ccc; }
.details-block .details-body ul,
.details-block .details-body ol { margin: 6px 0 0 0; padding-left: 18px; }
.details-block .details-body li { margin-bottom: 4px; }
.details-block .details-body .hi { color: #ddd; }

/* ---- Toggle button (indexing, mode toggles) ---- */
.toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 6px;
  color: #ccc;
  font-family: monospace;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
}
.toggle-btn:hover { background: #333; border-color: #888; }
.toggle-btn.active { background: #1e3a5f; border-color: #3a6aaa; color: #7ab4ff; }

/* ---- Generic button ---- */
.btn {
  background: #2a2a2a;
  border: 1px solid #555;
  color: #ccc;
  padding: 7px 18px;
  border-radius: 5px;
  cursor: pointer;
  font-family: monospace;
  font-size: 13px;
  transition: background 0.1s;
}
.btn:hover { background: #3a3a3a; color: #fff; border-color: #888; }
.btn.primary { background: #2255cc; border-color: #3366dd; color: #fff; }
.btn.primary:hover { background: #3366dd; }

/* ---- Legend ---- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-bottom: 16px;
  font-size: 13px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #ccc;
}
.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  display: inline-block;
  flex-shrink: 0;
}

/* ---- Tabular legend (.legend-table) ---- */
.legend-table {
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.6;
}
.legend-table td {
  padding: 2px 10px 2px 0;
  vertical-align: middle;
  white-space: nowrap;
}
.legend-table td:first-child { padding-right: 6px; }
.legend-table .lt-name { color: #ddd; font-weight: bold; }
.legend-table .lt-val  { color: #aaa; }
.legend-table .lt-desc { color: #666; font-style: italic; white-space: normal; }

/* ---- Three-column solver layout ---- */
.page-wrap { max-width: 1100px; }
.subtitle { color: #777; font-size: 12px; margin-bottom: 12px; }
.intro { margin-bottom: 16px; color: #bbb; line-height: 1.5; }
.intro code { background: #2a2a2a; padding: 1px 4px; border-radius: 3px; color: #ccc; }
.intro p { margin: 0 0 8px 0; }

/*
 * Responsive three-column layout (.solver-card):
 * Desktop (≥820px): board | history | right-panel side by side
 * Mobile (<820px): all panels stacked vertically
 *
 * The board uses clamp() so cells scale from 82px on desktop down to ~52px on phones.
 * The layout also switches from grid to flex-column on small screens.
 *
 * .layout is kept as an alias for .solver-card for backward compatibility.
 */

/* Cell size token — used by .board */
:root {
  --cell-size: clamp(52px, 16vw, 82px);
}

.solver-card,
.layout {
  display: grid;
  grid-template-columns: calc(var(--cell-size) * 5 + 16px) 220px 1fr;
  gap: 20px;
  align-items: flex-start;
}
.left-panel  { flex: 0 0 auto; }
.mid-panel   { min-width: 0; }
.right-panel { min-width: 0; }

/* ---- Mode toggle buttons (Solver/Simulator/Simple/Details) ---- */
.mode-btn {
  padding: 5px 14px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 6px;
  color: #999;
  font-family: monospace;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  user-select: none;
}
.mode-btn:hover { background: #333; border-color: #777; color: #ccc; }
.mode-btn.active {
  background: #1e3a1e;
  border-color: #3a7a3a;
  color: #7aee7a;
  font-weight: bold;
}

/* ---- Simulator "New game" button ---- */
.sim-new-btn {
  padding: 5px 14px;
  background: #1e3a1e;
  border: 1px solid #3a7a3a;
  border-radius: 6px;
  color: #7aee7a;
  font-family: monospace;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s;
}
.sim-new-btn:hover { background: #254825; }

/* ---- Phase badges (quest + trace) ---- */
/* Quest phases */
.phase-search { background: #1e3a5f; color: #7ab4ff; }
.phase-red    { background: #5f1e1e; color: #ff8080; }
.phase-post   { background: #1e4a2a; color: #7aff9a; }
.phase-done   { background: #333;    color: #aaa; }
/* Trace phases */
.phase-avoid   { background: #1e3a5f; color: #7ab4ff; }
.phase-collect { background: #1e4a2a; color: #7aff9a; }

/* ---- Board grid (cells scale with --cell-size) ---- */
.board {
  display: grid;
  grid-template-columns: repeat(5, var(--cell-size));
  grid-template-rows: repeat(5, var(--cell-size));
  gap: 4px;
}
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  position: relative;
  cursor: default;
  transition: filter 0.12s;
  user-select: none;
  overflow: visible;
}
.cell.unrevealed { background: #333; cursor: pointer; }
.cell.unrevealed:hover { filter: brightness(1.35); }
.cell.picker-open { filter: brightness(1.4); z-index: 20; }
.cell.target {
  background: #1e1e1e;
  border: 2px dashed #fff;
  color: #fff;
  cursor: pointer;
}
.cell.target:hover { filter: brightness(1.35); }
.cell.revealed { cursor: default; }
.cell-label { font-size: clamp(14px, 4vw, 18px); font-weight: bold; line-height: 1; }
.cell-overlay {
  font-size: 10px;
  color: rgba(255,255,255,0.85);
  line-height: 1.4;
  text-align: center;
  margin-top: 3px;
  white-space: pre;
}
.cell-overlay.dark { color: rgba(0,0,0,0.75); }

/* ---- Inline colour picker (attached to cell) ---- */
.cell-picker {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: #232323;
  border: 1px solid #666;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.7);
  white-space: nowrap;
}
.cell-picker.open { display: block; }
/* Flip upward for bottom-row cells */
.cell.row-3 .cell-picker,
.cell.row-4 .cell-picker { top: auto; bottom: calc(100% + 6px); }
.cell-picker-title { font-size: 11px; color: #aaa; margin-bottom: 6px; text-align: center; }
.cell-picker-btns { display: flex; gap: 5px; }
.picker-colour-btn {
  width: 36px;
  height: 36px;
  border-radius: 5px;
  border: 2px solid transparent;
  color: #fff;
  font-weight: bold;
  font-size: 12px;
  cursor: pointer;
  font-family: monospace;
  transition: filter 0.1s, border-color 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.picker-colour-btn:hover { filter: brightness(1.25); border-color: #fff; }
.picker-colour-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  filter: none !important;
  border-color: transparent !important;
}
/* Left/right-edge alignment */
.cell.col-0 .cell-picker { left: 0; transform: none; }
.cell.col-4 .cell-picker { left: auto; right: 0; transform: none; }

/* ---- Board controls ---- */
.board-controls {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ---- Below-fold section (legend, details) ---- */
.below-fold {
  margin-top: 24px;
}

/* ---- Recommendation display (used in info-section) ---- */
.rec-header {
  font-size: 11px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 8px;
}

/* ---- State subsection divider inside rec box ---- */
.state-divider {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #2a2a2a;
}
.state-header {
  font-size: 10px;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}
.rec-action {
  font-size: 17px;
  font-weight: bold;
  color: #f0f0f0;
  margin-bottom: 6px;
  line-height: 1.3;
}
.rec-action.none { color: #666; font-size: 14px; font-weight: normal; }
.rec-source { font-size: 11px; color: #666; margin-top: 4px; }
.rec-source.greedy { color: #9a7f30; }
.rec-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: bold;
  color: #fff;
  margin-right: 4px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* ---- Info panel (right column) ---- */
.info-section {
  background: #222;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 10px;
}
.info-section h3 {
  color: #ccc;
  font-size: 12px;
  margin: 0 0 8px 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 10px;
  font-size: 13px;
  color: #ccc;
  margin-bottom: 6px;
}
.stat-grid .label { color: #999; }
.stat-grid .val   { color: #fff; font-weight: bold; }
.phase-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: bold;
  margin-top: 2px;
}
.recommendation {
  font-size: 14px;
  color: #ccc;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #333;
}
.recommendation strong { color: #fff; }
.recommendation.none   { color: #666; font-style: italic; }

/* ---- Overlay toggles (quest / trace) ---- */
.overlay-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.overlay-table td { padding: 4px 0; vertical-align: middle; }
.overlay-table td:first-child { padding-right: 8px; width: 18px; }
.overlay-table tr { cursor: pointer; }
.overlay-table tr:hover .ov-title { color: #fff; }
.ov-title { color: #ddd; font-weight: bold; }
.ov-desc  { color: #888; font-size: 12px; line-height: 1.4; margin-top: 1px; }
input[type=checkbox] { cursor: pointer; accent-color: #4488ff; }

/* ---- History (middle column) ---- */
.history-header {
  color: #999;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.history-kakera {
  font-size: 13px;
  color: #ccc;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid #2a2a2a;
}
.history-kakera .kval { color: #fff; font-weight: bold; }
.history-list {
  font-size: 12px;
  color: #bbb;
  line-height: 1.8;
}
.history-list:empty::after {
  content: "No clicks yet.";
  color: #666;
  font-style: italic;
}
.history-item { border-bottom: 1px solid #2a2a2a; padding: 1px 0; }

/* ---- Sim: game-over state (auto-revealed non-clicked cells) ---- */
.cell.sim-gameover {
  cursor: default !important;
  opacity: 0.55;
  filter: grayscale(0.25);
}

/* ---- Sim: explicitly clicked cell highlight ---- */
.sim-cell-clicked {
  outline: 2px solid #ffffff !important;
  outline-offset: -2px;
  box-shadow: 0 0 6px 2px rgba(255,255,255,0.25);
  opacity: 0.50 !important;
  filter: none !important;
}
.sim-cell-clicked.sim-gameover {
  opacity: 0.80 !important;
}

/* ---- Cell coordinate label (shown when coord toggle is on) ---- */
/* Positioned top-left inside the cell (cell must be position:relative). */
.cell-coord {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 9px;
  color: rgba(255,255,255,0.45);
  line-height: 1;
  pointer-events: none;
  z-index: 1;
}

/* ---- Spinner ---- */
.spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid #444;
  border-top-color: #5599ff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 5px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   RESPONSIVE / MOBILE
   ============================================================ */

/* Tablet: slightly smaller cells; recommendation top-right, history below */
@media (max-width: 900px) {
  :root { --cell-size: clamp(52px, 14vw, 72px); }
  .solver-card,
  .layout {
    grid-template-columns: calc(var(--cell-size) * 5 + 16px) 1fr;
    grid-template-rows: auto auto;
  }
  .right-panel {
    grid-column: 2;
    grid-row: 1;
  }
  .mid-panel {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

/* Phone: single column, cells scale to fit viewport */
@media (max-width: 600px) {
  :root { --cell-size: clamp(48px, calc((100vw - 56px) / 5), 82px); }

  body { padding: 12px; }
  h1 { font-size: 18px; }

  .solver-card,
  .layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .left-panel,
  .mid-panel,
  .right-panel {
    width: 100%;
  }

  /* On mobile: recommendation (right-panel) above click history (mid-panel) */
  .right-panel { order: 1; }
  .mid-panel   { order: 2; }

  /* Make details blocks full-width on phone */
  .details-block { max-width: 100%; }

  /* History list: horizontal scroll guard */
  .history-list { word-break: break-word; }

  /* Make stat-grid less cramped */
  .stat-grid { gap: 4px 12px; }
}
