* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  overscroll-behavior: none;
}

body {
  font-family: Georgia, 'Times New Roman', serif;
  background: #dcdcdc;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

/* Overrides the body-wide user-select: none (needed for the drag game) so
   error text like "Could not connect to server." can still be copied. */
.selectable-text {
  user-select: text;
  -webkit-user-select: text;
}

/* Re-enable scrolling inside the help modal */
#help-body {
  touch-action: pan-y;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;                      /* fallback before JS runs */
  height: calc(var(--vh, 1vh) * 100); /* JS-measured true visible height */
  overflow: hidden;
}

#header, #score-bar, #build-panel, #keyboard-area {
  flex-shrink: 0;       /* these must keep their natural height */
}

#phrase-area {
  min-height: 0;        /* allow flex to compress it when needed */
}

.hidden { display: none !important; }

/* ---- Header ---- */

#header {
  display: flex;
  align-items: center;
  padding: 0.45rem 1rem;
  background: #1a5fb4;
  box-shadow: 0 2px 6px rgba(0,0,0,0.22);
  flex-shrink: 0;
}

/* Fills the space between the header's left edge and the button group,
   so the title is centered in that gap rather than flush against the
   left edge. */
#header-title-wrap {
  flex: 1;
  text-align: center;
}

#header-title {
  display: block;
  font-family: Georgia, serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.05em;
}

#header-date {
  display: block;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.75rem;
  font-weight: 400;
  color: #dceaff;
}

#header-btns {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  flex-shrink: 0;
}

#header-btns button {
  padding: 0.3rem 0.95rem;
  background: #fff;
  border: 1px solid #0d3d7a;
  border-radius: 5px;
  color: #1a5fb4;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.83rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

#header-btns button:hover {
  background: #dceaff;
}

#header-btns button:disabled {
  background: #eee;
  border-color: #bbb;
  color: #999;
  cursor: not-allowed;
}
#header-btns button:disabled:hover { background: #eee; }

/* ---- Hamburger menu (Archive, mode toggle, Recap, Help, Feedback) ---- */

#menu-wrap {
  position: relative;
}

#menu-btn {
  font-size: 1.05rem;
  line-height: 1;
  padding: 0.3rem 0.7rem;
}

#menu-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.4rem;
  display: flex;
  flex-direction: column;
  min-width: 170px;
  background: #fff;
  border: 1px solid #0d3d7a;
  border-radius: 6px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.28);
  overflow: hidden;
  z-index: 40;
}
#menu-dropdown.hidden { display: none; }

#menu-dropdown button {
  padding: 0.55rem 1rem;
  border: none;
  border-bottom: 1px solid #eee;
  border-radius: 0;
  text-align: left;
  white-space: nowrap;
}
#menu-dropdown button:last-child { border-bottom: none; }

.menu-divider {
  border-top: 2px solid #999;
}

/* Hint button — solid amber signals it spends points */
#hint-btn {
  background: #f0a30a !important;
  border-color: #a86c00 !important;
  color: #402400 !important;
}
#hint-btn:hover {
  background: #d98f00 !important;
}

/* ---- Mode display ---- */

#mode-display {
  text-align: center;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.72rem;
  color: #222;
  padding: 3px 0 2px;
  flex-shrink: 0;
}

/* ---- Phrase area ---- */

#phrase-area {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-end; /* sit lower in the available space, closer to the keyboard */
  justify-content: center;
  padding: 0.75rem 1.5rem 0.5rem;
  overflow: hidden;
}

/* First-use intro box — sits over the phrase area on desktop (enough room
   to show both at once); becomes a full-screen popup on phones, where
   there isn't. */
#first-use-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
#first-use-overlay.hidden { display: none; }

#first-use-box {
  position: relative;
  background: #fff;
  border: 1px solid #d5deea;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  padding: 1.5rem 2rem;
  max-width: min(420px, 92%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.6rem;
  font-family: Arial, Helvetica, sans-serif;
}

#first-use-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  font-size: 1.2rem;
  color: #888;
  cursor: pointer;
  padding: 4px;
}
#first-use-close:hover { color: #333; }

#first-use-headline {
  font-size: 1.3rem;
  font-weight: 700;
  color: #1a1a1a;
  margin: 0;
}

#first-use-subtext {
  font-size: 1.05rem;
  color: #555;
  margin: 0;
}

#first-use-buttons {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.4rem;
}
#first-use-buttons button {
  padding: 0.55rem 1.4rem;
  border-radius: 20px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: #eaf2fb;
  border: 1px solid #a9c8e8;
  color: #1a5fb4;
}
#first-use-buttons button:hover { background: #d8e8f8; }

@media (max-width: 520px) {
  #first-use-overlay {
    position: fixed;
    background: rgba(0,0,0,0.45);
    z-index: 2000; /* below Help/Demo's 3000, so they layer on top rather than under */
  }
}

#phrase {
  max-width: 860px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 38px;  /* starting size — overridden by scalePhraseFont() */
  line-height: 1.8;
  text-align: center;
  word-spacing: 0.25em;
  letter-spacing: 0.05em;
}

.word {
  display: inline;
  white-space: nowrap;
}

.word.incomplete {
  background: #fff2b3;
  border-radius: 4px;
  padding: 0 2px;
}

.letter {
  display: inline;
  transition: color 0.25s;
}

.word.incomplete .letter.original {
  color: #1a1a1a;
}

.word.incomplete .letter.inserted {
  color: #1a5fb4;
}

.word.complete {
  background: #bbdefb;
  border-radius: 4px;
  padding: 0 2px;
}

.word.complete .letter,
.word.complete .letter.original,
.word.complete .letter.inserted {
  color: #000;
}

.sep {
  display: inline;
  color: #1a1a1a;
}

/* Complete word visually joined to an incomplete word via apostrophe/hyphen —
   keep it yellow (like its incomplete partner) instead of blue.
   Needs 3 classes to out-specificity the plain .word.complete rule. */
.word.complete.connected-incomplete { background: #fff2b3; }

/* Separators (spaces and punctuation runs): yellow while attached word(s)
   are incomplete, blue once they're all complete */
.sep-pending { background: #fff2b3; }
.sep-done { background: #bbdefb; }

/* ---- Score bar ---- */

#score-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.4rem;
  padding: 0.6rem 0 0.2rem;
  font-family: Arial, Helvetica, sans-serif;
}

#scratchpad-wrong-msg {
  text-align: center;
  color: #c00;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  padding-bottom: 0.2rem;
}
#scratchpad-wrong-msg.hidden { display: none; }

#scratchpad-dropbox.drag-over {
  border-color: #1a5fb4;
  background: #e3edfa;
}

.scratch-word-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 5000;
  background: #fff2b3;
  border: 1px solid #d4b106;
  border-radius: 4px;
  padding: 3px 10px;
  font-family: Georgia, serif;
  font-size: 1rem;
  font-weight: 700;
  color: #1a1a1a;
  box-shadow: 0 3px 8px rgba(0,0,0,0.25);
  white-space: nowrap;
}

#score-display {
  font-size: 1.4rem;
  font-weight: 700;
  color: #1a1a1a;
  min-width: 120px;
  text-align: center;
}

#last-penalty {
  font-size: 1.1rem;
  font-weight: 700;
  color: #c0392b;
  min-width: 40px;
  text-align: right;
  transition: opacity 0.3s;
}

#last-award {
  font-size: 1.1rem;
  font-weight: 700;
  color: #27ae60;
  min-width: 40px;
  text-align: left;
  transition: opacity 0.3s;
}

/* ---- Keyboard ---- */

#keyboard-area {
  padding: 0.75rem 0 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: #cfcfcf;
  border-top: 1px solid #b8b8b8;
}

/* ---- Build panel ---- */

#build-panel {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0.3rem 0 0.5rem;
}

#build-box {
  min-width: 46px;
  min-height: 40px;
  border: 2px dashed #bbb;
  border-radius: 6px;
  background: #fff2b3;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: #000;
  padding: 4px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  letter-spacing: 0.08em;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  cursor: default;
}

#build-box.has-content {
  border: 2px solid #1a5fb4;
  background: #fff2b3;
  color: #000;
  cursor: grab;
}

#build-btn {
  padding: 0.3rem 0.7rem;
  background: #fff;
  border: 1px solid #999;
  border-radius: 5px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.78rem;
  color: #111;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

#build-btn:hover { background: #e8e0d5; }

#build-btn.cancel-mode {
  border-color: #c0392b;
  color: #c0392b;
}

.kb-row {
  display: flex;
  gap: 6px;
}

.key {
  width: 46px;
  height: 58px;
  border-radius: 5px;
  border: none;
  background: #fff2b3;
  box-shadow: 0 2px 0 #bbb, 0 3px 4px rgba(0,0,0,0.12);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  transition: transform 0.08s, box-shadow 0.08s, background 0.2s, color 0.2s;
}

.key:hover:not(.grayed) {
  transform: translateY(-2px);
  box-shadow: 0 4px 0 #bbb, 0 5px 8px rgba(0,0,0,0.18);
}

/* Keys aren't dragged in Build mode (tapping adds them to the build box
   instead), so suppress the grab cursor while it's active — use the plain
   arrow instead of a pointing-hand cursor. */
body.build-mode .key:not(.grayed) {
  cursor: default;
}

.key.grayed {
  background: #cacaca;
  color: #888;
  box-shadow: 0 1px 0 #aaa;
  cursor: default;
}

.key.dragging {
  opacity: 0.4;
  transform: scale(0.95);
}

.key.tap-selected {
  background: #1a5fb4;
  color: #fff;
  box-shadow: 0 2px 0 #0d3d7a, 0 3px 8px rgba(26,95,180,0.45);
  transform: translateY(-2px);
}

#build-box.tap-selected {
  background: #1a5fb4 !important;
  color: #fff !important;
  border-color: #0d3d7a !important;
}

/* Scale keyboard to fit viewport on small screens.
   Row 1 has 10 keys: 10 × key + 9 × gap must fit inside 100vw. */
@media (max-width: 520px) {
  .kb-row { gap: clamp(2px, 1vw, 6px); }
  .key {
    width:     clamp(28px, 8.5vw, 46px);
    height:    clamp(44px, 11vw, 58px);
    font-size: clamp(0.75rem, 3.2vw, 1.15rem);
    border-radius: 4px;
  }

  /* Too many header buttons to fit on one row on phones — stack the title
     on its own row above them, and let the button row wrap onto as many
     rows as it needs instead of clipping/hiding buttons. */
  #header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    padding: 0.5rem 0.6rem;
  }
  #header-title-wrap {
    flex: none;
    text-align: center;
  }
  #header-btns {
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 0.35rem;
  }
}

/* ---- Drag ghost ---- */

#drag-ghost {
  position: fixed;
  width: 46px;
  height: 58px;
  border-radius: 5px;
  background: #1a5fb4;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1000;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
  opacity: 0.55;
}

/* ---- Insertion cursor ---- */

#cursor {
  position: fixed;
  width: 3px;
  background: #e8770a;
  pointer-events: none;
  display: none;
  z-index: 500;
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 0 4px rgba(232,119,10,0.5);
}

/* ---- Tooltip ---- */

#tooltip {
  position: fixed;
  background: rgba(255, 248, 210, 0.82);
  color: #3a2800;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1rem;
  font-weight: 400;
  padding: 4px 9px;
  border-radius: 4px;
  pointer-events: none;
  display: none;
  z-index: 2000;
  transform: translate(-50%, calc(-100% - 20px));
  white-space: nowrap;
}

#tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(255, 248, 210, 0.82);
}

body.dragging, body.dragging * { cursor: none !important; }

/* ---- Win overlay ---- */

#win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: clamp(1rem, 5vh, 3rem);
  z-index: 3000;
}

#win-overlay.hidden { display: none; }

#win-box {
  background: #fff;
  border-radius: 16px;
  padding: 0.625rem clamp(0.5rem, 2vw, 1rem);
  text-align: center;
  box-shadow: 0 16px 48px rgba(0,0,0,0.3);
  max-width: min(560px, calc(100vw - 16px));
  width: 92%;
  max-height: 90vh;
  overflow-y: auto;
  overflow-wrap: break-word;
  word-break: break-word;
}

@media (max-width: 520px) {
  #win-box {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
    padding: 0.5rem 0.4rem;
    border-radius: 10px;
    overflow: hidden;
  }
  #win-text    { font-size: 1.2rem; }
  #win-score   { font-size: 0.9rem; }
  #win-initial { font-size: 0.95rem; }
  #win-author  { font-size: 0.85rem; }
  #win-buttons { flex-direction: column; gap: 0.4rem; align-items: center; }
}

#win-text {
  font-size: 1.5rem;
  font-family: Georgia, serif;
  color: #1a5fb4;
  margin-bottom: 0.4rem;
}

#win-date {
  font-size: 0.85rem;
  font-family: Arial, Helvetica, sans-serif;
  color: #000;
  margin-bottom: 0.35rem;
}
#win-date:empty { display: none; }

#win-score {
  font-size: 1rem;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 700;
  color: #1a5fb4;
  margin-bottom: 0.5rem;
}

#win-initial {
  font-size: 1.1rem;
  font-family: Georgia, serif;
  color: #333;
  font-style: italic;
  margin-bottom: 0.4rem;
  line-height: 1.6;
  letter-spacing: 0.04em;
}

#win-author {
  font-size: 0.95rem;
  font-family: Georgia, serif;
  color: #000;
  font-style: italic;
  margin-bottom: 0.8rem;
}

#author-display {
  text-align: center;
  font-size: 1.1rem;
  font-weight: bold;
  font-family: Georgia, serif;
  color: #444;
  font-style: italic;
  flex-shrink: 0;
}

#win-buttons {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}

#win-footer {
  margin-top: 0.5rem;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.5rem;
}

#win-brand {
  font-size: 0.8rem;
  font-family: Arial, Helvetica, sans-serif;
  color: #a86c00;
}

#win-hardmode {
  font-size: 0.85rem;
  font-weight: 700;
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #a86c00;
}
#win-hardmode:empty { display: none; }

#share-btn {
  padding: 0.4rem 1.3rem;
  background: #27ae60;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: Arial, sans-serif;
  cursor: pointer;
}

#share-btn:hover { background: #1e8449; }

#win-close {
  padding: 0.4rem 1.3rem;
  background: #1a5fb4;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: Arial, sans-serif;
  cursor: pointer;
}

#win-close:hover { background: #154d96; }

/* ---- Attempt recap overlay (Recap button, incomplete puzzle) ---- */

#attempt-recap-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}

#attempt-recap-overlay.hidden { display: none; }

#attempt-recap-box {
  background: #fff;
  border-radius: 16px;
  padding: 1.5rem clamp(1rem, 5vw, 2.5rem);
  text-align: center;
  box-shadow: 0 16px 48px rgba(0,0,0,0.3);
  max-width: min(560px, calc(100vw - 16px));
  width: 92%;
}

#attempt-recap-header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: 0.75rem;
}

#attempt-recap-header h2 {
  font-family: Georgia, serif;
  font-size: 1.3rem;
  color: #1a5fb4;
  margin: 0;
}

#attempt-recap-close {
  position: absolute;
  right: 0;
  background: none;
  border: none;
  color: #888;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
}
#attempt-recap-close:hover { color: #333; }

#attempt-recap-empty {
  color: #666;
  font-style: italic;
}

#attempt-recap-word {
  font-family: Georgia, serif;
  font-size: 1.8rem;
  letter-spacing: 0.05em;
  padding: 1rem 0.5rem;
  word-break: break-word;
}

.attempt-recap-letter {
  display: inline-block;
}

/* Orange insertion-point line, matching the real #cursor element */
#attempt-recap-line {
  display: inline-block;
  width: 3px;
  height: 1.4em;
  vertical-align: middle;
  background: #e8770a;
  border-radius: 2px;
  box-shadow: 0 0 4px rgba(232,119,10,0.5);
  margin: 0 1px;
}

/* ---- Hint choice overlay ---- */

#hint-choice-overlay {
  position: fixed;
  inset: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}
#hint-choice-overlay.hidden { display: none; }

#hint-choice-box {
  background: #fff;
  border-radius: 16px;
  padding: 1.5rem clamp(1rem, 5vw, 2rem);
  box-shadow: 0 16px 48px rgba(0,0,0,0.3);
  max-width: min(440px, calc(100vw - 16px));
  width: 92%;
}

#hint-choice-header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #d5deea;
  cursor: grab;
  touch-action: none;
}
#hint-choice-header.dragging { cursor: grabbing; }
#hint-choice-header h2 {
  font-family: Georgia, serif;
  font-size: 1.3rem;
  color: #1a5fb4;
  margin: 0;
}
#hint-choice-close {
  position: absolute;
  right: 0;
  background: none;
  border: none;
  color: #888;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
}
#hint-choice-close:hover { color: #333; }

.hint-choice-option {
  margin-bottom: 1.1rem;
  text-align: center;
}
.hint-choice-option:last-child { margin-bottom: 0; }

.hint-choice-desc {
  margin: 0 0 0.6rem;
  color: #445;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.9rem;
  line-height: 1.4;
}
.hint-target-word {
  background: #fff2b3;
  border-radius: 4px;
  padding: 0 2px;
  font-weight: 700;
  color: #1a1a1a;
  letter-spacing: 0.03em;
}

.hint-choice-btn {
  display: inline-block;
  min-width: 140px;
  padding: 0.55rem 1.4rem;
  border-radius: 20px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.hint-choice-fill {
  background: #eaf2fb;
  border: 1px solid #a9c8e8;
  color: #1a5fb4;
}
.hint-choice-fill:hover { background: #d8e8f8; }

.hint-choice-scratch {
  background: #eafaf3;
  border: 1px solid #a3ddc4;
  color: #1b7a4d;
}
.hint-choice-scratch:hover { background: #d7f3e6; }

/* ---- Scratchpad overlay ---- */

#scratchpad-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}
#scratchpad-overlay.hidden { display: none; }

#scratchpad-box {
  background: #fff;
  border-radius: 16px;
  padding: 1.25rem clamp(1rem, 4vw, 2rem);
  box-shadow: 0 16px 48px rgba(0,0,0,0.3);
  max-width: min(720px, calc(100vw - 16px));
  width: 94%;
  max-height: 90vh;
  overflow-y: auto;
}

#scratchpad-header { text-align: center; margin-bottom: 0.75rem; }
#scratchpad-header h2 {
  font-family: Georgia, serif;
  font-size: 1.3rem;
  color: #1a5fb4;
  margin: 0;
}

#scratchpad-allwords {
  font-size: 0.85rem;
  line-height: 2;
  text-align: center;
  padding: 0.5rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid #e0e6ee;
  word-spacing: 0.25em;
}
.scratch-mini-word {
  border-radius: 3px;
  padding: 0 3px;
}
.scratch-mini-word.incomplete { background: #fff2b3; cursor: grab; touch-action: none; }
.scratch-mini-word.complete   { background: #bbdefb; }
.scratch-mini-word.complete.connected-incomplete { background: #fff2b3; }

#scratchpad-dropbox {
  min-height: 64px;
  background: #f2f6fb;
  border: 2px dashed #b7c6dc;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  margin-bottom: 0.75rem;
}
#scratchpad-dropbox-placeholder {
  color: #8a97a8;
  font-size: 0.9rem;
  font-style: italic;
}

#scratchpad-row {
  min-height: 58px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  padding: 8px;
  margin-bottom: 0.75rem;
}

.scratch-tile {
  width: 40px;
  height: 52px;
  border-radius: 5px;
  border: none;
  background: #fff2b3;
  box-shadow: 0 2px 0 #bbb, 0 3px 4px rgba(0,0,0,0.12);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scratch-tile.movable { cursor: grab; touch-action: none; }
.scratch-tile.movable:active { cursor: grabbing; }
.scratch-tile.fixed {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}
.scratch-tile.dragging { opacity: 0.4; }

#scratchpad-msg {
  min-height: 1.3em;
  text-align: center;
  color: #c00;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

#scratchpad-buttons {
  display: flex;
  justify-content: center;
  gap: 1rem;
}
#scratchpad-buttons button {
  padding: 0.6rem 1.6rem;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-family: Arial, sans-serif;
  cursor: pointer;
}
#scratchpad-accept-btn { background: #1a5fb4; color: #fff; }
#scratchpad-accept-btn:hover:not(:disabled) { background: #154d96; }
#scratchpad-accept-btn:disabled { background: #99b8db; cursor: not-allowed; }
#scratchpad-cancel-btn { background: #ddd; color: #333; }
#scratchpad-cancel-btn:hover { background: #ccc; }

/* ---- Help overlay ---- */

#help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
}

#help-overlay.hidden { display: none; }

#help-box {
  position: relative;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.3);
  max-width: 580px;
  width: 92%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: text;
  -webkit-user-select: text;
}

/* Shown each time Help opens, over roughly half of #help-box — the user
   must close it to read the rest of the page underneath. */
#help-intro-overlay {
  position: absolute;
  top: 25%;
  left: 6%;
  right: 6%;
  height: 50%;
  background: #fff2b3;
  border: 2px solid #1a5fb4;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  padding: 1.5rem;
  text-align: center;
  z-index: 10;
}
#help-intro-overlay.hidden { display: none; }
#help-intro-overlay p {
  font-size: 1.05rem;
  color: #1a1a1a;
}
#help-intro-close {
  padding: 0.55rem 1.8rem;
  background: #1a5fb4;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}
#help-intro-close:hover { background: #0d3d7a; }

#help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.4rem 1.6rem 1rem 2.2rem;
  flex-shrink: 0;
  border-bottom: 1px solid #e8e0d5;
  cursor: grab;
  touch-action: none;
}
#help-header.dragging { cursor: grabbing; }

#help-body {
  overflow-y: auto;
  padding: 1.2rem 2.2rem 2rem;
}

#help-header-btns {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

#help-mode-btn {
  padding: 0.3rem 0.85rem;
  background: #fff;
  border: 1px solid #0d3d7a;
  border-radius: 5px;
  color: #1a5fb4;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.83rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
#help-mode-btn:hover { background: #dceaff; }

#help-demo-btn {
  padding: 0.3rem 0.85rem;
  background: #1a5fb4;
  border: 1px solid #0d3d7a;
  border-radius: 5px;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.83rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
#help-demo-btn:hover { background: #154d96; }

/* Draws attention to the Demo button on the automatic first-use Help
   popup, by cycling its color rather than fading in/out. */
#help-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: #888;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  flex-shrink: 0;
}

#help-close:hover { color: #333; }

#help-title {
  font-family: Georgia, serif;
  font-size: 1.6rem;
  color: #1a5fb4;
}

#help-title-mode {
  font-size: 0.65em;
}

.help-section {
  margin-bottom: 1.4rem;
}

.help-section h3.help-heading {
  font-family: Georgia, serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a5fb4;
  text-align: center;
  margin-bottom: 0.8rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid #c8d8f0;
}

.help-section p {
  font-family: Georgia, serif;
  font-size: 0.97rem;
  line-height: 1.65;
  color: #333;
  margin-bottom: 0.6rem;
}

.help-section p:last-child {
  margin-bottom: 0;
}

.help-tips {
  font-family: Georgia, serif;
  font-size: 0.97rem;
  line-height: 1.65;
  color: #333;
  margin: 0 0 0.6rem;
  padding-left: 1.4rem;
}
.help-tips li {
  margin-bottom: 0.3rem;
}
.help-tips li:last-child {
  margin-bottom: 0;
}


/* Details accordion */

details {
  border: 1px solid #ddd;
  border-radius: 7px;
  margin-bottom: 0.55rem;
  overflow: hidden;
}

details[open] {
  border-color: #a8c4e8;
}

details summary {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.93rem;
  font-weight: 600;
  color: #1a5fb4;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #f7f4f0;
}

details[open] summary {
  background: #eaf0fb;
  border-bottom: 1px solid #a8c4e8;
}

details summary::-webkit-details-marker { display: none; }

details summary::before {
  content: '▶';
  font-size: 0.65rem;
  color: #7aabdf;
  transition: transform 0.18s;
  flex-shrink: 0;
}

details[open] summary::before {
  transform: rotate(90deg);
}

details p,
details ol {
  font-family: Georgia, serif;
  font-size: 0.93rem;
  line-height: 1.65;
  color: #333;
  padding: 0.75rem 1rem;
}

details ol {
  padding-left: 2rem;
}

details ol li {
  margin-bottom: 0.4rem;
}

/* Double the gap between the two paragraphs in Inserting Letters
   (normally 0.75rem bottom + 0.75rem top padding = 1.5rem total). */
#help-inserting-letters p + p {
  margin-top: 1.5rem;
}

/* ---- Demo overlay ---- */

/* align-items is flex-start (not center) so #demo-box's top edge — and the
   skip-forward button inside its header — sits at a fixed screen position
   regardless of the box's own height. Several sections change #demo-box's
   height (the Scratchpad panel, hint-choice panel, and caption text of
   varying length all differ in height from what they replace); centering
   would recenter the whole box vertically every time and shift controls
   out from under the mouse mid-playback. */
#demo-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 6vh;
  z-index: 3000;
}

#demo-overlay.hidden { display: none; }

#demo-box {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.3);
  max-width: 640px;
  width: 94%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#demo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.4rem;
  flex-shrink: 0;
  border-bottom: 1px solid #e8e0d5;
}

#demo-title {
  font-family: Georgia, serif;
  font-size: 1.3rem;
  color: #1a5fb4;
}

#demo-title-mode {
  font-size: 0.7em;
}

#demo-timer {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: #666;
  min-width: 2.5rem;
  text-align: center;
}

#demo-header-btns {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#demo-header-btns button {
  padding: 0.3rem 0.85rem;
  background: #fff;
  border: 1px solid #0d3d7a;
  border-radius: 5px;
  color: #1a5fb4;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
#demo-header-btns button:hover { background: #dceaff; }
#demo-header-btns button:disabled {
  opacity: 0.45;
  cursor: default;
}
#demo-header-btns button:disabled:hover { background: #fff; }

/* AV controls: Restart | Skip Back | Play/Pause | Skip Forward */
#demo-av-controls {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

#demo-av-controls button {
  width: 30px;
  height: 30px;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#demo-av-controls svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

#demo-playpause-btn {
  position: relative;
}

/* Darker + larger than the other AV icons (still within the same 30x30
   button) so it reads clearly at a glance. */
#demo-voice-btn {
  color: #0d3d7a;
}
#demo-voice-btn svg {
  width: 21px;
  height: 21px;
}
#demo-voice-btn .voice-stroke {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

#demo-close-btn {
  color: #888 !important;
  border-color: #ccc !important;
}
#demo-close-btn:hover { background: #eee !important; }

/* The stage mimics the real app's phrase/score/keyboard area, reusing the
   same .word/.letter/.sep/.key classes so it stays visually in sync with
   the real game's styling automatically. */
#demo-stage {
  position: relative;
  background: #dcdcdc;
  padding: 0.5rem 0 0;
  overflow: hidden;
}

#demo-mini-header {
  display: flex;
  justify-content: flex-end;
  padding: 0 1rem 0.4rem;
}

#demo-hint-btn {
  padding: 0.3rem 0.95rem;
  background: #f0a30a;
  border: 1px solid #a86c00;
  border-radius: 5px;
  color: #402400;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.83rem;
  font-weight: 700;
  white-space: nowrap;
}

#demo-phrase-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.2rem;
  min-height: 130px;
}

#demo-phrase {
  max-width: 560px;
  font-size: 26px;
  line-height: 1.8;
  text-align: center;
  word-spacing: 0.25em;
  font-family: Arial, Helvetica, sans-serif;
}

/* Caption explaining what the demo is currently showing. Background color
   is set/cycled from JS (demoSetCaption) each time the text changes. */
#demo-caption {
  margin: 0 1.2rem 0.5rem;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  text-align: center;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: #222;
  min-height: 1.3em;
  transition: background-color 0.3s ease;
}

#demo-score-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.4rem;
  padding: 0.3rem 0 0.5rem;
  font-family: Arial, Helvetica, sans-serif;
}

#demo-score-display {
  font-size: 1.2rem;
  font-weight: 700;
  color: #1a1a1a;
  min-width: 110px;
  text-align: center;
}

#demo-last-penalty {
  font-size: 1rem;
  font-weight: 700;
  color: #c0392b;
  min-width: 36px;
  text-align: right;
  display: inline-block;
}

#demo-last-award {
  font-size: 1rem;
  font-weight: 700;
  color: #27ae60;
  min-width: 36px;
  text-align: left;
  display: inline-block;
}

#demo-keyboard-area {
  padding: 0.6rem 0 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: #cfcfcf;
  border-top: 1px solid #b8b8b8;
}

#demo-build-panel {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

#demo-build-box {
  min-width: 40px;
  min-height: 34px;
  border: 2px dashed #bbb;
  border-radius: 6px;
  background: #fff2b3;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: #000;
  padding: 3px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.08em;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

#demo-build-box.has-content {
  border: 2px solid #1a5fb4;
}

#demo-build-btn {
  padding: 0.25rem 0.6rem;
  background: #fff;
  border: 1px solid #999;
  border-radius: 5px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.72rem;
  color: #111;
  white-space: nowrap;
  transition: background 0.15s;
}

#demo-build-btn.cancel-mode {
  border-color: #c0392b;
  color: #c0392b;
}

/* Mini hint-choice panel — reuses .hint-choice-btn/.hint-choice-cost from
   the real #hint-choice-overlay, scaled down to fit inside the stage. Sits
   in-flow in the keyboard's slot (which is hidden while it's open) rather
   than covering the whole stage, so the caption/legend above stays visible. */
#demo-hint-choice {
  background: #cfcfcf;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  min-height: 160px;
}
#demo-hint-choice.hidden { display: none; }
#demo-hint-choice-title {
  font-family: Georgia, serif;
  font-size: 1.05rem;
  color: #1a5fb4;
  margin: 0 0 0.2rem;
  width: 100%;
  max-width: 320px;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid #b8b8b8;
  text-align: center;
  box-sizing: border-box;
}
#demo-hint-choice .hint-choice-option {
  margin-bottom: 0;
  max-width: 320px;
}
#demo-hint-choice .hint-choice-desc {
  font-size: 0.8rem;
  margin-bottom: 0.4rem;
}
#demo-hint-choice .hint-choice-btn {
  padding: 0.5rem 1.1rem;
  font-size: 0.85rem;
}

/* Mini Scratchpad panel — reuses .scratch-tile from the real
   #scratchpad-overlay, scaled down to fit inside the stage. Sits in-flow
   in the same slot as #demo-phrase-area/#demo-caption (which are hidden
   while it's open) rather than absolutely covering the whole stage, so the
   keyboard underneath stays visible and usable for the "drag a new letter
   in" animation. Opaque so nothing from the hidden phrase/caption peeks
   through — that's why it carries its own title and its own mirror of the
   caption text (see demoSetCaption). */
#demo-scratch-panel {
  background: #fff;
  border-radius: 8px;
  margin: 0 1.2rem 0.5rem;
  padding: 0.6rem 0.8rem 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  min-height: 130px;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
#demo-scratch-panel.hidden { display: none; }

#demo-scratch-title {
  font-family: Georgia, serif;
  font-size: 1.05rem;
  color: #1a5fb4;
  margin: 0;
}

#demo-scratch-caption {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: #222;
  text-align: center;
  min-height: 1.2em;
}

/* The Scratchpad's own copy of the whole (incomplete) phrase — the word
   being worked on is dragged from here, not from the main phrase display,
   which stays hidden underneath the panel the whole time it's open. */
#demo-scratch-allwords {
  font-size: 0.8rem;
  line-height: 1.8;
  text-align: center;
  word-spacing: 0.2em;
}
#demo-scratch-allwords .scratch-mini-word {
  padding: 0 2px;
}

/* Fixed size (not shrink-to-fit) — wide/tall enough for the longest target
   word (STATEMENTS, 10 letters at .scratch-tile's 24px width + 4px gaps)
   so the box doesn't visibly grow as letters get dragged in. */
#demo-scratch-dropbox {
  width: 300px;
  height: 40px;
  background: #f2f6fb;
  border: 2px dashed #b7c6dc;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#demo-scratch-row {
  display: flex;
  gap: 4px;
  min-height: 32px;
}
#demo-scratch-row .scratch-tile {
  width: 24px;
  height: 32px;
  font-size: 0.75rem;
}

/* Pool of this word's still-missing letters (alphabetized) — the source
   for dragging a new letter into the dropbox above. Replaces the keyboard,
   which stays hidden for the whole Scratchpad section. */
#demo-scratch-pool {
  display: flex;
  gap: 4px;
  min-height: 32px;
}
#demo-scratch-pool .scratch-tile {
  width: 24px;
  height: 32px;
  font-size: 0.75rem;
}

#demo-scratch-accept-btn {
  padding: 0.3rem 0.9rem;
  background: #1a5fb4;
  border: 1px solid #0d3d7a;
  border-radius: 5px;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
}

/* Everything in the stage is playback-only — never interactive */
#demo-stage, #demo-stage * {
  pointer-events: none;
  user-select: none;
}

#demo-stage .key {
  width: 40px;
  height: 50px;
  font-size: 1rem;
}

/* Simulated mouse cursor — a small black arrow with a white outline,
   matching a typical system pointer (not a filled circle, which reads as
   a letter "O" being dragged). Positioned so the arrow's tip (top-left of
   the shape) lands exactly on the target point, like a real cursor. */
#demo-cursor {
  position: absolute;
  width: 15px;
  height: 21px;
  background: #111;
  clip-path: polygon(0 0, 0 70%, 25% 55%, 38% 96%, 53% 89%, 40% 50%, 68% 50%);
  filter: drop-shadow(1px 0 0 #fff) drop-shadow(-1px 0 0 #fff)
          drop-shadow(0 1px 0 #fff) drop-shadow(0 -1px 0 #fff);
  transform-origin: 0 0;
  transition: left 0.9s ease, top 0.9s ease;
  z-index: 62;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
}

#demo-cursor.pressed {
  transform: scale(0.85);
}

/* Hand cursor shown over keyboard keys, matching the real page's grab
   cursor — except during Build mode, where it's suppressed (see .key
   cursor rules) so the arrow is used instead.
   The ✋ emoji ignores `color` (emoji are always rendered in their own
   fixed, multi-color glyph — this one defaults to a yellow skin tone), so
   brightness(0) invert(1) is used to force it to a solid white silhouette
   instead, with a thin black outline (via drop-shadow) for contrast. */
#demo-cursor.hand {
  width: 24px;
  height: 24px;
  background: none;
  clip-path: none;
  filter: brightness(0) invert(1)
          drop-shadow(1px 0 0 #000) drop-shadow(-1px 0 0 #000)
          drop-shadow(0 1px 0 #000) drop-shadow(0 -1px 0 #000);
}

/* Orange insertion-point line, matching the real #cursor element */
#demo-insert-cursor {
  position: absolute;
  width: 3px;
  background: #e8770a;
  display: none;
  z-index: 50;
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 0 4px rgba(232,119,10,0.5);
}

#demo-tooltip {
  position: absolute;
  background: rgba(255, 248, 210, 0.92);
  color: #3a2800;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.95rem;
  font-weight: 400;
  padding: 4px 9px;
  border-radius: 4px;
  display: none;
  z-index: 55;
  transform: translate(-50%, calc(-100% - 16px));
  white-space: nowrap;
}

/* Semi-transparent (matches the real #drag-ghost's opacity) so the target
   word stays visible underneath while a letter is being carried. */
#demo-ghost {
  position: absolute;
  min-width: 40px;
  height: 50px;
  border-radius: 5px;
  background: #1a5fb4;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  opacity: 0.6;
  transform: translate(-50%, -50%);
  transition: left 0.9s ease, top 0.9s ease;
  z-index: 58;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
}

/* Score/word/tooltip highlight pulse used by the demo to call out awards,
   penalties, hint reveals, and word tooltips. Uses a background-color flash
   (not just scale) so it reads clearly regardless of what's underneath.
   Uses the standalone `scale` property (not `transform: scale()`) because
   several pulsed elements — the tooltip in particular — already rely on
   `transform: translate(...)` for their own positioning; animating
   `transform` directly would clobber that position for the animation's
   duration and make the pulsing tooltip jump to the wrong spot. */
@keyframes demoPulse {
  0%   { scale: 1;   background-color: transparent; }
  30%  { scale: 1.6; background-color: #ffd700; }
  60%  { scale: 1.6; background-color: #ffd700; }
  100% { scale: 1;   background-color: transparent; }
}

.demo-pulse {
  display: inline-block;
  border-radius: 4px;
  animation: demoPulse 0.9s ease;
}

/* The tooltip's own pulse (fires right before the missing letters are
   shown) should be quicker than the shared score-indicator pulse. */
#demo-tooltip.demo-pulse {
  animation-duration: 0.45s;
}

/* Briefly enlarges and darkens a completed word to draw the eye to it —
   filter:brightness works regardless of the word's own background color
   (yellow incomplete or blue complete), unlike demoPulse's gold flash. */
@keyframes demoWordHighlight {
  0%   { scale: 1;   filter: brightness(1); }
  30%  { scale: 1.3; filter: brightness(0.65); }
  60%  { scale: 1.3; filter: brightness(0.65); }
  100% { scale: 1;   filter: brightness(1); }
}

.demo-word-highlight {
  display: inline-block;
  border-radius: 4px;
  animation: demoWordHighlight 1.2s ease;
}

/* ---- Login / Account overlays ---- */

#login-overlay, #account-overlay, #feedback-overlay, #suggest-quote-overlay, #privacy-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4000;
}

#login-overlay.hidden, #account-overlay.hidden, #feedback-overlay.hidden, #suggest-quote-overlay.hidden, #privacy-overlay.hidden { display: none; }

#account-stats-overlay, #account-delete-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4500;
}
#account-stats-overlay.hidden, #account-delete-overlay.hidden { display: none; }

#account-stats-box {
  position: relative;
  background: #fff;
  border-radius: 14px;
  padding: 1.75rem 2rem;
  width: 380px;
  max-width: 92vw;
  box-shadow: 0 16px 48px rgba(0,0,0,0.3);
  font-family: Arial, Helvetica, sans-serif;
}
#account-stats-box h1 {
  text-align: center;
  margin: 0 0 14px;
  font-size: 1.3em;
  color: #1a5fb4;
}

.account-stats-mode {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #e0e6ee;
}
.account-stats-mode:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.account-stats-mode h3 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
  color: #333;
}
.account-stats-mode p { margin: 0 0 0.25rem; font-size: 0.88em; color: #444; }

.login-box {
  position: relative;
  background: #fff;
  border-radius: 14px;
  padding: 1.75rem 2rem;
  width: 360px;
  max-width: 92vw;
  box-shadow: 0 16px 48px rgba(0,0,0,0.3);
  font-family: Arial, Helvetica, sans-serif;
}

.login-box-close {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  background: none;
  border: none;
  color: #888;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.login-box-close:hover { color: #333; }

.login-box h1 {
  text-align: center;
  margin: 0 0 4px;
  font-size: 1.3em;
  color: #1a5fb4;
}

.login-subtitle {
  text-align: center;
  margin: 0 0 14px;
  font-size: 0.85em;
  color: #444;
}

.login-help-text {
  font-size: 0.78em;
  color: #555;
  margin: 0 0 10px;
}

.privacy-list {
  font-size: 0.88em;
  color: #333;
  margin: 0 0 14px;
  padding-left: 1.3em;
}
.privacy-list li { margin-bottom: 0.6em; }
.privacy-list li:last-child { margin-bottom: 0; }

/* ---- Archive overlay ---- */

#archive-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4000;
}
#archive-overlay.hidden { display: none; }

#archive-box {
  position: relative;
  background: #fff;
  border-radius: 14px;
  padding: 1.25rem 1.4rem 1.4rem;
  width: 360px;
  max-width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,0.3);
  font-family: Arial, Helvetica, sans-serif;
}

#archive-close {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  background: none;
  border: none;
  color: #888;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
#archive-close:hover { color: #333; }

#archive-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
#archive-header h2 {
  margin: 0;
  font-size: 1.05rem;
  color: #1a5fb4;
  min-width: 9.5rem;
  text-align: center;
}
#archive-prev-btn, #archive-next-btn {
  background: none;
  border: 1px solid #bbb;
  border-radius: 6px;
  width: 30px;
  height: 30px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  color: #1a5fb4;
}
#archive-prev-btn:hover:not(:disabled), #archive-next-btn:hover:not(:disabled) { background: #eef3fa; }
#archive-prev-btn:disabled, #archive-next-btn:disabled { color: #ccc; border-color: #eee; cursor: not-allowed; }

#archive-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #667;
  margin-bottom: 0.3rem;
}

#archive-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.archive-day {
  aspect-ratio: 1;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: Arial, Helvetica, sans-serif;
  cursor: pointer;
  color: #222;
}
.archive-day-blank { visibility: hidden; cursor: default; }
.archive-day-viewed     { background: greenyellow; }
.archive-day-incomplete { background: sandybrown; }
.archive-day-completed  { background: deepskyblue; }
.archive-day-future, .archive-day-before-start {
  background: #ddd;
  color: #999;
  cursor: default;
}
.archive-day:not(:disabled):hover { filter: brightness(0.93); }

.archive-day-today {
  font-weight: 700;
  box-shadow: inset 0 0 0 2px #1a1a1a;
}

#archive-key {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  margin-top: 1rem;
  font-size: 0.75rem;
  color: #444;
  justify-content: center;
}
.archive-key-item { display: flex; align-items: center; gap: 0.35rem; }
.archive-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}
.archive-swatch-viewed     { background: greenyellow; }
.archive-swatch-incomplete { background: sandybrown; }
.archive-swatch-completed  { background: deepskyblue; }

.login-panel.hidden { display: none; }

.login-box label {
  display: block;
  margin-bottom: 4px;
  font-weight: bold;
  font-size: 0.9em;
}

.login-box input[type=email],
.login-box input[type=password],
.login-box input[type=text],
.login-box textarea {
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 12px;
  border: 1px solid #bbb;
  border-radius: 4px;
  font-size: 1em;
  box-sizing: border-box;
  font-family: inherit;
}
.login-box textarea { resize: vertical; }

.login-box input:disabled {
  background: #eee;
  color: #666;
}

.field-count {
  float: right;
  font-weight: normal;
  color: #888;
  font-size: 0.85em;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.checkbox-row input { width: auto; margin: 0; }
.checkbox-label { font-weight: normal !important; }

.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 38px; margin-bottom: 14px; }
.pw-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-60%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: #777;
  font-size: 1.1em;
  line-height: 1;
}
.pw-toggle:hover { color: #333; }

.btn-primary {
  width: 100%;
  padding: 10px;
  background: #1a5fb4;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 1em;
  font-weight: 700;
  cursor: pointer;
  /* Promotes the button to its own compositing layer — works around a
     Chromium bug where the mouse cursor icon can stay stuck as the text
     I-beam (from a just-blurred input) instead of switching to the
     pointer when it moves onto a plain, non-layered element. */
  transform: translateZ(0);
}
.btn-primary:hover { background: #0d3d7a; }
.btn-primary:disabled { background: #ccc; color: #888; cursor: not-allowed; }
.btn-primary:disabled:hover { background: #ccc; }

.login-links {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1.1rem;
  font-size: 1em;
}
.login-links a {
  color: #1a5fb4;
  cursor: pointer;
  text-decoration: underline;
}

.error-msg   { color: #c00; font-size: 0.88em; margin-bottom: 4px; }
.success-msg { color: #080; font-size: 0.88em; margin-bottom: 4px; }

#login-resend { text-align: center; margin: -6px 0 10px; font-size: 0.8em; }
#login-resend a { color: #1a5fb4; cursor: pointer; text-decoration: underline; }

#account-overlay .login-box { text-align: center; }
#account-overlay .btn-primary {
  width: auto;
  padding: 0.5rem 1.3rem;
}
#account-email { font-size: 0.9em; color: #666; margin: 0 0 16px; }

#account-mode-row {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 16px;
}
.account-mode-option {
  display: inline-flex !important;
  align-items: center;
  gap: 0.35rem;
  font-weight: normal !important;
  cursor: pointer;
}
.account-mode-option input { width: auto; margin: 0; }

#account-divider {
  border-top: 1px solid #ddd;
  margin: 1rem 0 0.75rem;
}

#account-secondary-btns {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

#account-stats-btn, #account-logout-btn { background: #4a90d9; }
#account-stats-btn:hover, #account-logout-btn:hover { background: #3a7dc4; }

#account-delete-row {
  display: flex;
  justify-content: center;
  margin-top: 0.6rem;
}

#account-delete-btn { background: #bcdcf5; color: #000; }
#account-delete-btn:hover { background: #a5cded; }

#account-delete-form p {
  text-align: left;
  font-size: 0.9em;
  color: #444;
  margin-bottom: 1rem;
  line-height: 1.4;
}

#account-delete-confirm-btn { background: #c0392b; }
#account-delete-confirm-btn:hover { background: #a5311f; }
