/* Cosmeredle — design tokens and components.
   Replaces the Tailwind Play CDN, which is a development-only tool and
   forces `script-src` to allow a third-party origin. */

:root {
  /* Surfaces */
  --bg: #0f111a;
  --surface-1: #171a27;
  --surface-2: #1e2233;
  --surface-raised: #0b0d16;
  --border: #2c3145;
  --border-strong: #3d4459;

  /* Text */
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --text-inverse: #ffffff;

  /* Brand */
  --accent-from: #2563eb;
  --accent-to: #7c3aed;
  --accent: #6366f1;
  --accent-soft: #a5b4fc;

  /* Guess statuses. Every status also carries a text label in the cell,
     so colour is never the only channel conveying meaning. */
  --status-correct: #15803d;
  --status-partial: #a16207;
  --status-incorrect: #374151;
  --status-fewer: #1d4ed8;
  --status-more: #6d28d9;

  --danger: #b91c1c;
  --success: #15803d;

  /* Scale */
  --radius-sm: 0.375rem;
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --gap: 0.5rem;
  --shell-width: 64rem;

  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    Roboto, sans-serif;
  --font-display: "Cinzel", ui-serif, Georgia, "Times New Roman", serif;

  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.4), 0 8px 10px -6px rgb(0 0 0 / 0.4);

  --transition: 150ms ease;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 2.5rem 1rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  background-color: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

h1,
h2,
h3,
.display {
  font-family: var(--font-display);
  margin: 0;
}

:where(button, input):focus-visible,
:where([tabindex]):focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
}

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

[hidden] {
  display: none !important;
}

/* ---------------------------------------------------------------- Backdrop */

.mist-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.mist {
  position: absolute;
  inset: -50% -50%;
  background: radial-gradient(
    circle at center,
    rgb(76 29 149 / 0.15) 0%,
    rgb(30 58 138 / 0.05) 40%,
    transparent 70%
  );
  animation: drift 20s infinite alternate ease-in-out;
}

.mist:nth-child(2) {
  background: radial-gradient(
    circle at 70% 30%,
    rgb(55 48 163 / 0.1) 0%,
    transparent 60%
  );
  animation-duration: 25s;
  animation-direction: alternate-reverse;
}

@keyframes drift {
  from {
    transform: translate(0, 0) scale(1);
  }
  to {
    transform: translate(5%, 5%) scale(1.1);
  }
}

/* ------------------------------------------------------------------ Layout */

.shell {
  width: 100%;
  max-width: var(--shell-width);
}

.site-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 1rem;
  margin-bottom: 2rem;
}

.site-title {
  grid-column: 2;
  font-size: clamp(2rem, 6vw, 3.75rem);
  font-weight: 700;
  text-align: center;
  background: linear-gradient(to right, #60a5fa, #a855f7);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.site-header__auth {
  grid-column: 3;
  justify-self: end;
}

.site-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

/* ----------------------------------------------------------------- Buttons */

.btn {
  font: inherit;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    background-color var(--transition),
    border-color var(--transition),
    transform var(--transition),
    opacity var(--transition);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--primary {
  background-image: linear-gradient(
    to right,
    var(--accent-from),
    var(--accent-to)
  );
  color: var(--text-inverse);
  box-shadow: var(--shadow);
}

.btn--primary:hover:not(:disabled) {
  filter: brightness(1.15);
}

.btn--primary:active:not(:disabled) {
  transform: scale(0.97);
}

.btn--secondary {
  background-color: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn--secondary:hover:not(:disabled) {
  background-color: var(--border);
}

.btn--link {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
  text-decoration: underline;
  cursor: pointer;
}

.btn--link:hover {
  color: var(--text-inverse);
}

.btn--icon {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}

.btn--icon:hover {
  color: var(--text-inverse);
}

/* ------------------------------------------------------------------ Inputs */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field__label {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.input {
  font: inherit;
  width: 100%;
  padding: 0.5rem 0.75rem;
  color: var(--text);
  background-color: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.input::placeholder {
  color: var(--text-faint);
}

.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.input:disabled {
  opacity: 0.6;
}

/* --------------------------------------------------------------- Auth area */

.auth-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.125rem;
}

.auth-status__name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--accent-soft);
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-actions {
  display: flex;
  gap: 0.75rem;
}

/* ------------------------------------------------------------------ Dialog */

.dialog {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background-color: var(--surface-1);
  color: var(--text);
  padding: 2rem;
  width: min(28rem, calc(100vw - 2rem));
  box-shadow: var(--shadow-lg);
}

.dialog::backdrop {
  background-color: rgb(0 0 0 / 0.6);
  backdrop-filter: blur(4px);
}

.dialog__close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
}

.dialog__title {
  font-size: 1.5rem;
  text-align: center;
  color: #60a5fa;
  margin-bottom: 1.5rem;
}

.dialog__form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.dialog__form .btn--primary {
  margin-top: 0.5rem;
}

/* -------------------------------------------------------------- Guess form */

.guess-form {
  position: relative;
  display: flex;
  gap: var(--gap);
  width: 100%;
  max-width: 28rem;
  margin-bottom: 2.5rem;
}

.guess-form__input {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
}

.guess-form__submit {
  padding: 0.75rem 1.5rem;
}

.combobox-list {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  z-index: 30;
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 15rem;
  overflow-y: auto;
  background-color: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.combobox-list__option {
  padding: 0.5rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.combobox-list__option:last-child {
  border-bottom: none;
}

.combobox-list__option:hover,
.combobox-list__option[aria-selected="true"] {
  background-color: var(--accent);
  color: var(--text-inverse);
}

/* ------------------------------------------------------------- Guess board */

.board {
  width: 100%;
}

.board__row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--gap);
  width: 100%;
  max-width: 62.5rem;
  margin: 0 auto var(--gap);
}

.board__head {
  font-family: var(--font-display);
  color: var(--text-muted);
  font-size: 0.875rem;
  letter-spacing: 0.05em;
}

.board__head > * {
  text-align: center;
  font-weight: 700;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-strong);
}

.cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  text-align: center;
  padding: 0.75rem 0.5rem;
  min-height: 5rem;
  border-radius: var(--radius);
  border: 1px solid rgb(255 255 255 / 0.06);
  box-shadow: var(--shadow);
  font-weight: 600;
  /* `anywhere` also shrinks min-content width, which chopped short words mid
     way across on narrow screens; `break-word` only breaks what cannot fit. */
  overflow-wrap: break-word;
  background-color: var(--status-incorrect);
  color: var(--text-inverse);
}

/* Children of the column-flex cell size to their content on the cross axis,
   so without this a long ability list escapes the cell and can widen the page. */
.cell > * {
  max-width: 100%;
}

.cell__label {
  display: none;
  font-family: var(--font-display);
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
  overflow-wrap: normal;
}

.cell__value {
  font-size: 0.875rem;
}

.cell--correct {
  background-color: var(--status-correct);
}
.cell--partial {
  background-color: var(--status-partial);
}
.cell--incorrect {
  background-color: var(--status-incorrect);
  color: var(--text);
}
.cell--fewer {
  background-color: var(--status-fewer);
}
.cell--more {
  background-color: var(--status-more);
}

.cell--animated {
  animation: flip-in 600ms ease forwards;
  opacity: 0;
  transform: rotateX(-90deg);
}

@keyframes flip-in {
  from {
    transform: rotateX(-90deg);
    opacity: 0;
  }
  to {
    transform: rotateX(0);
    opacity: 1;
  }
}

/* ------------------------------------------------------------------ Banner */

.banner {
  width: 100%;
  max-width: 62.5rem;
  margin: 0 auto 1.5rem;
  padding: 1.25rem;
  text-align: center;
  border-radius: var(--radius-lg);
  border: 1px solid var(--status-correct);
  background-color: rgb(21 128 61 / 0.15);
}

.banner__title {
  font-size: 1.5rem;
  color: #4ade80;
}

.banner__detail {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------ Legend */

.legend {
  width: 100%;
  max-width: 48rem;
  margin-top: 3rem;
  padding: 1rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background-color: rgb(30 34 51 / 0.5);
}

.legend__title {
  font-size: 1.125rem;
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.legend__items {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.875rem;
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.legend__swatch {
  width: 1rem;
  height: 1rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

/* ------------------------------------------------------------------ Toasts */

.toast-region {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  pointer-events: none;
  max-width: min(24rem, calc(100vw - 2rem));
}

.toast {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid;
  color: var(--text-inverse);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  overflow-wrap: anywhere;
  transition: opacity 300ms ease;
}

.toast--error {
  background-color: var(--danger);
  border-color: #ef4444;
}

.toast--success {
  background-color: var(--success);
  border-color: #22c55e;
}

.toast--leaving {
  opacity: 0;
}

/* ------------------------------------------------------------- Scrollbars  */

* {
  scrollbar-color: #312e81 var(--bg);
}

::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: #312e81;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #4338ca;
}

/* ------------------------------------------------------------ Small screens */

@media (max-width: 48rem) {
  body {
    padding: 1.5rem 0.5rem;
  }

  .board__head {
    display: none;
  }

  /* Headers are gone, so each cell names its own column. */
  .cell__label {
    display: block;
  }

  .board__row {
    gap: 0.25rem;
  }

  .cell {
    padding: 0.5rem 0.25rem;
    min-height: 4.5rem;
  }

  .cell__value {
    font-size: 0.75rem;
  }

  .site-header {
    grid-template-columns: 1fr;
  }

  .site-title,
  .site-header__auth {
    grid-column: 1;
    justify-self: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }

  .cell--animated {
    opacity: 1;
    transform: none;
  }
}

.toast-region__live {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.dialog[open] {
  animation: dialog-in 180ms ease-out;
}

.dialog[open]::backdrop {
  animation: backdrop-in 180ms ease-out;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
}

@keyframes backdrop-in {
  from {
    opacity: 0;
  }
}
