/* Page basics */
body {
  margin: 0;
  background: #eef2f6;
  color: #14213d;
  font-family:Arial, Helvetica, sans-serif;
  line-height: 1.5;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 14px 40px;
}

h1 { margin: 0; font-size: 2rem; }
h2 { margin-top: 0; font-size: 1.1rem; }
.subtitle { color: #5b6b85; margin-top: 2px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }

/* White boxes that hold each section */
.panel {
  background: white;
  border: 1px solid #c9d3e0;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
}

.info {
  display: flex;
  gap: 5px 24px;
  flex-wrap: wrap;
  font-family: Menlo, Consolas, monospace;
  font-size: 0.9rem;
}

/* Buttons */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

button {
  font: inherit;
  font-size: 0.9rem;
  padding: 5px 11px;
  border: 1px solid #c9d3e0;
  border-radius: 4px;
  background: white;
  color: #14213d;
  cursor: pointer;
}

button:hover { border-color: #14213d; }

/* The currently selected tool is dark */
button.active {
  background: #14213d;
  color: white;
  border-color: #14213d;
}

/* The spectrum canvas stretches to fit the box */
canvas {
  width: 100%;
  height: auto;
  display: block;
  cursor: crosshair;
  border: 1px solid #c9d3e0;
}

.hint {
  margin: 8px 0 0;
  font-size: 0.85rem;
  color: #5b6b85;
}

/* Results text */
#output {
  font-family: Menlo, Consolas, monospace;
  font-size: 0.9rem;
}

#output div { margin-bottom: 4px; }
#output strong { color: #c2185b; }

/* --- Zoom slider --- */
input[type="range"] { width: 140px; vertical-align: middle; }

/* --- Game additions --- */
.row { display: flex; gap: 8px; }
iframe.editor { width: 100%; height: 420px; border: 1px solid #c9d3e0; border-radius: 4px; margin-bottom: 8px; }
#hint-list { padding-left: 20px; }
#btn-hint { margin-top: 6px; }
button:disabled { opacity: 0.5; cursor: default; }
[hidden] { display: none !important; }
#admin-out { width: 100%; height: 220px; font: 0.85rem Menlo, Consolas, monospace; }
.field { display: block; margin-bottom: 8px; }
.field input, .field textarea { width: 100%; font: inherit; padding: 6px; border: 1px solid #c9d3e0; border-radius: 4px; }

/* --- Measurements table --- */
table.results { border-collapse: collapse; margin-bottom: 6px; }
table.results th, table.results td { border: 1px solid #c9d3e0; padding: 3px 12px; text-align: left; }
table.results th { background: #f6f8fb; }

/* --- How to play box and answer reveal --- */
dialog#help { max-width: 560px; width: calc(100% - 28px); border: 1px solid #c9d3e0; border-radius: 8px; padding: 18px 22px; background: white; color: #14213d; font-family:system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; max-height: calc(100vh - 64px); max-height: calc(100dvh - 64px); overflow-y: auto; }
dialog#help::backdrop { background: rgba(20, 33, 61, 0.5); }
dialog#help h2 { margin-top: 0; font-size: 1.4rem; }
dialog#help li { margin-bottom: 6px; }
#btn-solution { margin-left: 8px; margin-top: 6px; padding: 2px 9px; }
#btn-weekly { padding: 2px 9px; }

/* --- Guess grid (Chemdle style): the border colour is the feedback --- */
#guesses { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.slot { aspect-ratio: 300 / 220; border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.slot.empty { border: 2px dashed #c9d3e0; }
.slot.guess { background: white; border: 4px solid #d9534f; padding: 4px; }
.slot.guess.formula { border-color: #e0a100; }
.slot.guess.win { border-color: #2e7d32; }
.slot svg { max-width: 100%; max-height: 100%; height: auto; }

/* --- Solution pop-up --- */
dialog#solution { max-width: 620px; width: calc(100% - 28px); max-height: 90vh; overflow: auto; border: 1px solid #c9d3e0; border-radius: 8px; padding: 18px 22px; background: white; color: #14213d; font-family: Arial, Helvetica, sans-serif; }
dialog#solution::backdrop { background: rgba(20, 33, 61, 0.5); }
dialog#solution h2 { margin-top: 0; font-size: 1.4rem; }
dialog#solution h3 { font-size: 1.05rem; margin: 12px 0 6px; }
#end-structure { text-align: center; }
#end-structure svg { max-width: 100%; height: auto; }
#paper-abstract { font-size: 0.9rem; max-height: 220px; overflow: auto; }
.dialog-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* --- Wordle-style statistics in the solution pop-up --- */
.stats-box { border-top: 1px solid #c9d3e0; margin-top: 14px; padding-top: 4px; }
dialog#solution h4.stats-heading { font-size: 14px; letter-spacing: 0.04em; margin: 12px 0 18px; font-family:Arial, Helvetica, sans-serif; }
dialog#solution h4.stats-heading:has(+ .heat-grid) { margin-top: 25px;}
dialog#solution h4.stats-heading:has(+ .dist) { margin-top: 25px; }
.stats-row { display: flex; justify-content: space-between; gap: 8px; max-width: 420px; }
.stats-cell { flex: 1; text-align: center; }
.stats-num { font-size: 32px; line-height: 1.1; }
.stats-label { font-size: 12px; color: #5b6b85; }
.dist { max-width: 320px; margin: 0px 0 28px 8px; }
.dist-row { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.dist-label { width: 1.4em; text-align: right; font-weight: bold; font-size: 0.8rem; line-height: 1.3; }
.dist-bar { background: #8a96a8; color: white; font-weight: bold; font-size: 0.75rem; line-height: 1.3; text-align: right; padding: 1px 6px; box-sizing: border-box; border-radius: 3px; }
.dist-bar.dist-today { background: #2e7d32; }
.heat-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; max-width: 520px; margin-bottom: 4px; }
.heat-cell { aspect-ratio: 1; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 0.85rem; }
.heat-cell.heat-today { outline: 3px solid #14213d; outline-offset: 1px; }
.heat-guess { text-align: center; font-size: 0.75rem; color: #5b6b85; }
.stats-frozen { font-style: italic; margin-bottom: 6px; }   /* "Your stats right after you finished this puzzle..." note on archive games */

/* --- Scrolling fixes --- */
body { overflow-anchor: none; }   /* stop the browser re-positioning the page when content loads in */
canvas { user-select: none; -webkit-user-select: none; }   /* dragging on the spectrum shouldn't select page text */

/* --- Difficulty rating (sits on its own line in the info box) --- */
.diff-easy { color: #2e7d32; }
.diff-medium { color: #f5cc00; }
.diff-hard { color: #c62828; }

/* --- Touch support (iPhone / iPad) --- */
canvas { touch-action: pan-y; }            /* sideways drags go to the spectrum; up/down swipes still scroll the page */
button { touch-action: manipulation; }     /* no double-tap zoom or tap delay on buttons */
@media (pointer: coarse) {                 /* only on touchscreens: bigger, easier-to-tap buttons */
  button { padding: 9px 14px; }
  #btn-solution, #btn-weekly { padding: 6px 12px; }
  #topnav .navlink { padding: 8px 10px; }
}

/* --- Top-right links: Archive | Suggest | How to play, in one white box --- */
.navbox { margin-left: auto; display: inline-flex; align-items: center; background: white; border: 1px solid #c9d3e0; border-radius: 6px; padding: 1px 4px; }
.navbox .sep { color: #c9d3e0; user-select: none; }
#topnav .navlink { font: inherit; font-size: 0.9rem; color: #14213d; background: none; border: none; border-radius: 4px; margin: 0; padding: 3px 10px; text-decoration: none; cursor: pointer; }
#topnav .navlink:hover { text-decoration: underline; }   /* change to "text-decoration: underline" on .navlink above to always underline */

/* --- Archive pop-up: a calendar for one month --- */
dialog#archive { max-width: 680px; width: calc(100% - 28px); max-height: 90vh; overflow: auto; border: 1px solid #c9d3e0; border-radius: 8px; padding: 18px 22px; background: white; color: #14213d; font-family: Arial, Helvetica, sans-serif; }
dialog#archive::backdrop { background: rgba(20, 33, 61, 0.5); }
.cal-nav { display: flex; justify-content: center; align-items: center; margin: 10px 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-head { text-align: center; font-size: 0.8rem; color: #5b6b85; padding-bottom: 2px; }
.cal-cell { display: flex; flex-direction: column; gap: 1px; min-height: 76px; padding: 3px 6px; border: 3px solid #d5dae1; border-radius: 8px; background: white; color: #14213d; text-decoration: none; font-size: 11px; line-height: 1.25; overflow: hidden; }
a.cal-cell:hover { box-shadow: 0 0 0 1px rgba(20, 33, 61, 0.25); }
.cal-cell .cal-date { align-self: flex-start; font-size: 11px; color: #5b6b85; }
.cal-cell .cal-num { font-weight: bold; font-size: 14px; }
.cal-cell .cal-status { font-size: 10.5px; color: #5b6b85; }
.cal-cell.cal-today .cal-date { background: #14213d; color: white; border-radius: 9px; padding: 0 6px; }
.cal-cell.cal-empty { border: 1px solid #edf0f4; background: #f8fafc; }
.cal-cell.cal-empty .cal-date { color: #b4bdca; }
.cal-blank { min-height: 0; }
/* pastel outlines: grey = not played, yellow = in progress, green = solved, red = not solved */
.cal-notplayed { border-color: #d5dae1; }
.cal-progress { border-color: #f5dd7a; }
.cal-won { border-color: #a8d8aa; }
.cal-lost { border-color: #f1a9a4; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 12px; font-size: 0.8rem; color: #5b6b85; }
.legend-box { display: inline-block; width: 13px; height: 13px; border-width: 3px; border-style: solid; border-radius: 3px; background: white; box-sizing: border-box; margin-right: 5px; vertical-align: -2px; }
@media (max-width: 520px) {
  .cal-grid { gap: 3px; }
  .cal-cell { min-height: 56px; padding: 2px 3px; border-width: 2px; font-size: 9px; }
  .cal-cell .cal-num { font-size: 11px; }
  .cal-cell .cal-status { font-size: 8px; }
}

/* --- "What's new" pop-up --- */
dialog#updates { max-width: 480px; width: calc(100% - 28px); max-height: 90vh; overflow: auto; border: 1px solid #c9d3e0; border-radius: 8px; padding: 18px 22px; background: white; color: #14213d; font-family: Arial, Helvetica, sans-serif; }
dialog#updates::backdrop { background: rgba(20, 33, 61, 0.5); }
dialog#updates h2 { font-size: 1.4rem; }
dialog#updates li { margin-bottom: 6px; }

/* --- Weekly challenges list in the archive --- */
#archive-weekly h3 { margin: 18px 0 6px; font-size: 1rem; }
#archive-weekly-list { display: flex; flex-direction: column; gap: 6px; }
.weekly-item { display: flex; gap: 14px; align-items: center; padding: 8px 12px; border-width: 3px; border-style: solid; border-radius: 8px; color: #14213d; text-decoration: none; font-size: 0.9rem; }
.weekly-item:hover { box-shadow: 0 0 0 1px rgba(20, 33, 61, 0.25); }
.weekly-item .num { font-weight: bold; }
.weekly-item .dates { color: #5b6b85; }
.weekly-item .status { margin-left: auto; color: #5b6b85; font-size: 0.85rem; }

/* --- "Update Log" link at the bottom of the page --- */
.footer-row { text-align: right; margin-top: 4px; }
.footer-link { border: none; background: none; padding: 2px 0; font-size: 0.85rem; color: gray; text-decoration: underline; cursor: pointer; }

/* --- Keep the page from showing a focus outline when we hand it keyboard focus --- */
body:focus { outline: none; }
