/* The board's colors. These values are the Standard look, the one the
   board has always had (and the one a board saved before themes came in
   still gets); every other theme sets them from its nine colors in the
   block after this one. */
:root {
  color-scheme: var(--scheme);
  --toolbar-height: 62px;
  --scheme: dark;
  --chrome-fg: #ffffff;
  --toolbar-bg: rgba(3, 7, 18, 0.96);
  --toolbar-line: rgba(255, 255, 255, 0.14);
  --control-bg: #374151;
  --control-hover: #4b5563;
  --control-border: rgba(255, 255, 255, 0.44);
  --show-bg: rgba(3, 7, 18, 0.82);
  --show-fg: #ffffff;
  --show-border: rgba(255, 255, 255, 0.5);
  --panel-bg: rgba(17, 24, 39, 0.92);
  --panel-border: rgba(255, 255, 255, 0.22);
  --panel-fg: #ffffff;
  --header-bg: rgba(0, 0, 0, 0.22);
  --header-line: rgba(255, 255, 255, 0.13);
  --icon-hover: rgba(255, 255, 255, 0.13);
  --icon-pressed: rgba(255, 255, 255, 0.16);
  --title-focus: rgba(255, 255, 255, 0.6);
  --grip: rgba(255, 255, 255, 0.7);
  --editor-bg: rgba(0, 0, 0, 0.16);
  --editor-border: rgba(255, 255, 255, 0.42);
  --editor-focus: rgba(96, 165, 250, 0.65);
  --done-bg: rgba(239, 68, 68, 0.3);
  --warn-bg: rgba(245, 158, 11, 0.18);
  --warn-border: rgba(245, 158, 11, 0.75);
  --warn-button-bg: rgba(255, 255, 255, 0.12);
  --warn-button-border: rgba(255, 255, 255, 0.44);
  --warn-button-hover: rgba(255, 255, 255, 0.24);
  --link: #93c5fd;
  --option-bg: rgba(255, 255, 255, 0.1);
  --option-border: rgba(255, 255, 255, 0.42);
  --option-hover: rgba(255, 255, 255, 0.2);
  --on-bg: rgba(96, 165, 250, 0.45);
  --on-border: rgba(147, 197, 253, 0.95);
  --on-fg: #ffffff;
  --check-accent: auto;
  --dialog-bg: #111827;
  --dialog-border: rgba(255, 255, 255, 0.25);
  --good: #86efac;
  --warn: #fcd34d;
  --accent: #60a5fa;
  --focus: #60a5fa;
  --danger: #ef4444;
}

/* Every other theme. script.js puts the theme's colors on the page as
   --t-bg, --t-fg, --t-panel and so on (the same nine colors the Classroom
   Scoreboard and the Quiz Game Board Builder use), plus --t-good and
   --t-warn for the status lines, darker on the light themes. Panels and
   the toolbar are opaque here, not see-through like Standard's, so their
   text keeps its contrast over any background color or picture. */
:root[data-theme]:not([data-theme="standard"]) {
  --scheme: var(--t-scheme);
  --chrome-fg: var(--t-fg);
  --toolbar-bg: var(--t-panel);
  --toolbar-line: var(--t-border);
  --control-bg: var(--t-panel-2);
  --control-hover: var(--t-bg);
  --control-border: var(--t-border);
  --show-bg: var(--t-accent);
  --show-fg: var(--t-accent-fg);
  --show-border: var(--t-accent);
  --panel-bg: var(--t-panel);
  --panel-border: var(--t-border);
  --panel-fg: var(--t-fg);
  --header-bg: var(--t-panel-2);
  --header-line: var(--t-border);
  --icon-hover: var(--t-panel);
  --icon-pressed: var(--t-bg);
  --title-focus: var(--t-focus);
  --grip: var(--t-muted);
  --editor-bg: var(--t-panel-2);
  --editor-border: var(--t-border);
  --editor-focus: var(--t-focus);
  --warn-bg: var(--t-panel);
  --warn-border: var(--t-warn);
  --warn-button-bg: var(--t-panel-2);
  --warn-button-border: var(--t-border);
  --warn-button-hover: var(--t-bg);
  --link: var(--t-accent);
  --option-bg: var(--t-panel-2);
  --option-border: var(--t-border);
  --option-hover: var(--t-bg);
  --on-bg: var(--t-accent);
  --on-border: var(--t-accent);
  --on-fg: var(--t-accent-fg);
  --check-accent: var(--t-accent);
  --dialog-bg: var(--t-panel);
  --dialog-border: var(--t-border);
  --good: var(--t-good);
  --warn: var(--t-warn);
  --accent: var(--t-accent);
  --focus: var(--t-focus);
}

/* What Standard leaves to the browser, the themes set: a focus ring in the
   theme's focus color on the panel and dialog controls (the browser's own
   ring is drawn for a dark page), and placeholder text that is readable on
   the light themes too. */
:root[data-theme]:not([data-theme="standard"]) :is(.panel, dialog) :is(button, select, a, input:not(.panel-title)):focus-visible,
:root[data-theme]:not([data-theme="standard"]) .show-toolbar:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Standard's placeholder text: the browser's own grey was 3.95:1 on the note panel */
::placeholder {
  color: rgba(255, 255, 255, 0.72);
  opacity: 1;
}

:root[data-theme]:not([data-theme="standard"]) ::placeholder {
  color: var(--t-muted);
  opacity: 1;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  color: inherit;
}

body {
  color: var(--chrome-fg);
  background: #1f2937;
}

.toolbar {
  position: fixed;
  z-index: 10000;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: center;
  gap: 0.75rem 1rem;
  padding: 0.65rem 1rem;
  color: var(--chrome-fg);
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--toolbar-line);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.25);
}

.toolbar.hidden {
  display: none;
}

.toolbar-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.toolbar button,
.toolbar select,
.file-label,
.home-link {
  border: 1px solid var(--control-border);
  border-radius: 0.45rem;
  padding: 0.45rem 0.7rem;
  color: var(--chrome-fg);
  background: var(--control-bg);
  cursor: pointer;
}

.home-link {
  text-decoration: none;
}

.toolbar select {
  max-width: 11rem;
}

.toolbar button:hover,
.toolbar select:hover,
.file-label:hover,
.home-link:hover {
  background: var(--control-hover);
}

.toolbar button:focus-visible,
.toolbar select:focus-visible,
.home-link:focus-visible,
.file-label:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* The same deep red on every theme, so the text on it is always white. */
.toolbar .danger:hover {
  color: #ffffff;
  background: #991b1b;
}

.background-controls label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

input[type="color"] {
  width: 2.4rem;
  height: 2rem;
  padding: 0.1rem;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.file-label input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  padding-top: var(--toolbar-height);
  overflow: hidden;
  background-color: #1f2937;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

.board.toolbar-hidden {
  padding-top: 0;
}

.show-toolbar {
  position: fixed;
  z-index: 10001;
  top: 0.75rem;
  right: 0.75rem;
  padding: 0.45rem 0.7rem;
  color: var(--show-fg);
  border: 1px solid var(--show-border);
  border-radius: 0.45rem;
  background: var(--show-bg);
  cursor: pointer;
}

.hidden {
  display: none !important;
}

[hidden] {
  display: none !important;
}

.panel {
  position: absolute;
  left: 2rem;
  top: 6rem;
  width: 360px;
  height: 240px;
  min-width: 220px;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--panel-fg);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 0.7rem;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(5px);
}

.panel.active {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

.panel-header {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.65rem;
  padding: 0.3rem;
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-line);
}

.drag-handle,
.panel-actions button {
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 0.35rem;
  background: transparent;
  cursor: pointer;
}

.drag-handle {
  cursor: move;
  touch-action: none;
}

.drag-handle:hover,
.panel-actions button:hover {
  background: var(--icon-hover);
}

.panel-title {
  min-width: 0;
  padding: 0.28rem 0.4rem;
  color: var(--panel-fg);
  font-weight: 700;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0.3rem;
}

.panel-title:focus {
  border-color: var(--title-focus);
  outline: none;
}

.panel-actions {
  display: flex;
}

.panel-content {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.65rem;
}

.resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 22px;
  height: 22px;
  cursor: nwse-resize;
  touch-action: none;
}

.resize-handle::after {
  content: "";
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 9px;
  height: 9px;
  border-right: 3px solid var(--grip);
  border-bottom: 3px solid var(--grip);
}

.text-editor,
.names-editor {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  resize: none;
  padding: 0.65rem;
  color: var(--panel-fg);
  background: var(--editor-bg);
  border: 1px solid var(--editor-border);
  border-radius: 0.4rem;
  font-size: 1.25rem;
  line-height: 1.4;
}

.text-editor:focus,
.names-editor:focus {
  outline: 3px solid var(--editor-focus);
  border-color: transparent;
}

/* The formatted view of a text panel. Hidden while the panel's controls
   are showing (the textarea is being edited); swapped in — and the
   textarea out — once the controls are tucked away or the board is in
   presentation mode. */
.text-display {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  padding: 0.65rem;
  color: var(--panel-fg);
  font-size: 1.25rem;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  overflow-y: auto;
  display: none;
}

.panel.controls-hidden .text-display,
.board.presentation .text-display {
  display: block;
}

.panel.controls-hidden .text-editor,
.board.presentation .text-editor {
  display: none;
}

.fmt-bold { font-weight: 800; }
.fmt-italic { font-style: italic; }
.fmt-underline { text-decoration: underline; text-underline-offset: 0.12em; }
.fmt-big { font-size: 1.45em; line-height: 1.15; }

.clock-display,
.timer-display,
.names-display {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  width: 100%;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  line-height: 1;
  overflow: hidden;
}

/* Sizes below are only what the text starts at: the script measures each
   display and sets an exact size on .fit-text, either to fill the panel
   (Auto) or to whatever the teacher typed. */
.clock-display {
  font-size: clamp(2.6rem, 8vw, 7.5rem);
}

.timer-display {
  font-size: clamp(2.8rem, 9vw, 8.5rem);
}

.names-display {
  font-size: clamp(2rem, 6vw, 5.5rem);
  line-height: 1.1;
}

/* The block that gets measured and scaled. It must be free to take its
   own size, so it is never stretched to the display box. */
.fit-text {
  max-width: 100%;
  padding: 0 0.12em;
}

.clock-display .fit-text,
.timer-display .fit-text {
  white-space: nowrap;
}

/* break-word, not anywhere: a name should wrap between its words, and the
   auto-fit should shrink until each word fits on a line rather than split
   one down the middle. */
.names-display .fit-text {
  overflow-wrap: break-word;
}

/* Sized in em so the date scales with the clock face it sits under. */
.clock-date {
  margin-top: 0.3em;
  font-size: 0.3em;
  font-weight: 600;
  opacity: 0.85;
}

/* Once a panel's controls are hidden, the display itself is the button. */
.panel.controls-hidden .timer-display,
.panel.controls-hidden .names-display,
.board.presentation .timer-display,
.board.presentation .names-display {
  cursor: pointer;
}

.timer-display.finished {
  color: var(--panel-fg);
  background: var(--done-bg);
  border-radius: 0.5rem;
  animation: pulse 0.8s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.035); }
}

/* The name picker's question about repeated names, under the editor */
.names-warning {
  flex: 0 0 auto;
  margin-top: 0.5rem;
  padding: 0.6rem 0.75rem;
  color: var(--panel-fg);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 0.4rem;
  font-size: 1rem;
  line-height: 1.35;
}

.names-warning p {
  margin: 0 0 0.55rem;
}

.names-warning-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.names-warning button {
  border: 1px solid var(--warn-button-border);
  border-radius: 0.35rem;
  padding: 0.36rem 0.6rem;
  color: var(--panel-fg);
  background: var(--warn-button-bg);
  cursor: pointer;
}

.names-warning button:hover,
.names-warning button:focus-visible {
  background: var(--warn-button-hover);
}

.panel-options {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.75rem;
  flex-wrap: wrap;
  line-height: 1.2;
}

.panel-options .more-link {
  color: var(--link);
  font-size: 0.9em;
  white-space: nowrap;
}

.panel-options label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.panel-options button,
.panel-options input,
.panel-options select {
  border: 1px solid var(--option-border);
  border-radius: 0.35rem;
  padding: 0.36rem 0.55rem;
  color: var(--panel-fg);
  background: var(--option-bg);
}

.panel-options input[type="checkbox"] {
  padding: 0;
  accent-color: var(--check-accent);
}

.panel-options input[type="color"] {
  padding: 0.1rem;
  width: 2.4rem;
  height: 2rem;
}

.panel-options button {
  cursor: pointer;
}

.panel-options button:hover {
  background: var(--option-hover);
}

.font-size-group,
.format-group {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* The B / I / U / Big buttons wear their own formatting as the label. */
.format-group button {
  min-width: 2.1rem;
}

.font-size-group button {
  padding: 0.36rem 0.45rem;
}

.panel-options .is-on {
  color: var(--on-fg);
  background: var(--on-bg);
  border-color: var(--on-border);
}

.font-size-input {
  width: 4.4rem;
}

/* --- Hiding the controls once a board is set up --- */

.panel.controls-hidden .panel-options,
.board.presentation .panel-options,
.board.presentation .panel-actions,
.board.presentation .drag-handle,
.board.presentation .resize-handle {
  display: none;
}

.toggle-options[aria-pressed="true"] {
  background: var(--icon-pressed);
}

/* The handle and the buttons are gone, so the title is the only thing left
   in the header grid — give it the whole row instead of the first column. */
.board.presentation .panel-header {
  display: block;
}

.board.presentation .panel-title {
  width: 100%;
  text-align: center;
  pointer-events: none;
}


.timer-minutes {
  width: 5.2rem;
}

.names-status {
  flex: 0 0 auto;
  text-align: center;
  opacity: 0.82;
}

#aboutDialog,
#fileDialog {
  max-width: 34rem;
  padding: 1.25rem 1.5rem;
  color: var(--chrome-fg);
  background: var(--dialog-bg);
  border: 1px solid var(--dialog-border);
  border-radius: 0.7rem;
  line-height: 1.45;
}

#aboutDialog p,
#fileDialog p {
  margin: 0.65em 0;
}

#aboutDialog::backdrop,
#fileDialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

#aboutDialog h2,
#fileDialog h2 {
  margin-top: 0;
}

#aboutDialog a,
#fileDialog a {
  color: var(--accent);
}

#aboutDialog .about-fineprint {
  font-size: 0.88rem;
  opacity: 0.85;
}

#aboutDialog button,
#fileDialog button {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--control-border);
  border-radius: 0.45rem;
  background: var(--control-bg);
  cursor: pointer;
}

#aboutDialog button:hover,
#fileDialog button:hover {
  background: var(--control-hover);
}

/* The save / open file dialog: the same look as About, plus its rows of
   controls and a status line. The warning amber and the green are both
   well over 4.5:1 on the dialog's background in every theme (the light
   themes use darker ones). */
#fileDialog .file-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
  margin: 0.9rem 0;
}

#fileDialog .file-check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

#fileDialog button:focus-visible,
#fileDialog input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

#fileDialog .file-status {
  color: var(--good);
}

#fileDialog .file-status.warn {
  color: var(--warn);
}

@media (max-width: 800px) {
  .panel {
    width: 300px;
  }
}
