:root {
  color-scheme: dark;
  --toolbar-height: 62px;
  --panel-bg: rgba(17, 24, 39, 0.92);
  --panel-border: rgba(255, 255, 255, 0.22);
  --accent: #60a5fa;
  --danger: #ef4444;
}

* {
  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 {
  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;
  background: rgba(3, 7, 18, 0.96);
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  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 rgba(255, 255, 255, 0.24);
  border-radius: 0.45rem;
  padding: 0.45rem 0.7rem;
  background: #374151;
  cursor: pointer;
}

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

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

.toolbar button:hover,
.toolbar select:hover,
.file-label:hover,
.home-link:hover {
  background: #4b5563;
}

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

.toolbar .danger:hover {
  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;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 0.45rem;
  background: rgba(3, 7, 18, 0.82);
  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: white;
  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: rgba(0, 0, 0, 0.22);
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
}

.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: rgba(255, 255, 255, 0.13);
}

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

.panel-title:focus {
  border-color: rgba(255, 255, 255, 0.3);
  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 rgba(255, 255, 255, 0.7);
  border-bottom: 3px solid rgba(255, 255, 255, 0.7);
}

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

.text-editor:focus,
.names-editor:focus {
  outline: 3px solid rgba(96, 165, 250, 0.65);
  border-color: transparent;
}

.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: #fff;
  background: rgba(239, 68, 68, 0.3);
  border-radius: 0.5rem;
  animation: pulse 0.8s ease-in-out infinite alternate;
}

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

.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 label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.panel-options button,
.panel-options input,
.panel-options select {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 0.35rem;
  padding: 0.36rem 0.55rem;
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

.panel-options input[type="checkbox"] {
  padding: 0;
}

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

.panel-options button {
  cursor: pointer;
}

.panel-options button:hover {
  background: rgba(255, 255, 255, 0.2);
}

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

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

.panel-options .is-on {
  background: rgba(96, 165, 250, 0.45);
  border-color: rgba(147, 197, 253, 0.95);
}

.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: rgba(255, 255, 255, 0.16);
}

/* 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;
}

/* Nothing is being edited in presentation mode, so drop the form styling
   and let the text sit on the panel. */
.board.presentation .text-editor {
  background: transparent;
  border-color: transparent;
}

.timer-minutes {
  width: 5.2rem;
}

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

#aboutDialog {
  max-width: 34rem;
  padding: 1.25rem 1.5rem;
  color: white;
  background: #111827;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 0.7rem;
  line-height: 1.45;
}

#aboutDialog p {
  margin: 0.65em 0;
}

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

#aboutDialog h2 {
  margin-top: 0;
}

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

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

#aboutDialog button {
  padding: 0.45rem 0.9rem;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 0.45rem;
  background: #374151;
  cursor: pointer;
}

#aboutDialog button:hover {
  background: #4b5563;
}

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