/* The app lock (docs/app-lock-brief.md): the lock screen, the snake board and the corner pad
   (js/views/lock.js), the App lock section of Settings and its set-up (js/views/lock-settings.js),
   and the Lock button in the sidebar and the More menu.

   The board is the one bold thing: the snake game's grid of rounded squares and a calm blue
   snake, one thick rounded body with a slightly larger head whose eyes look the way it goes.
   Everything around it is the plain dashboard: white panels with a 1px rule, Exchange blue only
   for the snake, the current step and actions. Plain ASCII only. */

/* -------------------------------------------------------------------- tokens */
:root {
  --lock-tile: var(--mist);          /* the board's squares and the corner buttons */
  --lock-tile-line: var(--rule);
  --lock-tile-hover: #E8ECF2;
  --lock-under: var(--accent-tint);  /* a square the snake lies on, a corner as it is tapped */
  --lock-snake: var(--accent-fill);  /* Exchange blue */
  --lock-eye: #FFFFFF;
  --lock-pupil: #0E1726;
  --lock-dot: var(--ink);
}
:root[data-theme="dark"] {
  --lock-tile: #1B2433;
  --lock-tile-line: #2A3547;
  --lock-tile-hover: #222D3F;
  --lock-under: #1C2742;
}

/* ------------------------------------------------------------- the lock screen */
/* No shell: the page centres one column like Sign in, wide enough on a computer for the two
   steps side by side. */
body.signed-out main:has(> .lock-screen) { margin-right: auto; margin-left: auto; }
.lock-screen { max-width: 460px; margin: 0 auto; padding: 8px 0 0; }
@media (min-width: 760px) { .lock-screen { max-width: 760px; padding-top: 4vh; } }
.lock-head { display: flex; align-items: center; gap: 14px; min-height: 48px; }
.lock-head .logo-mark { display: block; flex: none; width: 40px; height: 40px; }
.lock-title { margin: 0; font-family: var(--font-display); font-size: 28px; font-weight: 700; line-height: 1.15; }
.lock-title:focus { outline: none; }
@media (min-width: 760px) {
  .lock-head { gap: 16px; }
  .lock-head .logo-mark { width: 44px; height: 44px; }
  .lock-title { font-size: 36px; }
}
.lock-intro { max-width: 30em; margin: 10px 0 0; color: var(--slate); font-size: 18px; line-height: 1.45; }
.lock-message { margin: 16px 0 0; }
.lock-message:empty { display: none; }
.lock-message-text { padding: 12px 16px; border-radius: 8px; font-weight: 700; }
.lock-message-text.bad { background: var(--bad-pale); color: var(--bad); }
.lock-message-text.warn { background: var(--warn-pale); color: var(--warn-text); }

.lock-steps { display: grid; gap: 16px; margin-top: 20px; }
@media (min-width: 760px) {
  .lock-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
}

/* A step: a white panel. The one to do now has a 2px line in Exchange blue. */
.lock-step { min-width: 0; padding: 16px; border: 1px solid var(--rule); border-radius: 12px; background: var(--paper); }
.lock-step.is-current { padding: 15px; border: 2px solid var(--accent); }
@media (min-width: 720px) {
  .lock-step { padding: 20px; }
  .lock-step.is-current { padding: 19px; }
}
.lock-step-title { margin: 0; font-size: 18px; line-height: 1.3; }
.lock-step.is-waiting .lock-step-title { color: var(--slate); }
.lock-hint { margin: 4px 0 14px; color: var(--slate); font-size: 14px; }
.lock-hint.text-warn { color: var(--warn-text); font-weight: 700; }
.lock-keys { display: none; margin: 10px 0 0; color: var(--slate); font-size: 14px; }
.lock-board:focus-visible ~ .lock-keys { display: block; }
.lock-keys-pad { display: none; }
@media (hover: hover) and (pointer: fine) { .lock-keys-pad { display: inline; } }
.lock-redraw { margin: 6px 0 -8px; }
.lock-step.is-waiting .lock-pad { opacity: 0.55; }
.lock-pad-actions { margin-top: 16px; }
.lock-pad-actions .btn { flex: 1 1 0; min-width: 0; }
.lock-step-2 .lock-pad-actions { max-width: 288px; }
.lock-forgot { margin: 20px 0 0; }
.lock-forgot .btn-link { text-align: left; }

/* On a phone one step at a time: before the snake is drawn, step 2 is only its title; after,
   the board folds into a small picture beside its title and Redraw, and the pad takes the room. */
@media (max-width: 759px) {
  .lock-screen.at-2 .lock-intro { display: none; }
  .lock-step-2.is-waiting .lock-step-body { display: none; }
  .lock-step-1.is-done {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    grid-template-areas: "board title" "board hint" "board redraw";
    column-gap: 14px;
    align-items: center;
  }
  .lock-step-1.is-done .lock-step-title { grid-area: title; align-self: end; }
  .lock-step-1.is-done .lock-hint { grid-area: hint; margin: 2px 0 0; }
  .lock-step-1.is-done .lock-redraw { grid-area: redraw; margin: -4px 0 -8px; }
  .lock-step-1.is-done .lock-board { grid-area: board; align-self: start; width: 64px; border-radius: 8px; pointer-events: none; }
  .lock-step-1.is-done .lock-keys { display: none; }
}

/* A wrong try: one short shake, none with reduced motion. */
@keyframes lock-shake {
  0%, 100% { transform: none; }
  18% { transform: translateX(-10px); }
  38% { transform: translateX(9px); }
  58% { transform: translateX(-6px); }
  78% { transform: translateX(3px); }
}
.lock-screen.is-shaking .lock-steps { animation: lock-shake 0.4s ease-in-out; }

/* ------------------------------------------------------------- the snake board */
/* One focusable control. touch-action: none keeps the page still while a finger draws. */
.lock-board {
  position: relative;
  width: min(100%, 320px);
  aspect-ratio: 1;
  border-radius: 12px;
  touch-action: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.lock-board:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.lock-board-svg { display: block; width: 100%; height: 100%; }
.lock-cell { fill: var(--lock-tile); stroke: var(--lock-tile-line); stroke-width: 2; }
.lock-cell.on { fill: var(--lock-under); stroke: none; }
@media (hover: hover) { .lock-cell:not(.on):hover { fill: var(--lock-tile-hover); } }
.lock-board:focus-visible .lock-cell.cursor { stroke: var(--accent); stroke-width: 6; }
.lock-body { fill: none; stroke: var(--lock-snake); stroke-linecap: round; stroke-linejoin: round; }
.lock-head-shape { fill: var(--lock-snake); }
.lock-head-in { transform-box: fill-box; transform-origin: center; }
.lock-eye { fill: var(--lock-eye); }
.lock-pupil { fill: var(--lock-pupil); }

/* -------------------------------------------------------------- the corner pad */
/* Four quarter shapes round a middle that shows the taps. Each corner is far larger than 72px:
   the pad is up to 288px square. */
.lock-pad {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 288px);
  aspect-ratio: 1;
}
.lock-corner {
  position: relative;
  min-width: 72px;
  min-height: 72px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--rule-btn);
  border-radius: 10px;
  background: var(--lock-tile);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.lock-corner-1 { grid-area: 1 / 1; border-top-left-radius: 48px; }
.lock-corner-2 { grid-area: 1 / 2; border-top-right-radius: 48px; }
.lock-corner-3 { grid-area: 2 / 2; border-bottom-right-radius: 48px; }
.lock-corner-4 { grid-area: 2 / 1; border-bottom-left-radius: 48px; }
@media (hover: hover) { .lock-corner:not(:disabled):hover { border-color: var(--rule-strong); background: var(--lock-tile-hover); } }
.lock-corner:not(:disabled):active { border-color: var(--accent); background: var(--lock-under); }
.lock-corner:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lock-corner:disabled { cursor: not-allowed; }
.lock-corner-glow { position: absolute; inset: 0; background: var(--lock-under); opacity: 0; pointer-events: none; }
/* In the set-up the corners carry their numbers, clockwise from the top left. */
.lock-corner-n {
  position: absolute;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}
.lock-corner-1 .lock-corner-n { top: 20%; left: 22%; }
.lock-corner-2 .lock-corner-n { top: 20%; right: 22%; }
.lock-corner-3 .lock-corner-n { right: 22%; bottom: 20%; }
.lock-corner-4 .lock-corner-n { bottom: 20%; left: 22%; }

/* The middle: a round window over the four corners. One dot per tap, never which corner; in the
   set-up, the digits. At least four places show, empty until tapped. */
.lock-pad-middle {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 46%;
  aspect-ratio: 1;
  border: 8px solid var(--paper);
  border-radius: 50%;
  background: var(--paper);
  transform: translate(-50%, -50%);
}
.lock-pad-middle::before { content: ""; position: absolute; inset: 0; border: 1px solid var(--rule); border-radius: 50%; }
/* Four to a row, a second row centred under the first. */
.lock-slots { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 9px; max-width: 75px; }
.lock-slot { display: block; width: 12px; height: 12px; border-radius: 50%; }
.lock-slot-empty { border: 2px solid var(--rule-strong); }
.lock-slot-dot { background: var(--lock-dot); }
.lock-pad-digits .lock-slots { gap: 2px 6px; max-width: 82px; }
.lock-slot-digit {
  width: 16px;
  height: auto;
  text-align: center;
  border-radius: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
}

/* ------------------------------------------------------------- Settings, App lock */
.lockset-now { max-width: 44em; }
.lockset-actions { margin-top: 16px; }
.lockset-after, .lockset-offrow { margin: 20px 0 0; padding-top: 16px; border-top: 1px solid var(--rule); }
.lockset-after .field { margin-bottom: 0; }
.lockset-after .actions { margin-top: 12px; }
.lockset-offrow .actions { margin-top: 10px; }
.lockset legend { margin: 0 0 4px; font-weight: 700; }
.lockset-choices { gap: 0 28px; }
@media (min-width: 720px) { .lockset-choices { grid-template-columns: repeat(4, max-content); } }
.lockset-off { max-width: 40em; }
.lockset-off + .lockset-off { margin-top: 6px; }
.lockset-off + .actions { margin-top: 16px; }

/* The set-up: one step at a time, the board or the pad beside the words on wide screens. */
.lockset-flow { margin-top: 4px; padding-top: 16px; border-top: 1px solid var(--rule); scroll-margin-top: 72px; }
@media (min-width: 960px) { .lockset-flow { scroll-margin-top: 88px; } }
.lockset-progress { display: flex; gap: 6px; margin: 0 0 14px; padding: 0; list-style: none; }
.lockset-progress > li {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--rule-btn);
  border-radius: 8px;
  background: var(--paper);
  color: var(--slate);
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}
.lockset-progress > li.is-done { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.lockset-progress > li[aria-current="step"] { border-color: var(--accent-fill); background: var(--accent-fill); color: var(--on-accent); }
.lockset-grid { display: grid; gap: 16px; }
.lockset-head, .lockset-input, .lockset-foot { min-width: 0; }
.lockset-foot .lockset-buttons { margin-top: 12px; }
@media (min-width: 720px) {
  .lockset-grid {
    grid-template-columns: 320px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "input head" "input foot";
    gap: 12px 28px;
    align-items: start;
  }
  .lockset-grid.is-plain { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; grid-template-areas: "head"; }
  .lockset-input { grid-area: input; }
  .lockset-head { grid-area: head; }
  .lockset-foot { grid-area: foot; }
}
.lockset-step-title { margin: 0 0 6px; font-size: 18px; line-height: 1.3; }
.lockset-head > p + p { margin-top: 8px; }
.lockset-head .hint { margin-top: 8px; }
.lockset-numbering { padding: 10px 14px; border-radius: 8px; background: var(--accent-tint); }
.lockset-status { font-weight: 700; }
.lockset-status.ok { color: var(--ok); }
.lockset-status.bad { color: var(--bad); }
.lockset-status.warn { color: var(--warn-text); }
.lockset-status:empty { display: none; }
.lockset-buttons { margin-top: 16px; }
.lockset-error { margin-top: 16px; }
.lockset-summary { margin: 0 0 12px; }
.lockset-code { font-family: var(--font-display); font-size: 22px; font-weight: 700; white-space: nowrap; }

/* ------------------------------------------------------------------- the shell */
/* The Lock button: below Help in the sidebar, and last in the phone's More menu. */
.side-link.side-lock { width: 100%; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; }
.side-link.side-lock:hover { background: var(--hover); }
.more-menu .more-lock {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.more-menu .more-lock .glyph { color: var(--slate); }
.more-menu .more-lock:hover { background: var(--hover); color: var(--ink); }

/* -------------------------------------------------------------------- motion */
@media (prefers-reduced-motion: reduce) {
  .lock-screen.is-shaking .lock-steps { animation: none; }
}
