/* Theme
   Bulma 1.0 already derives both schemes from a handful of HSL knobs and
   switches on `prefers-color-scheme` plus the `data-theme` attribute that
   base.jhtml sets, so we only pick the hue and let it do the rest.
   Everything below the theme block is what Bulma cannot know about.

   Loaded *after* bulma.min.css — that is what makes plain selectors here win
   without `!important`.
*/

:root {
  color-scheme: light dark;

  /* #0b1020, the navy this UI used to hardcode, is hue 226 — close enough to
     Bulma's own 221 that the dark scheme barely moves. */
  --bulma-scheme-h: 226;
  --bulma-scheme-s: 16%;

  /* One accent for the whole app, same hue as the scheme. Red belongs to
     is-danger (a rejected flag) and to the logo, so it is not used here. */
  --bulma-primary-h: 226deg;
  --bulma-primary-s: 62%;
  --bulma-primary-l: 50%;
  /* Bulma derives the invert from a step of its generated palette, which for this hue
     stays dark and put near-black on the primary buttons at 3.8:1 — under AA. Pinning
     it to white gives 6.3:1. */
  --bulma-primary-invert-l: 100%;

  /* Links share the accent instead of Bulma's unrelated 233deg. */
  --bulma-link-h: 226deg;
  --bulma-link-s: 62%;
  --bulma-link-l: 55%;
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

#flag-submit-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

#flag-submit-form .flag-input-group {
  flex: 1 1 14rem;
  min-width: 0;
  margin-bottom: 0;
}

.flag-input-group .control.is-expanded {
  min-width: 0;
}

.task-description {
  overflow-wrap: anywhere;
}

.task-description pre {
  white-space: pre-wrap;
}

.task-description table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

.task-card .card-header {
  flex-wrap: wrap;
}

.task-card .card-header-title {
  min-width: 0;
  flex: 1 1 0;
  overflow-wrap: anywhere;
}

.task-card .task-card-tags {
  padding: 0.75rem;
  align-self: center;
}

.task-detail .card-header-title {
  flex-basis: 16rem;
}

.task-card .card-content {
  padding: 1rem;
}

.task-card .card-footer-item {
  min-width: 0;
}

.task-attachments {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--bulma-border);
}

.task-section-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.task-attachment-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.task-attachment-row,
.task-attachment-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-width: 0;
}

.task-attachment-main {
  display: flex;
  align-items: baseline;
  flex: 1 1 10rem;
  gap: 0.4rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.task-attachment-main > i {
  flex: 0 0 auto;
  color: var(--bulma-text-weak);
}

.task-attachment-main > span {
  min-width: 0;
}

.task-attachment-file,
.task-attachment-meta {
  flex-wrap: nowrap;
}

.task-attachment-file .task-attachment-main {
  flex: 1 1 0;
}

.task-attachment-file .task-attachment-main > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-attachment-meta {
  flex: 0 0 auto;
}

.task-endpoint.button {
  display: inline-block;
  max-width: 100%;
  height: auto;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: left;
}

.task-copy-feedback {
  color: var(--bulma-success-text);
}

.task-copy-feedback:empty {
  display: none;
}

.task-attachments :focus-visible {
  outline: 2px solid var(--bulma-link);
  outline-offset: 2px;
}

.task-grid .card,
.task-detail {
  border: 1px solid var(--bulma-border);
}

/* The navbar carries the flag form, so it needs to read as its own surface
   rather than blending into the page. */
.navbar:not(.is-transparent) {
  --bulma-navbar-box-shadow-size: 0 1px 0 0;
  --bulma-navbar-box-shadow-color: var(--bulma-border);
}

.footer {
  border-top: 1px solid var(--bulma-border);
}

/* Bulma's boxed shadow is a 10%-opacity ring, which all but disappears where the
   dropdown sits over cards of the same tone in the dark scheme. */
.navbar-dropdown.is-boxed {
  box-shadow:
    0 0.5rem 1.25rem hsla(var(--bulma-scheme-h), var(--bulma-scheme-s), 0%, 0.35),
    0 0 0 1px var(--bulma-border);
}

/* Settings dropdown. Wide enough for three segments of either row, so neither
   control wraps; below 1024px Bulma drops the fixed width and these render as
   plain rows inside the burger menu. */
.settings-dropdown {
  min-width: 19rem;
}

.settings-group {
  padding: 0.5rem 1.5rem;
}

/* Small caps label for a value or a control. Bulma 1.0 dropped `.heading`, which
   used to cover this. */
.mini-label {
  margin-bottom: 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--bulma-text-weak);
}

/* One segmented control per row: equal segments, no wrapping, and none of
   Bulma's bottom margin since the group already spaces things out. */
.settings-options {
  flex-wrap: nowrap;
  margin-bottom: 0;
}

.settings-options .button {
  flex: 1 1 0;
  margin-bottom: 0;
}

/* Initial-in-a-circle stand-in for an avatar, in the navbar and on /profile. */
.user-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  margin-right: 0.5rem;
  border-radius: 50%;
  background-color: var(--bulma-primary);
  color: var(--bulma-primary-invert);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
}

/* Profile facts: label over value, side by side while there is room. */
.profile-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 1rem;
}

.user-badge.is-large {
  width: 5rem;
  height: 5rem;
  margin-right: 0;
  font-size: 2rem;
}

/* Solved cards. Bulma has no "solved" state, but it does expose the derived
   success shades, so the green follows the theme instead of being frozen. */
.card.solved .card-header {
  background-color: var(--bulma-success);
}

/* Only what sits directly on the green. Tags are left out on purpose: each one
   brings its own background (is-dark for the solve count), and forcing the
   success invert onto them puts dark text on a dark pill. Icons live inside
   either a tag or the title, so they inherit the right colour on their own. */
.card.solved .card-header .card-header-title,
.card.solved .card-header .title {
  color: var(--bulma-success-invert);
}

.card.solved .card-header .subtitle {
  color: var(--bulma-success-invert);
  opacity: 0.85;
}

.card.solved .card-header .task-card-tags .tag.is-success {
  background-color: var(--bulma-success-dark);
  color: var(--bulma-success-dark-invert);
}

/* Hidden tasks (visible to admins) */
.card.task-hidden {
  background-color: var(--bulma-background);
  background-image: none;
}

/* Admin debug block: a tool bolted onto a player-facing card, so it gets its
   own inset surface to stop it reading as part of the task description. */
/* scheme-main-bis, not --bulma-background: the latter is what a plain .tag uses,
   and the block is full of tags that would vanish into it. */
.task-debug {
  border: 1px solid var(--bulma-border);
  border-radius: var(--bulma-radius);
  background-color: var(--bulma-scheme-main-bis);
  padding: 0.5rem 0.625rem;
}

/* Compact enough that both classtype labels sit on one line in a 260px card. */
.task-debug .tag:not(body) {
  font-size: 0.7rem;
  height: 1.75em;
  padding-left: 0.6em;
  padding-right: 0.6em;
}

.task-debug .tags {
  gap: 0.25rem;
}

.task-debug .tags .tag {
  margin-bottom: 0;
}

.task-debug > .tags:last-child {
  margin-bottom: 0;
}

.task-debug summary {
  cursor: pointer;
  color: var(--bulma-text-weak);
}

.task-debug details[open] summary {
  margin-bottom: 0.5rem;
}

.task-debug code,
.task-debug pre {
  font-size: 0.85em;
}

.task-debug pre {
  max-height: 20rem;
  overflow: auto;
}

/* Secrets stay blurred until asked for, so a task list can be shown from a
   shared screen. */
.debug-secret {
  filter: blur(4px);
  cursor: pointer;
  user-select: none;
}

.debug-secret.revealed {
  filter: none;
  cursor: auto;
  user-select: text;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}

.app-toast-stack {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: min(28rem, calc(100vw - 2rem));
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  z-index: 2000;
  pointer-events: none;
}

.app-toast.notification {
  pointer-events: auto;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.18);
  margin: 0;
  opacity: 0;
  transform: translateY(8px) scale(0.985);
  transition: opacity 180ms ease, transform 180ms ease;
}

.app-toast.notification.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.app-toast.notification.is-leaving {
  opacity: 0;
  transform: translateY(8px) scale(0.985);
}

/* The four kinds ride on Bulma's own .notification.is-* colours, so they follow
   data-theme without a second palette to keep in sync. */
.app-toast-message {
  font-size: 1rem;
  line-height: 1.3;
  word-break: break-word;
  /* Title, message and link are separate nodes so the server never has to send markup
     for emphasis — see the textContent-only rule in toasts.js. */
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.app-toast-title {
  font-size: 1.05rem;
}

.app-toast-link {
  align-self: flex-start;
  font-size: 0.85rem;
  text-decoration: underline;
}

@media (max-width: 768px) {
  .app-toast-stack {
    bottom: 0.75rem;
    right: 0.75rem;
    left: 0.75rem;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-toast.notification {
    transition: none;
    transform: none;
  }

  .app-toast.notification.is-visible,
  .app-toast.notification.is-leaving {
    transform: none;
  }
}
