/* Elder Games shared styles. Tokens come from mockups/tokens (UX_DESIGN.md section 2); no inline styles are used anywhere. */
:root {
  --bg: #FBF8F3;
  --surface: #FFFFFF;
  --primary: #2E6B5E;
  --primary-light: #E1EFEA;
  --accent: #C85C1D;
  --text: #2A2A28;
  --text-2: #6B6459;
  --border: #E6DFD3;
  --warn: #C9891A;
  --warn-text: #7A5200;
  --warn-bg: #FBEFD5;
  --ok: #2E6B5E;
  --on-primary: #FFFFFF;
  --strip: #1F4F45;
  --ink-on-yellow: #1A1A18;
  --scrim: rgba(0, 0, 0, 0.45);
  --border-w: 1px;
  --pad-red: #C0392B;
  --pad-green: #27865B;
  --pad-blue: #2B6CB0;
  --pad-yellow: #D69E2E;
  --radius: 12px;
  --radius-lg: 16px;
  --space: 12px;
  --target: 3.5rem;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}

html[data-contrast="on"] {
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --primary: #00483C;
  --primary-light: #D6EBE5;
  --accent: #9A3F00;
  --text: #000000;
  --text-2: #000000;
  --border: #000000;
  --warn: #7A5200;
  --warn-text: #000000;
  --warn-bg: #FFF1CC;
  --ok: #00483C;
  --border-w: 3px;
}

/* High contrast also marks <html> and <body> with .eg-high-contrast: black on white, 3 px borders, links underlined (never colour alone), buttons stay at least 56 px. */
.eg-high-contrast { color: #000000; background: #FFFFFF; }
.eg-high-contrast a { text-decoration: underline; }
.eg-high-contrast button, .eg-high-contrast .eg-btn, .eg-high-contrast .eg-iconbtn, .eg-high-contrast .eg-barbtn { border-width: 3px; min-height: 3.5rem; }
.eg-high-contrast [aria-checked="true"], .eg-high-contrast [aria-selected="true"], .eg-high-contrast [aria-pressed="true"] { text-decoration: underline; }

html { font-size: 16px; }
html[data-text-size="large"] { font-size: 20px; }
html[data-text-size="xlarge"] { font-size: 24px; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1.25rem;
  line-height: 1.45;
}

h1, h2, h3 { margin: 0 0 var(--space); line-height: 1.25; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
p { margin: 0 0 var(--space); }

button { font-family: inherit; }

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

/* Focus ring: always visible, 4px accent (FR-14). */
:focus { outline: 4px solid var(--accent); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
:focus-visible { outline: 4px solid var(--accent); outline-offset: 2px; }

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

[hidden] { display: none !important; }

/* Page structure */
.eg-page { max-width: 44rem; margin: 0 auto; min-height: 100vh; }
.eg-main { padding: var(--space); }

.eg-oldbrowser { background: var(--warn-bg); color: var(--warn-text); padding: var(--space); font-weight: 700; text-align: center; }

/* Top bar (teal) */
.eg-bar {
  background: var(--primary); color: var(--on-primary);
  padding: 8px var(--space);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}
.eg-bar-title { flex: 1 1 auto; text-align: center; font-size: 1.25rem; font-weight: 800; margin: 0; }
.eg-bar-title--wide { flex-basis: 100%; order: 5; }
.eg-bar-spacer { flex: 1 1 auto; }

.eg-iconbtn, .eg-barbtn {
  min-height: var(--target); min-width: var(--target);
  background: transparent; color: var(--on-primary);
  border: 2px solid var(--on-primary); border-radius: var(--radius);
  font-size: 1.125rem; font-weight: 800; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 0 var(--space);
  text-decoration: none;
}
.eg-bar :focus { outline-color: var(--on-primary); }
html[data-contrast="on"] .eg-iconbtn, html[data-contrast="on"] .eg-barbtn { border-width: 3px; }

/* Buttons */
.eg-btn {
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
  min-height: var(--target); min-width: var(--target); padding: 0.6rem 1.1rem;
  border: 2px solid var(--primary); border-radius: var(--radius);
  background: var(--surface); color: var(--primary);
  font-size: 1.375rem; font-weight: 800; cursor: pointer; text-decoration: none;
}
.eg-btn--accent { background: var(--accent); border-color: var(--accent); color: var(--on-primary); }
.eg-btn--block { display: flex; width: 100%; margin-top: var(--space); }
.eg-btn[disabled] { opacity: 0.55; cursor: default; }
html[data-contrast="on"] .eg-btn { border-width: 3px; }
.eg-btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: var(--space); }
.eg-btnrow > .eg-btn { flex: 1 1 8rem; margin-top: 0; }

/* Cards */
.eg-card {
  background: var(--surface); border: var(--border-w) solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; margin-bottom: var(--space);
}
.eg-center { text-align: center; }
.eg-muted { color: var(--text-2); font-size: 1.125rem; }
.eg-note { color: var(--text-2); font-size: 1.125rem; margin: 0 0 var(--space); }

.eg-greet {
  background: var(--primary-light); color: var(--primary);
  border-radius: var(--radius); padding: var(--space); font-size: 1.125rem; margin-bottom: var(--space);
}
.eg-strip { background: var(--strip); color: var(--on-primary); padding: 8px var(--space); border-radius: 8px; margin-bottom: 14px; font-size: 1.125rem; }

/* Game cards on the hub */
.eg-games { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 40rem) { .eg-games { grid-template-columns: 1fr 1fr; } }
.eg-gamecard {
  background: var(--surface); border: var(--border-w) solid var(--border);
  border-radius: 14px; padding: var(--space);
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space);
}
.eg-gameicon { font-size: 2.5rem; line-height: 1; }
.eg-gametext { flex: 1 1 8rem; min-width: 0; }
.eg-gametitle { font-size: 1.25rem; font-weight: 800; display: block; overflow-wrap: anywhere; }
.eg-gamedesc { color: var(--text-2); font-size: 1.125rem; overflow-wrap: anywhere; }
.eg-gamenote { flex-basis: 100%; margin: 0; color: var(--warn-text); font-weight: 700; font-size: 1.125rem; }
.eg-badge {
  display: inline-block; background: var(--primary-light); color: var(--primary);
  font-weight: 800; font-size: 1.125rem; border-radius: 20px; padding: 3px 10px; margin-top: 4px;
  border: var(--border-w) solid transparent;
}
html[data-contrast="on"] .eg-badge { border-color: var(--primary); }
.eg-skeleton { min-height: 7rem; background: var(--primary-light); border-radius: 14px; opacity: 0.7; animation: eg-pulse 1.4s ease-in-out infinite; }
@keyframes eg-pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 0.9; } }

/* Settings sheet */
.eg-overlay { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: var(--scrim); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.eg-sheet {
  background: var(--bg); width: 100%; max-width: 44rem; max-height: 100vh; overflow-y: auto;
  border-radius: 22px 22px 0 0; padding: 16px; border-top: var(--border-w) solid var(--border);
}
.eg-sheet h2 { margin-bottom: 4px; }
.eg-sheet-label { display: block; margin: 12px 0 6px; font-size: 1.25rem; font-weight: 800; }
.eg-seg { display: flex; border: 2px solid var(--primary); border-radius: var(--radius); overflow: hidden; }
html[data-contrast="on"] .eg-seg { border-width: 3px; }
.eg-seg button {
  flex: 1 1 0; min-height: var(--target); padding: 8px 4px; border: 0; border-left: 1px solid var(--primary);
  background: var(--surface); color: var(--primary); font-size: 1.125rem; font-weight: 800; cursor: pointer;
}
.eg-seg button:first-child { border-left: 0; }
.eg-seg button[aria-checked="true"] { background: var(--primary); color: var(--on-primary); }
.eg-seg button[aria-checked="true"]::before { content: "\2713\00a0"; }
.eg-seg :focus { outline-offset: -4px; }

/* Game shell */
.eg-status { min-height: 1.6em; font-size: 1.125rem; font-weight: 700; color: var(--primary); margin: 4px 0 var(--space); }
.eg-hud { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 var(--space); }
.eg-progress { font-size: 1.125rem; font-weight: 800; }
.eg-score {
  background: var(--primary-light); color: var(--primary); font-weight: 800; font-size: 1.125rem;
  border-radius: 20px; padding: 3px 12px; border: var(--border-w) solid transparent;
}
html[data-contrast="on"] .eg-score { border-color: var(--primary); }
.eg-steps { list-style: none; margin: 0 0 var(--space); padding: 0; }
.eg-step { font-size: 1.25rem; margin: 10px 0; display: flex; gap: 10px; align-items: flex-start; }
.eg-step-n { font-weight: 800; color: var(--primary); }
.eg-step-emoji { font-size: 1.75rem; line-height: 1.2; }
.eg-level {
  display: block; width: 100%; text-align: left; font: inherit; color: inherit;
  background: var(--surface); border: 2px solid var(--border); border-radius: 14px; padding: 14px; margin: 10px 0;
  min-height: 4.5rem; cursor: pointer;
}
html[data-contrast="on"] .eg-level { border-width: 3px; }
.eg-level-name { display: block; font-size: 1.25rem; font-weight: 800; }
.eg-level-desc { display: block; color: var(--text-2); font-size: 1.125rem; }
.eg-bigscore { font-size: 2.125rem; font-weight: 800; color: var(--primary); margin: 6px 0; }
.eg-ribbon { display: inline-block; background: var(--accent); color: var(--on-primary); font-weight: 800; border-radius: 20px; padding: 2px 12px; margin-left: 6px; }
.eg-saved { font-weight: 700; margin: var(--space) 0; }
.eg-saved--bad { color: var(--warn-text); }
.eg-banner { background: var(--warn-bg); color: var(--warn-text); border: 2px solid var(--warn); border-radius: var(--radius); padding: var(--space); font-weight: 700; margin: var(--space) 0; }
.eg-emoji { font-size: 2.625rem; line-height: 1.2; }

/* Building blocks for the games (from the mockup) */
.eg-grid { display: grid; gap: 8px; margin: 10px 0; }
.eg-g2 { grid-template-columns: repeat(2, 1fr); }
.eg-g3 { grid-template-columns: repeat(3, 1fr); }
.eg-g4 { grid-template-columns: repeat(4, 1fr); }
.eg-g5 { grid-template-columns: repeat(5, 1fr); }
.eg-g6 { grid-template-columns: repeat(6, 1fr); }
.eg-tile {
  min-height: var(--target); min-width: var(--target); border-radius: var(--radius); border: 2px solid var(--primary);
  background: var(--primary); color: var(--on-primary); font-size: 1.625rem; font-weight: 800; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 4px;
}
.eg-tile--up { background: var(--surface); color: var(--text); }
.eg-tile--ok { background: var(--primary-light); border-color: var(--ok); color: var(--text); }
.eg-tile--hint { box-shadow: 0 0 0 4px var(--accent); }
.eg-tile--gap { background: transparent; border: 2px dashed var(--text-2); cursor: default; }
.eg-pad { min-height: 6rem; border-radius: var(--radius-lg); border: 0; color: var(--on-primary); font-size: 1.25rem; font-weight: 800; cursor: pointer; }
.eg-pad--red { background: var(--pad-red); }
.eg-pad--green { background: var(--pad-green); }
.eg-pad--blue { background: var(--pad-blue); }
.eg-pad--yellow { background: var(--pad-yellow); color: var(--ink-on-yellow); }
.eg-pad--ring { box-shadow: 0 0 0 6px var(--on-primary), 0 0 0 10px var(--accent); }
.eg-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.eg-keys button { min-height: var(--target); background: var(--surface); color: var(--primary); border: 2px solid var(--primary); border-radius: var(--radius); font-size: 1.375rem; font-weight: 800; cursor: pointer; }
.eg-answer {
  min-height: 4.5rem; background: var(--surface); color: var(--text); border: 2px solid var(--primary); border-radius: 14px;
  font-size: 1.625rem; font-weight: 800; padding: 12px 8px; cursor: pointer;
}
.eg-answer--ok { background: var(--primary-light); }
.eg-answer--warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn-text); font-size: 1.125rem; }
.eg-meter { height: 10px; border-radius: 5px; background: var(--primary-light); margin: 6px 0 14px; overflow: hidden; }
.eg-meter > span { display: block; height: 100%; background: var(--primary); }
.eg-shake { animation: eg-shake 0.3s; }
@keyframes eg-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* Reduced motion: no flips, shakes or pulses, only an instant change. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Hub tabs and the two-player games (Play Together) */
.eg-tabs { display: flex; gap: 8px; margin-bottom: var(--space); }
.eg-tab {
  flex: 1 1 0; min-height: var(--target); padding: 8px; border: 2px solid var(--primary); border-radius: var(--radius);
  background: var(--surface); color: var(--primary); font-size: 1.125rem; font-weight: 800; cursor: pointer;
}
.eg-tab[aria-selected="true"] { background: var(--primary); color: var(--on-primary); }
html[data-contrast="on"] .eg-tab { border-width: 3px; }
.eg-turn { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 1.5rem; font-weight: 800; margin: 4px 0 var(--space); padding: 10px; border-radius: var(--radius); background: var(--primary-light); color: var(--primary); }
.eg-turn--over { background: var(--warn-bg); color: var(--warn-text); }
