/* Flagle game. Uses the site's --s-* colour variables, so light and dark themes follow the page. */

.fl-app {
  --fl-hidden: var(--s-surface-3);
  --fl-win: #12a05c;
  --fl-lose: #e5484d;
  --fl-accent: var(--s-primary);
  position: relative;
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px 8px;
  box-sizing: border-box;
  font-family: var(--s-font);
  color: var(--s-text);
}

.fl-app *,
.fl-modal * {
  box-sizing: border-box;
}

.fl-app.is-booting .fl-board {
  opacity: 0.6;
}

.fl-ic {
  display: inline-flex;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
}

.fl-ic svg {
  width: 100%;
  height: 100%;
}

.fl-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ---------- top bar ---------- */

.fl-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.fl-tabs {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: var(--s-surface-2);
  border: 1px solid var(--s-border);
}

.fl-tab {
  border: 0;
  background: none;
  color: var(--s-muted);
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.fl-tab:hover {
  color: var(--s-text);
}

.fl-tab.is-active {
  background: var(--s-surface);
  color: var(--s-text);
  box-shadow: 0 1px 3px rgba(15, 40, 80, 0.14);
}

.fl-tools {
  display: flex;
  gap: 2px;
}

.fl-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--s-text);
  cursor: pointer;
}

.fl-icon-btn:hover:not(:disabled) {
  background: var(--s-surface-2);
}

.fl-icon-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.fl-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 2px 8px;
}

.fl-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.fl-sub {
  color: var(--s-muted);
  font-size: 14px;
  font-weight: 600;
}

/* ---------- flag board ---------- */

.fl-flag {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  border-radius: 14px;
  overflow: hidden;
  background-color: var(--fl-hidden);
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.05) 75%),
    linear-gradient(45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.05) 75%);
  background-size: 28px 28px;
  background-position: 0 0, 14px 14px;
  box-shadow: inset 0 0 0 1px var(--s-border), var(--s-shadow);
}

html:not(.dark) .fl-flag {
  background-image:
    linear-gradient(45deg, rgba(15, 27, 45, 0.04) 25%, transparent 25%, transparent 75%, rgba(15, 27, 45, 0.04) 75%),
    linear-gradient(45deg, rgba(15, 27, 45, 0.04) 25%, transparent 25%, transparent 75%, rgba(15, 27, 45, 0.04) 75%);
}

.fl-flag::after {
  content: "?";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(64px, 18vw, 120px);
  font-weight: 800;
  color: var(--s-text);
  opacity: 0.06;
  pointer-events: none;
}

.fl-flag.is-win::after,
.fl-flag.is-lose::after {
  content: none;
}

.fl-flag.is-loading {
  animation: fl-pulse 1.2s ease-in-out infinite;
}

@keyframes fl-pulse {
  50% {
    opacity: 0.6;
  }
}

.fl-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.fl-fx {
  opacity: 0;
  pointer-events: none;
}

.fl-fx.is-pop {
  animation: fl-reveal 0.7s ease-out forwards;
}

@keyframes fl-reveal {
  0% {
    opacity: 0;
    filter: brightness(1.8);
  }
  35% {
    opacity: 1;
    filter: brightness(1.35);
  }
  100% {
    opacity: 1;
    filter: none;
  }
}

.fl-flag.is-win {
  box-shadow: 0 0 0 3px var(--fl-win), var(--s-shadow);
}

.fl-flag.is-lose {
  box-shadow: 0 0 0 3px var(--fl-lose), var(--s-shadow);
}

.fl-revealed {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 2px 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--s-muted);
}

.fl-meter {
  flex: 0 0 72px;
  height: 8px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--fl-accent) var(--p), var(--s-surface-3) var(--p));
}

.fl-left {
  margin-left: auto;
}

/* ---------- input ---------- */

.fl-form {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.fl-form.is-shake {
  animation: fl-shake 0.35s;
}

@keyframes fl-shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

.fl-combo {
  position: relative;
  flex: 1;
  min-width: 0;
}

.fl-input {
  width: 100%;
  height: 50px;
  padding: 0 16px;
  border-radius: 14px;
  border: 2px solid var(--s-border);
  background: var(--s-surface);
  color: var(--s-text);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  outline: none;
  transition: border-color 0.15s;
}

.fl-input:focus {
  border-color: var(--fl-accent);
}

.fl-input::placeholder {
  color: var(--s-muted);
  opacity: 0.8;
}

.fl-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 25;
  max-height: min(320px, 46vh);
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  border-radius: 14px;
  border: 1px solid var(--s-border);
  background: var(--s-surface);
  box-shadow: var(--s-shadow-lg);
}

.fl-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}

.fl-opt small {
  margin-left: auto;
  color: var(--s-muted);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fl-opt[aria-selected="true"],
.fl-opt:hover {
  background: var(--s-surface-2);
}

.fl-opt.is-used {
  opacity: 0.4;
  cursor: default;
}

.fl-thumb {
  width: 30px;
  height: 20px;
  border-radius: 3px;
  object-fit: cover;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.fl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 14px;
  border: 0;
  font: inherit;
  font-weight: 800;
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.fl-btn .fl-ic {
  width: 18px;
  height: 18px;
}

.fl-btn-primary {
  background: linear-gradient(135deg, #2f86e8, var(--s-primary-2));
  color: #fff;
  box-shadow: 0 8px 20px -10px rgba(31, 111, 224, 0.8);
}

.fl-btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
}

.fl-btn-primary:disabled {
  opacity: 0.5;
  cursor: default;
}

.fl-btn-ghost {
  background: var(--s-surface-2);
  color: var(--s-text);
  border: 1px solid var(--s-border);
}

.fl-btn-ghost:hover {
  border-color: var(--fl-accent);
}

.fl-submit {
  height: 50px;
  padding: 0 22px;
}

.fl-link {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: 800;
  color: var(--fl-accent);
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- guesses ---------- */

.fl-rows {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.fl-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto 26px 58px;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--s-surface);
  border: 1px solid var(--s-border);
  font-weight: 700;
  font-size: 15px;
}

.fl-row.is-empty {
  display: flex;
  justify-content: center;
  background: transparent;
  border-style: dashed;
  color: var(--s-muted);
  opacity: 0.6;
  font-size: 13px;
}

.fl-row.is-new {
  animation: fl-row-in 0.35s ease-out;
}

@keyframes fl-row-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

.fl-row.is-win {
  border-color: var(--fl-win);
  background: color-mix(in srgb, var(--fl-win) 12%, var(--s-surface));
}

.fl-row .fl-thumb {
  width: 36px;
  height: 24px;
}

.fl-row-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fl-row-km {
  color: var(--s-muted);
  font-size: 14px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.fl-dir {
  width: 24px;
  height: 24px;
  color: var(--fl-accent);
  transition: transform 0.4s;
}

.fl-dir.is-win {
  color: var(--fl-win);
}

.fl-row-pct {
  justify-self: end;
  min-width: 52px;
  padding: 3px 6px;
  border-radius: 8px;
  text-align: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(90deg, color-mix(in srgb, var(--fl-accent) 28%, transparent) var(--p), var(--s-surface-2) var(--p));
}

.fl-practice-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

/* ---------- end of round ---------- */

.fl-end {
  margin-top: 14px;
  padding: 16px;
  border-radius: 16px;
  text-align: center;
  background: var(--s-surface);
  border: 1px solid var(--s-border);
  box-shadow: var(--s-shadow);
  animation: fl-row-in 0.35s ease-out;
}

.fl-end.is-win {
  border-color: color-mix(in srgb, var(--fl-win) 55%, var(--s-border));
}

.fl-end-msg {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 800;
}

.fl-end-answer {
  margin: 0 0 12px;
  color: var(--s-muted);
  font-weight: 700;
}

.fl-end-answer a {
  font-weight: 800;
}

.fl-end-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.fl-countdown {
  margin: 12px 0 0;
  color: var(--s-muted);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.fl-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.fl-confetti i {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  animation: fl-fall 1.6s ease-in forwards;
}

@keyframes fl-fall {
  to {
    transform: translate(var(--x), 120%) rotate(540deg);
    top: 100%;
    opacity: 0.2;
  }
}

/* ---------- toast ---------- */

.fl-toast {
  position: absolute;
  left: 50%;
  top: 120px;
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #0f1b2d;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

html.dark .fl-toast {
  background: #e8eef8;
  color: #0f1b2d;
}

.fl-toast.is-on {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- modals ---------- */

.fl-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 14, 26, 0.55);
  animation: fl-fade 0.15s ease-out;
  font-family: var(--s-font);
}

@keyframes fl-fade {
  from {
    opacity: 0;
  }
}

.fl-modal-card {
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 18px 20px 20px;
  border-radius: 20px;
  background: var(--s-surface);
  color: var(--s-text);
  box-shadow: var(--s-shadow-lg);
  animation: fl-row-in 0.2s ease-out;
}

.fl-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.fl-modal-head h3 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
}

.fl-modal h4 {
  margin: 18px 0 8px;
  font-size: 15px;
  font-weight: 800;
}

.fl-modal p {
  margin: 0 0 10px;
  line-height: 1.5;
}

.fl-muted {
  color: var(--s-muted);
  font-size: 14px;
}

.fl-example {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.fl-example figure {
  margin: 0;
  text-align: center;
  font-weight: 700;
  font-size: 13px;
}

.fl-ex-flag {
  width: 150px;
  height: 100px;
  border-radius: 8px;
  display: block;
  box-shadow: inset 0 0 0 1px var(--s-border);
}

.fl-ex-hidden {
  background: var(--fl-hidden);
}

.fl-ex-arrow {
  font-size: 24px;
  font-weight: 800;
  color: var(--s-muted);
}

.fl-example p {
  flex-basis: 100%;
  text-align: center;
}

.fl-stat-nums {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  text-align: center;
}

.fl-stat-nums b {
  display: block;
  font-size: 30px;
  font-weight: 800;
  line-height: 1.1;
}

.fl-stat-nums span {
  font-size: 12px;
  color: var(--s-muted);
  font-weight: 700;
}

.fl-bars {
  display: grid;
  gap: 5px;
}

.fl-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 14px;
}

.fl-bar-row > span {
  width: 12px;
}

.fl-bar-fill {
  display: flex;
  justify-content: flex-end;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--s-surface-3);
  color: var(--s-text);
  font-size: 13px;
}

.fl-bar-fill.is-today {
  background: var(--fl-win);
  color: #fff;
}

.fl-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--s-border);
  cursor: pointer;
}

.fl-switch:last-child {
  border-bottom: 0;
}

.fl-switch-text {
  flex: 1;
  display: grid;
}

.fl-switch-text small {
  color: var(--s-muted);
  font-size: 13px;
  font-weight: 600;
}

.fl-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.fl-switch-ui {
  position: relative;
  width: 46px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: 99px;
  background: var(--s-surface-3);
  transition: background 0.15s;
}

.fl-switch-ui::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}

.fl-switch input:checked + .fl-switch-ui {
  background: var(--fl-accent);
}

.fl-switch input:checked + .fl-switch-ui::after {
  transform: translateX(18px);
}

.fl-switch input:focus-visible + .fl-switch-ui {
  outline: 2px solid var(--fl-accent);
  outline-offset: 2px;
}

.fl-cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 0;
  text-transform: capitalize;
}

.fl-cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.fl-cal-wd {
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--s-muted);
  padding: 4px 0;
  text-transform: uppercase;
}

.fl-cal-day {
  aspect-ratio: 1;
  border: 1px solid var(--s-border);
  border-radius: 10px;
  background: var(--s-surface);
  color: var(--s-text);
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
}

.fl-cal-day:hover:not(:disabled) {
  border-color: var(--fl-accent);
}

.fl-cal-day:disabled {
  opacity: 0.3;
  cursor: default;
}

.fl-cal-day.is-won {
  background: var(--fl-win);
  border-color: var(--fl-win);
  color: #fff;
}

.fl-cal-day.is-lost {
  background: var(--fl-lose);
  border-color: var(--fl-lose);
  color: #fff;
}

.fl-cal-day.is-started {
  border-color: #f5a524;
  box-shadow: inset 0 0 0 2px #f5a524;
}

.fl-cal-day.is-current {
  outline: 2px solid var(--fl-accent);
  outline-offset: 1px;
}

@media (max-width: 420px) {
  .fl-app {
    padding: 10px 12px 6px;
  }
  .fl-tab {
    padding: 7px 10px;
    font-size: 13px;
  }
  .fl-icon-btn {
    width: 36px;
    height: 36px;
  }
  .fl-row {
    grid-template-columns: 30px minmax(0, 1fr) auto 22px 50px;
    gap: 7px;
    padding: 6px 8px;
    font-size: 14px;
  }
  .fl-row .fl-thumb {
    width: 30px;
    height: 20px;
  }
  .fl-row-km {
    font-size: 13px;
  }
  .fl-submit {
    padding: 0 16px;
  }
  .fl-revealed {
    font-size: 13px;
  }
  .fl-stat-nums b {
    font-size: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fl-app *,
  .fl-modal * {
    animation: none !important;
    transition: none !important;
  }
}
