/*
 * Shared components for slivce-node pages. One file instead of the
 * ~200-line inline <style> block duplicated per page in the old Django
 * templates (see the migration design review for the specific numbers).
 * Requires tokens.css to be loaded first.
 */

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--accent-soft);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

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

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
}

.wordmark {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.header-controls {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.theme-custom {
  position: relative;
}

.theme-custom-panel {
  position: absolute;
  top: 46px;
  right: 0;
  z-index: 20;
  width: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/*
 * `display: flex` above beats the browser's own `[hidden] { display: none }`
 * rule, because author CSS always outranks the user-agent stylesheet
 * regardless of selector specificity - so JS toggling the `hidden`
 * attribute alone never actually hid this panel. This rule (class +
 * attribute selector, higher specificity than `.theme-custom-panel` alone)
 * restores the expected behavior.
 */
.theme-custom-panel[hidden] {
  display: none;
}

.theme-custom-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.theme-custom-title {
  margin: 0;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

.theme-custom-close {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--ink-faint);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.theme-custom-close:hover {
  background: var(--surface-sunken);
  color: var(--ink);
}

.theme-custom-panel label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.theme-custom-panel input[type="color"] {
  width: 40px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
}

.wordmark .dot {
  color: var(--accent);
}

.page-center {
  display: flex;
  justify-content: center;
  padding: var(--space-6) var(--space-4) var(--space-7);
}

/* ---------- Sheet (form card) ---------- */

.sheet {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-6) var(--space-5) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.sheet.is-wide {
  max-width: 460px;
}

.sheet h1 {
  font-family: var(--serif);
  font-size: 1.5rem;
  margin: 0;
  text-align: center;
  color: var(--ink);
}

.back-link {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--ink-soft);
}

.back-link:hover {
  color: var(--accent);
}

/* ---------- Forms ---------- */

form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.field .input-row {
  position: relative;
  display: flex;
}

input[type="text"],
input[type="password"],
input[type="email"] {
  width: 100%;
  font-family: var(--sans);
  font-size: 1rem;
  padding: 10px 12px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus {
  border-color: var(--accent);
}

.field .input-row.has-toggle input {
  padding-right: 42px;
}

.eye-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 4px;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--ink-faint);
}

.field-hint {
  font-size: 0.8rem;
  color: var(--ink-faint);
}

.form-message {
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.form-message.is-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.form-message.is-hidden {
  display: none;
}

.form-footer {
  display: flex;
  justify-content: center;
  gap: var(--space-4);
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.form-footer a {
  text-decoration: none;
  font-weight: 600;
}

.form-footer a:hover {
  text-decoration: underline;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 0.98rem;
  font-weight: 600;
  padding: 11px 22px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-secondary {
  background: var(--surface-sunken);
  color: var(--ink);
  border: 1px solid var(--line-strong);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-block {
  width: 100%;
}

/*
 * Same cascade-origin footgun as .theme-custom-panel below: `display:
 * inline-flex` above is author CSS and always beats the UA stylesheet's
 * `[hidden] { display: none }`, so a `.btn` toggled via the `hidden`
 * attribute/property (e.g. index.html's #ostrivecLink, game.html's
 * auth-only links) would stay visible without this explicit override.
 */
.btn[hidden] {
  display: none;
}

@media (prefers-reduced-motion: no-preference) {
  .btn:hover {
    transform: translateY(-1px);
    opacity: 0.94;
  }
}

/* ---------- Theme toggle ---------- */

.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

/* ---------- Stats (profile page) ---------- */

.profile-identity {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}

.profile-identity .username {
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 700;
}

.profile-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}

.stat-card {
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-card .stat-label {
  font-size: 0.76rem;
  color: var(--ink-faint);
}

.stat-card .stat-value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
}

/*
 * Guess-distribution chart (replaces the old 2x3 grid of boxes, which left
 * an orphaned 6th box alone on its own row). Single series (one player's
 * own counts), so one hue throughout - no categorical palette needed. Mark
 * spec follows the dataviz skill: bars capped at 20px thick, 4px rounded
 * at the data-end / square at the baseline, value directly labeled at the
 * tip since bar length varies too much for a reliably-fitting inline label.
 */

.attempt-chart {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.attempt-row {
  display: grid;
  grid-template-columns: 16px 1fr minmax(28px, auto);
  align-items: center;
  gap: var(--space-3);
}

.attempt-row .attempt-n {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-faint);
  text-align: center;
}

.attempt-track {
  height: 20px;
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.attempt-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 0 4px 4px 0;
  transition: width 0.4s ease;
}

.attempt-row:hover .attempt-track,
.attempt-row:focus-within .attempt-track {
  background: var(--accent-soft);
}

.attempt-row .attempt-count {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  text-align: right;
}

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

.section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  margin: 0;
}

.empty-note {
  font-size: 0.92rem;
  color: var(--ink-faint);
  text-align: center;
}

/*
 * Hero (index / game hub): lighter-touch than .sheet on purpose - these
 * are navigation screens, not forms, so a bordered card for every single
 * page would make the whole site read as one repeated template.
 */

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  text-align: center;
  width: 100%;
  max-width: 340px;
}

.hero h1 {
  font-family: var(--serif);
  font-size: 2rem;
  margin: 0 0 var(--space-2);
  text-wrap: balance;
}

.hero .btn {
  width: 100%;
}

.hero .btn svg {
  flex-shrink: 0;
}

/* ---------- Leaderboard ---------- */

.table-scroll {
  overflow-x: auto;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.leaderboard-table th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}

.leaderboard-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.leaderboard-table tbody tr:hover {
  background: var(--surface-sunken);
}

.leaderboard-table th:first-child,
.leaderboard-table td:first-child {
  width: 48px;
  font-family: var(--mono);
  color: var(--ink-faint);
}

.leaderboard-table th:last-child,
.leaderboard-table td:last-child {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
