/* Random tools on the site shell: /coin-flip/, /dice-roller/,
   /random-number-generator/, /random-team-generator/ (tools, lime), and the
   shared page parts the arcade games reuse (.random-page, .random-article;
   the FAQ is the shared .faq-block). Loaded after games.css, which owns the page frame (the
   .rt-play / .ar-play column, the one-line h1 and its subline) and the SEO
   section rhythm. Replaces input-lab.css + random-tools/style.css on these
   pages. Tokens only, logical properties, one accent via body[data-accent]. */

/* ── Legacy variable bridge ──────────────────────────────────────────────
   The arcade game sheets still read the old Input Lab names. Zero
   specificity so a theme loaded later always wins. */
:where(body[data-random-tools]) {
  --lab-raised: var(--surface-2);
  --lab-raised-hover: var(--surface-3);
  --lab-border: var(--border);
  --lab-hairline: var(--border-strong);
  --lab-text: var(--text-muted);
}

/* ── Base controls inside the tool (low specificity: game sheets win) ─── */
:where(.random-page) button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-block-size: var(--tap);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--step--1);
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition:
    background-color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}
:where(.random-page) button > i { font-size: 0.95em; color: var(--accent); }
@media (hover: hover) and (pointer: fine) {
  :where(.random-page) button:hover:not(:disabled) { border-color: var(--border-control); background: var(--surface-3); }
}
:where(.random-page) button:active:not(:disabled) { transform: translateY(1px); }
:where(.random-page) button:disabled { opacity: 0.45; cursor: default; }
:where(.random-page) :is(input:not([type="checkbox"]), textarea) {
  display: block;
  box-sizing: border-box;
  inline-size: 100%;
  min-inline-size: 0;
  min-block-size: var(--tap);
  padding: 10px var(--space-4);
  border: 1px solid var(--border-control);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
  color: var(--text);
  font-size: max(16px, var(--step-0));
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  caret-color: var(--accent);
  transition: border-color var(--dur-fast) var(--ease);
}
:where(.random-page) :is(input:not([type="checkbox"]), textarea):hover,
:where(.random-page) :is(input:not([type="checkbox"]), textarea):focus-visible { border-color: var(--primary); }
:where(.random-page) textarea { min-block-size: 7.5rem; resize: vertical; line-height: 1.5; }
:where(.random-page) textarea::placeholder { color: var(--text-faint); opacity: 1; }
:where(.random-page) [aria-invalid="true"] { border-color: var(--danger) !important; }
:where(.random-page) [aria-invalid="true"]:focus-visible { outline-color: var(--danger); }
.random-page [hidden] { display: none !important; }

/* ── Workspace: a category panel, controls beside the result readout ──── */
.random-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  inline-size: 100%;
  max-inline-size: 60rem;
  margin-inline: auto !important;
  overflow: hidden;
  border: 1px solid var(--border);
  border-block-start-color: var(--accent);
  border-radius: var(--radius-lg);
  background: var(--surface-1);
  box-shadow: var(--shadow-1);
  position: relative;
}
/* The 2px inner accent line sits above both halves (the result half has
   its own Hull fill, which would cover a background-drawn strip). */
.random-workspace::before {
  content: '';
  position: absolute;
  inset-inline: 0;
  inset-block-start: 0;
  z-index: 1;
  block-size: 2px;
  background: var(--accent);
  pointer-events: none;
}
@media (min-width: 768px) {
  .random-workspace { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
}
.random-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-5);
}
.random-range { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.random-field { display: flex; flex-direction: column; gap: var(--space-2); min-inline-size: 0; }
.random-field label,
.random-check { color: var(--text); font-size: 0.95rem; font-weight: 500; line-height: 1.25; }
.random-label-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-1) var(--space-3); }
.random-help { margin: 0; color: var(--text-muted); font-size: var(--step--1); line-height: 1.5; }
.random-check { display: flex; align-items: center; gap: var(--space-3); min-block-size: var(--tap); cursor: pointer; }
.random-check input { inline-size: 20px; block-size: 20px; margin: 0; accent-color: var(--accent); }

/* Primary action: the category CTA (accent fill, Void Ink text). */
.random-page .random-submit {
  justify-content: space-between;
  inline-size: 100%;
  min-block-size: 48px;
  padding-inline: var(--space-5);
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: var(--step-0);
  box-shadow: var(--shadow-1);
}
.random-page .random-submit > i { color: inherit; }
@media (hover: hover) and (pointer: fine) {
  .random-page .random-submit:hover:not(:disabled) { border-color: transparent; background: color-mix(in srgb, var(--accent) 86%, white); }
}
[dir="rtl"] .random-submit > i,
[dir="rtl"] .random-back > i { transform: scaleX(-1); }

/* Text action ("Use example names"). */
.random-page .random-text-button {
  min-block-size: var(--tap);
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font-size: var(--step--1);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--accent) 60%, transparent);
  text-underline-offset: 5px;
}
@media (hover: hover) and (pointer: fine) {
  .random-page .random-text-button:hover:not(:disabled) { background: none; text-decoration-color: var(--accent); }
}

/* Dice presets: chips; the picked one takes the selected (violet) state. */
.random-presets { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.random-page .random-presets button {
  position: relative;
  min-block-size: 32px;
  padding: 0 var(--space-3);
  border-color: var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.random-page .random-presets button::after { content: ''; position: absolute; inset: -6px 0; }
.random-page .random-presets button[aria-pressed="true"] {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 18%, var(--surface-2));
  color: var(--text);
}

/* Coin preview: the 50 / 50 odds in the display face. */
.random-coin-preview {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding-block-start: 0.1em;
  color: var(--text);
  font-family: var(--font-display);
  font-size: var(--step-4);
  font-weight: 600;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}
.random-coin-preview > span:nth-child(2) { color: var(--text-faint); font-size: 0.6em; }

/* "More options" disclosure. */
.random-options > summary,
.random-history > summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-block-size: var(--tap);
  color: var(--text);
  font-size: var(--step--1);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
:is(.random-options, .random-history) > summary::-webkit-details-marker { display: none; }
:is(.random-options, .random-history) > summary::after {
  content: '';
  inline-size: 7px;
  block-size: 7px;
  margin-block-start: -3px;
  border-inline-end: 2px solid var(--accent);
  border-block-end: 2px solid var(--accent);
  transform: rotate(45deg);
  transition: transform var(--dur-med) var(--ease);
}
:is(.random-options, .random-history)[open] > summary::after { margin-block-start: 3px; transform: rotate(-135deg); }
.random-options > div { display: flex; flex-direction: column; gap: var(--space-3); padding-block-start: var(--space-2); }

/* ── Result: the readout half, on Hull ────────────────────────────────── */
.random-result {
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
  padding: var(--space-5);
  border-block-start: 1px solid var(--border);
  background: var(--bg-raised);
}
@media (min-width: 768px) {
  .random-result { border-block-start: 0; border-inline-start: 1px solid var(--border); }
}
.random-result > h2 {
  margin: 0;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: var(--step-0);
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding-block-start: 0.12em;
}
:lang(ar) .random-result > h2 { letter-spacing: 0; }
.random-output {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  min-block-size: 7rem;
  margin-block: var(--space-3);
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
  user-select: text;
  -webkit-user-select: text;
}
.random-placeholder { margin: 0; color: var(--text-muted); line-height: 1.6; }
.random-coin,
.random-total,
.random-number:only-child {
  margin: 0;
  padding: 0.1em 0 0;
  background: none;
  color: var(--accent);
  font-family: var(--font-display);
  font-size: var(--step-5);
  font-weight: 600;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}
:lang(zh) .random-coin, :lang(ja) .random-coin { font-family: var(--font-body); font-weight: 700; font-size: var(--step-4); line-height: 1.15; }
:lang(ar) .random-coin { line-height: 1.3; }
.random-number-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  max-block-size: 22rem;
  overflow: auto;
}
.random-number {
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  color: var(--text);
  font-family: var(--font-display);
  font-size: var(--step-2);
  font-weight: 600;
  line-height: 1.1;
  padding-block-start: calc(var(--space-1) + 0.1em);
}
.random-number:only-child { border: 0; }
/* Dice: each die a small key with a 2px bottom edge, Teko numerals. */
.random-dice {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  max-block-size: 16rem;
  margin: var(--space-3) 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}
.random-dice > li {
  display: grid;
  place-items: center;
  min-inline-size: 44px;
  min-block-size: 44px;
  padding: var(--space-1) var(--space-2) 0;
  border: 1px solid var(--border-control);
  border-block-end-width: 3px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 600;
  line-height: 1;
}
/* Teams: each team a Deck 1 card; heading in the accent. */
.random-teams {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(9rem, 100%), 1fr));
  gap: var(--space-3);
  max-block-size: 28rem;
  overflow: auto;
}
.random-team {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-1);
}
.random-team > h3 {
  margin: 0 0 var(--space-2);
  color: var(--accent);
  font-family: var(--font-body);
  font-size: var(--step--1);
  font-weight: 600;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.random-team > ul { margin: 0; padding-inline-start: 1.1em; color: var(--text); line-height: 1.7; overflow-wrap: anywhere; }
.random-team li::marker { color: var(--accent); }
.random-result-footer { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.random-page .random-result-footer button { min-block-size: 36px; padding-inline: var(--space-3); position: relative; }
.random-page .random-result-footer button::after { content: ''; position: absolute; inset: -4px 0; }
#result-summary,
#copy-status { color: var(--text-muted); font-size: var(--step--1); line-height: 1.5; }
#result-summary { margin: 0 0 var(--space-3); }
#result-summary:empty,
#random-error:empty,
#copy-status:empty { display: none; }
#random-error { margin: 0; color: var(--danger); line-height: 1.5; }

/* ── Under the tool: history and privacy note ─────────────────────────── */
.random-history,
.random-privacy { inline-size: 100%; max-inline-size: 60rem; margin-inline: auto !important; }
.random-history { padding-inline: var(--space-1); }
.random-history > :not(summary) + * { margin-block-start: var(--space-3); }
.random-history > ol { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-3) 0 0; padding: 0; list-style: none; }
.random-history li {
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--step--1);
}
.random-history li:first-child { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); color: var(--text); }
.random-page #clear-history { margin-block-start: var(--space-3); }
.random-privacy { color: var(--text-muted); text-align: center; }

/* ── Article and FAQ (SEO section) ─────────────────────────────────────── */
.random-article { max-inline-size: 68ch; margin-inline: auto; color: var(--text-muted); line-height: 1.7; }
.random-article > section + section { margin-block-start: var(--space-7); }
.random-article h2 {
  margin: 0 0 var(--space-3);
  color: var(--text);
  font-family: var(--font-display);
  font-size: var(--step-3);
  font-weight: 600;
  line-height: 0.95;
  text-transform: uppercase;
  text-wrap: balance;
}
:lang(zh) .random-article h2, :lang(ja) .random-article h2 { font-family: var(--font-body); font-weight: 700; font-size: var(--step-2); line-height: 1.15; }
:lang(ru) .random-article h2, :lang(hi) .random-article h2 { line-height: 1.15; }
:lang(ar) .random-article h2 { line-height: 1.4; }
.random-article p { margin: 0; }
.random-article p + p { margin-block-start: var(--space-4); }

/* Related tools: link chips with an accent icon; the Input Lab link leads. The row and the FAQ after it leave the
   centred article column and open on the h1 edge, like every family's closing blocks. */
.random-related {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: var(--space-2);
  margin-block-start: var(--space-8);
}
.random-related > a {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-block-size: 36px;
  padding-inline: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--step--1);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.random-related > a::after { content: ''; position: absolute; inset: -4px 0; }
.random-related > a > i { color: var(--accent); font-size: 0.9em; }
.random-related > a:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); background: var(--surface-3); color: var(--text); }

/* ── Browser surfaces ──────────────────────────────────────────────────── */
.random-page ::selection { background: color-mix(in srgb, var(--accent) 38%, transparent); color: var(--text); }
:is(.random-number-list, .random-dice, .random-teams) { scrollbar-color: var(--border-strong) var(--bg-raised); scrollbar-width: thin; }

@media (max-width: 380px) {
  .random-controls, .random-result { padding: var(--space-4); }
  .random-range { gap: var(--space-3); }
}
@media (prefers-reduced-motion: reduce) {
  :where(.random-page) button,
  :is(.random-options, .random-history) > summary::after { transition: none; }
}
