/* Bare-bones on purpose: black and white only. Design comes last. */

body {
  font-family: sans-serif;
  -webkit-tap-highlight-color: transparent;   /* no blue flash when tapping on phones */
  margin: 8px;
  color: #000;
  background: #fff;
}

header {                          /* title on the left, Check / Reveal on the right */
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
}
h1 { font-size: 1.2em; margin: 0; }
#title {                          /* the title is a menu button, but looks like a plain title */
  font: inherit;
  font-weight: bold;
  color: #000;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
#title-menu { left: 0; min-width: 14em; }
#title-menu h2 { font-size: 0.9em; margin: 8px 10px 4px; }
#title-menu a { display: block; padding: 8px 10px; color: #000; text-decoration: none; }
#title-menu a:hover { background: #ddd; }
#title-menu hr { margin: 4px 0; border: 0; border-top: 1px solid #ccc; }
#timer {                          /* between the title and Clues (phone) / the menus (PC) */
  font: inherit;
  font-variant-numeric: tabular-nums;   /* digits don't jiggle as they change */
  min-width: 3.5em;
  padding: 4px 8px;
  color: #000;
  background: #fff;
  border: 1px solid #000;
  cursor: pointer;
}
#status { margin: 0 0 6px; font-weight: bold; }
#status:empty { display: none; }

/* ---------------------------------------------------------------- Check / Reveal menus */
header { flex-wrap: wrap; }
#tools {
  display: flex;
  flex-wrap: wrap;                /* narrow phones: the buttons wrap onto a second row */
  justify-content: flex-end;
  gap: 6px;
  align-items: center;
  margin-left: auto;
}
#tools button, #stats-button {
  font: inherit;
  color: #000;
  background: #fff;
  border: 1px solid #000;
  padding: 4px 8px;
  cursor: pointer;
}
.menu { position: relative; }
.menu-items {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 10;
  display: flex;
  flex-direction: column;
  min-width: 10em;
  background: #fff;
  border: 1px solid #000;
}
.menu-items[hidden] { display: none; }
#tools .menu-items button { border: 0; text-align: left; padding: 8px 10px; }
#tools .menu-items button:hover { background: #ddd; }
.menu-items p { margin: 8px 10px; }
h2 { font-size: 1em; margin: 0 0 4px; }
#message:empty { display: none; }

/* ---------------------------------------------------------------- grid */
#board {
  display: flex;
  flex-direction: column;
}

#grid-viewport {                  /* keeps the grid's normal size; a zoomed grid is cut off at its edges */
  width: fit-content;
  overflow: hidden;
  touch-action: manipulation;     /* no double-tap zoom on the page */
}
#grid-viewport.zoomed { cursor: grab; }
#grid-viewport.zoomed .square { cursor: grab; }
#grid-viewport.dragging, #grid-viewport.dragging * { cursor: grabbing; }
body.touch #grid-viewport { touch-action: none; }   /* pinch and drag zoom the grid, not the page */

#grid {
  position: relative;             /* squares' positions are measured from the grid (zoom.js) */
  transform-origin: 0 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--square));
  gap: 1px;                       /* the black lines between squares */
  background: #000;
  border: 1px solid #000;
  width: fit-content;
  user-select: none;
  -webkit-user-select: none;
}

.square {
  position: relative;
  width: var(--square);
  height: var(--square);
  background: #fff;
  cursor: pointer;
}
.square.black { background: #000; cursor: default; }
.square.locked .letter { font-weight: bold; }          /* checked correct, or revealed */
.square.wrong::after {                                  /* wrong: a diagonal line */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top right, transparent 47%, #000 48%, #000 52%, transparent 53%);
  pointer-events: none;
}
.square.revealed::before {                              /* revealed: a corner triangle */
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  border-top: calc(var(--square) * 0.3) solid #000;
  border-left: calc(var(--square) * 0.3) solid transparent;
}
.square.in-entry { background: #ddd; }
.square.selected { background: #999; }

.number {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: calc(var(--square) * 0.28);
  line-height: 1;
}
.letter {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: calc(var(--square) * 0.12);
  font-size: calc(var(--square) * 0.58);
}

/* ---------------------------------------------------------------- clue bar */
#clue-bar {
  position: relative;
  padding: 6px;
  margin: 6px 0;
  border: 1px solid #000;
  background: #fff;
  min-height: 1.3em;
  cursor: pointer;
}
#clue-bar-text { white-space: pre; }   /* keep the gap after the clue number */

/* ---------------------------------------------------------------- clue lists */
#lists section { min-width: 0; }

#lists ol {
  position: relative;             /* so the lists can jump to the current clue */
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
}

#lists li {
  padding: 3px 6px;
  cursor: pointer;
}
#lists li.current { background: #ddd; }

/* ---------------------------------------------------------------- hints */
.type-icon {                      /* 32x14 pixel art, shown at double size */
  width: 64px;
  height: 28px;
  image-rendering: pixelated;
  vertical-align: middle;
  margin-right: 2px;
}
#lists .type-icon { width: 48px; height: 21px; }
.picture {                        /* stand-in for a segment picture */
  display: inline-block;
  min-width: 2.6em;
  padding: 4px 2px;
  border: 1px solid #000;
  text-align: center;
  vertical-align: middle;
  line-height: 1;
}
.hint-button {
  font: inherit;
  font-size: 0.8em;
  margin-left: 6px;
  padding: 0 6px;
  color: #000;
  background: #fff;
  border: 1px solid #000;
  cursor: pointer;
}
.hint-button[hidden] { display: none; }
#tools button:disabled { color: #999; border-color: #999; cursor: default; }
#lists li.crossing .clue::after { /* the crossing clue's little rectangle */
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 0.9em;
  margin-left: 0.5em;
  vertical-align: middle;
  background: #999;
}

/* ---------------------------------------------------------------- PC: clues to the right */
@media (min-width: 800px) {
  #player {
    display: flex;
    gap: 16px;
    align-items: flex-start;
  }
  #lists {
    flex: 1;                      /* the lists take whatever width the grid leaves */
    display: flex;
    gap: 16px;
  }
  #lists section { flex: 1; }
  #lists ol { max-height: calc((var(--square) + 1px) * var(--cols) - 1em); }
}

/* ---------------------------------------------------------------- narrow PC window: clues below */
@media (max-width: 799px) {
  #lists {
    display: flex;
    gap: 8px;
    margin-top: 8px;
  }
  #lists section { flex: 1; }
  #lists ol { max-height: 40vh; }
}

/* ---------------------------------------------------------------- touch screens only */
body.touch {
  --keyboard-height: calc(200px + env(safe-area-inset-bottom));
  padding-bottom: var(--keyboard-height);   /* keep the page clear of the keyboard */
}

#clues-button, #previous-entry, #next-entry, #keyboard { display: none; }

body.touch #clues-button,
body.touch #previous-entry,
body.touch #next-entry { display: block; }

/* touch: title and Clues on the top row, the menus on the row below, grid centred */
body.touch #clues-button { margin-left: auto; padding: 4px 8px; }
body.touch #stats-button { margin-left: auto; }   /* phone: Stats sits just before Clues, */
body.touch #stats-button:not([hidden]) + #clues-button { margin-left: 6px; }   /* keeping two rows */
body.touch #tools { width: 100%; justify-content: flex-end; }
body.touch #grid-viewport { margin: 0 auto; }
body.touch .type-icon { width: 48px; height: 21px; }     /* smaller icons on phones */
body.touch #lists .type-icon { width: 32px; height: 14px; }

body.touch button {
  font: inherit;
  color: #000;
  background: #fff;
  border: 1px solid #000;
  touch-action: manipulation;
}

body.touch #clue-bar {            /* below the grid: ‹ clue › */
  order: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0;
}
body.touch #clue-bar { height: 4.6em; }    /* fixed, so the grid never has to resize */
body.touch #clue-bar-text {
  flex: 1;
  max-height: 100%;
  overflow-y: auto;               /* a very long clue scrolls inside the bar */
  padding: 4px 0;
  white-space: pre-wrap;
}
body.touch #previous-entry,
body.touch #next-entry { border: 0; font-size: 1.6em; padding: 0 12px; }
body.touch #lists li.crossing .clue::after { display: none; }

/* the keyboard, and the clue lists that can take its place */
body.touch #keyboard,
body.touch.show-clues #lists {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--keyboard-height);
  padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid #000;
  box-sizing: border-box;
}
body.touch #keyboard { display: block; }
body.touch #lists { display: none; }
body.touch.show-clues #keyboard { display: none; }
body.touch.show-clues #lists { display: flex; gap: 8px; margin: 0; }
body.touch.show-clues #lists section { flex: 1; display: flex; flex-direction: column; }
body.touch.show-clues #lists ol { max-height: none; flex: 1; }

/* ---------------------------------------------------------------- stats popup */
.popup {                          /* dims the page behind the box */
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
}
.popup[hidden] { display: none; }
.stats-box {
  box-sizing: border-box;
  position: relative;
  max-width: min(26em, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 16px 20px;
  background: #fff;
  border: 1px solid #000;
}
.stats-box h2 { font-size: 1.3em; margin: 0 0 12px; }
.popup-close {
  position: absolute;
  top: 8px;
  right: 8px;
  font: inherit;
  color: #000;
  background: #fff;
  border: 0;
  cursor: pointer;
}
#stats-list { margin: 0; }
.code-box { width: 100%; box-sizing: border-box; font: 0.8em monospace; word-break: break-all; }
.dialog-buttons { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.dialog-buttons button { font: inherit; padding: 6px 12px; color: #000; background: #fff; border: 1px solid #000; }
.dialog-note { min-height: 1.2em; }
#stats-list dt { font-weight: bold; margin-top: 10px; }
#stats-list dd { margin: 0; }
#stats-list dd.everyone { font-size: 0.85em; color: #555; }

.key-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 4px;
}
.key {
  flex: 1;
  max-width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1.2em;
  user-select: none;
  -webkit-user-select: none;
}
.key.wide { flex: 1.5; max-width: 66px; font-size: 1em; }
.key.blank { visibility: hidden; }              /* keeps the digits layout's keys in place */
.key-row.arrows .key { height: 32px; max-width: 72px; }   /* the slim arrow row */
.key:active { background: #999; }

/* ---------------------------------------------------------------- archive page */
#archive a { flex: 1; padding: 10px 4px; color: #000; text-decoration: none; }
#archive a:hover { background: #eee; }
.archive-mark { padding: 10px 8px; min-width: 1.5em; text-align: center; }
#archive-header { flex-wrap: wrap; justify-content: flex-start; gap: 8px 16px; }
#archive-header h1 { margin-right: auto; }
#jump { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#jump input { font: inherit; padding: 2px 4px; border: 1px solid #000; }
#jump-message { font-size: 0.85em; }
#random { color: #000; }
#random.disabled { color: #888; text-decoration: none; }
#archive-view { position: relative; display: flex; align-items: flex-start; }
#archive { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; flex: 1; }
#archive::-webkit-scrollbar { display: none; }
.archive-column { list-style: none; padding: 0 12px 0 0; margin: 0; flex: 0 0 min(22em, 100%);
                  box-sizing: border-box; scroll-snap-align: start; }
.archive-column li { display: flex; justify-content: space-between; border-bottom: 1px solid #ccc; }
.archive-column li.flash { animation: flash 3.2s; }
@keyframes flash { 0%, 60% { background: #ccc; } 100% { background: transparent; } }
.column-arrow { font: inherit; font-size: 1.6em; background: #fff; border: 1px solid #000; padding: 0 8px; }
body.archive-page #keyboard {     /* the number pad (touch screens only) */
  display: none; position: fixed; left: 0; right: 0; bottom: 0; padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid #000;
}
body.archive-page.number-pad #keyboard { display: block; }
body.archive-page.number-pad { padding-bottom: 170px; }
@media (max-width: 600px) {       /* phones: the jump row under the title row */
  #archive-header h1 { flex: 1 0 auto; margin-right: 0; }
  #jump { order: 3; flex: 1 0 100%; }
}
