/* GREENCASTLE / readable terminal
   Shared presentation only. Board/piece geometry, cinematic artwork, timing,
   native hidden states and application state are deliberately not restyled. */
:root {
  --tc-screen: #010603;
  --tc-panel: #031109;
  --tc-raised: #071d10;
  --tc-control: #04130a;
  --tc-hover: #123a21;
  --tc-selected: #123a21;
  --tc-green: #41ff72;
  --tc-text: #c5ffd4;
  --tc-muted: #a4dcb2;
  --tc-border: #398a51;
  --tc-rule: #286940;
  --tc-edge: #65d982;
  --tc-focus: #e1ffe9;
  --tc-warning: #ffda94;
  --tc-danger: #ffb4a6;
  --tc-warning-surface: #201b0c;
  --tc-danger-surface: #24130f;
  --tc-font: "Courier New", monospace;
  --tc-label: 12px;
  --tc-copy: 14px;
  --tc-space: 8px;
  --tc-heading-glow: 0 0 9px #41ff722e;
  --green: var(--tc-green);
  --black: var(--tc-screen);
  --panel: var(--tc-panel);
}
html[data-terminal-glow="soft"] { --tc-heading-glow: 0 0 3px #41ff7220; }
html[data-terminal-glow="off"] { --tc-heading-glow: none; }
html[data-terminal-contrast="high"] {
  --tc-text: #e4ffed;
  --tc-muted: #bcf4c9;
  --tc-border: #8dffa7;
  --tc-rule: #65d982;
  --tc-panel: #010603;
}

/* System colors retain authority in forced-colors mode. */
@media not (forced-colors: active) {
  body { color: var(--tc-text); background-color: var(--tc-screen); font-family: var(--tc-font); }
  body:has(>.page,>.review-shell,>.training-shell) {
    background: radial-gradient(ellipse at 50% 10%, #092316, var(--tc-screen) 65%);
  }
  html :is(.onboarding,.panel,.page,.review-log,.analysis-panel,.training-coach,.training-progress,.training-chapter,.terminal-controls,.online-session-panel,.library-card,.record-card) {
    background-color: var(--tc-panel);
    color: var(--tc-text);
    border-color: var(--tc-border);
  }
  html :is(.onboarding,.modal>.panel,.page) {
    border-width: 1px;
    box-shadow: 0 0 20px #41ff7210;
  }
  html :is(.config-header,.training-progress,.review-log>h2,.training-coach>h2) {
    background-color: var(--tc-raised);
    border-color: var(--tc-rule);
  }
  html :is(.console>header,.review-shell>header,.training-shell>header,.page-nav,footer,.mission-section,.mission-preferences,.mission-support,.result-statistics,.result-tools,.config-help,.config-previews,.training-lessons,.training-explanation) {
    border-color: var(--tc-rule);
  }

  /* One readable type hierarchy; uppercase belongs to labels, not paragraphs. */
  html :is(.mission-title,.page h1,.review-shell>header h1,.training-shell>header h1) {
    color: var(--tc-green);
    font-weight: 700;
    letter-spacing: .02em;
    line-height: 1.2;
    text-shadow: var(--tc-heading-glow);
  }
  html :is(.console>header h1,.terminal-boot h1) {
    color: var(--tc-green);
    text-shadow: var(--tc-heading-glow);
  }
  /* Bright green identifies the current screen. Smaller sections remain mint. */
  html .mission-home.mission-detail>.mission-section>h2,
  html .config-header>.eyebrow,
  html .account-page .account-section>h2 {
    color: var(--tc-green);
    text-shadow: var(--tc-heading-glow);
  }
  html :is(.onboarding,.modal,.review-shell,.training-shell,.page) :is(h2,h3,h4,strong) {
    color: var(--tc-text);
    text-shadow: none;
  }
  html :is(.onboarding,.panel,.review-shell,.training-shell,.page) .eyebrow {
    color: var(--tc-muted);
    font-size: var(--tc-label);
    line-height: 1.6;
    letter-spacing: .1em;
    opacity: 1;
    text-shadow: none;
  }
  html :is(.onboarding h2,.config-section h2,.training-coach>h2,.analysis-panel>h2,.library-section,.page h2) {
    border-left: 2px solid var(--tc-edge);
    padding-left: 10px;
    font-size: 16px;
    line-height: 1.5;
    letter-spacing: .05em;
    text-shadow: none;
  }
  html :is(.mission-copy,.mission-empty,.onboarding .online-copy,.onboard-level span,.personality-card p,.config-note,.config-online-note,.terminal-help,.terminal-policy,.analysis-note,.analysis-section>p,.key-help,.isolation-note,.training-learning,.training-progress p,.training-chapter>p,.library-hint,.library-card p,.project-support p,.form-help) {
    color: var(--tc-muted);
    font-size: 13px;
    line-height: 1.7;
    letter-spacing: normal;
    opacity: 1;
    text-shadow: none;
  }
  html :is(.onboarding .hint,.panel .hint,.config-section #difficultyGuide,.config-section .clock-config p,.difficulty-guide) {
    color: var(--tc-muted) !important;
    font-size: 13px !important;
    line-height: 1.7 !important;
    letter-spacing: normal;
    opacity: 1;
    text-shadow: none;
  }
  html :is(.analysis-finding p,.analysis-observations dd,.analysis-focus p,.training-prompt,.training-feedback,.training-guidance,.training-explanation p,.training-reflection,.training-completion,.page p,.page li,.page dd) {
    color: var(--tc-text);
    text-shadow: none;
    letter-spacing: normal;
    line-height: 1.75;
  }
  html :is(.analysis-finding p,.analysis-observations dd,.analysis-focus p) { font-size: var(--tc-copy); }
  html :is(.terminal-help,.terminal-policy,.training-learning,.analysis-note,.key-help,.isolation-note) { font-size: var(--tc-copy); }
  html :is(.page p,.page li,.page dd) { font-size: 16px; }
  html :is(.analysis-observations dt,.training-explanation h3,.training-chapter h3) {
    color: var(--tc-text);
    font-size: var(--tc-label);
    line-height: 1.6;
    letter-spacing: .05em;
  }
  html :is(.analysis-focus,.training-guidance,.training-reflection,.note,.personality-card,.onboard-level) {
    background: var(--tc-raised);
    border-color: var(--tc-edge);
    color: var(--tc-text);
  }
  html :is(.mission-primary small,.mission-record-list small,.training-chapter small,.project-support small,.updated,.beta-version,.mission-update,.release-label,.review-meta p,.console>header p,.readout,.console>footer) {
    color: var(--tc-muted);
    opacity: 1;
    text-shadow: none;
  }
  html :is(.mission-primary small,.mission-home>.beta-version,.mission-home .mission-update,.project-support small,.readout,.console>footer,.console>header p) {
    font-size: 11px;
    line-height: 1.6;
  }

  /* Shared controls. Never match board squares or alter hidden/display rules. */
  html :is(.startup button,.modal button,.config,.new,.resign,.menu-toggle,.back-results,.review-shell button,.training-shell button,.page button,.mission-primary>a,.mission-import,.project-support a,.support-actions a,.back,.file-label,.library-entry):not(.square) {
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--tc-control);
    color: var(--tc-text);
    -webkit-text-fill-color: currentColor;
    border-color: var(--tc-edge);
    border-radius: 0;
    min-height: 44px;
    font-family: var(--tc-font);
    font-weight: 700;
    line-height: 1.5;
    text-shadow: none;
    letter-spacing: .025em;
    cursor: pointer;
  }
  html :is(.startup button,.modal button,.config,.new,.resign,.menu-toggle,.review-shell button,.training-shell button,.page button):not(.square):not(.close):not(.mission-primary>button) {
    font-size: var(--tc-label);
  }
  html :is(.startup button,.modal button,.config,.new,.resign,.menu-toggle,.review-shell button,.training-shell button,.page button,.mission-primary>a,.mission-import,.project-support a,.support-actions a,.back,.file-label,.library-entry):not(.square):hover:not(:disabled) {
    background-color: var(--tc-hover);
    color: var(--tc-focus);
    filter: none;
  }
  html :is(.mode-switch,.onboard-sides,.sides,.clock-choices) button.active,
  html .config-tabs button[aria-selected="true"],
  html .cinematic-choices button[aria-pressed="true"],
  html .mission-primary>.selected,
  html .training-chapter button[aria-current="step"],
  html .move-list button[aria-current="step"] {
    background: var(--tc-selected);
    color: var(--tc-text);
    border-color: var(--tc-green);
    box-shadow: inset 0 -3px var(--tc-green);
    outline: none;
  }
  html .mission-primary #missionPlay { background-color: var(--tc-raised); border-color: var(--tc-edge); }
  html :is(.begin-match,.initialize,#rematch,#continueTraining,#loadPgn,#analyzeGame,#sendFeedback,#confirmMenu),
  html .outcome-first #rematch,
  html .outcome-first .online-rematch-actions .session-buttons button:first-child {
    background: var(--tc-green);
    color: var(--tc-screen);
    -webkit-text-fill-color: currentColor;
    border-color: var(--tc-green);
    text-shadow: none;
  }
  html :is(.begin-match,.initialize,#rematch,#continueTraining,#loadPgn,#analyzeGame,#sendFeedback,#confirmMenu):hover:not(:disabled) {
    background: var(--tc-text);
    color: var(--tc-screen);
    border-color: var(--tc-text);
  }
  /* Primary button descendants must not inherit the pale heading color. */
  html :is(.begin-match,.initialize,#rematch,#continueTraining,#loadPgn,#analyzeGame,#sendFeedback,#confirmMenu) :is(span,strong) { color: inherit; }
  html :is(.startup button,.modal button,.config,.new,.resign,.menu-toggle,.review-shell button,.training-shell button,.page button):not(.square):disabled {
    background: var(--tc-panel);
    color: var(--tc-muted);
    border-color: var(--tc-rule);
    box-shadow: none;
    opacity: .7;
    cursor: not-allowed;
  }
  html :is(.begin-match,.initialize,#rematch,#continueTraining,#loadPgn,#analyzeGame,#sendFeedback,#confirmMenu):disabled {
    background: var(--tc-panel);
    color: var(--tc-muted);
    border-color: var(--tc-rule);
    box-shadow: none;
    opacity: .7;
    cursor: not-allowed;
  }
  html :is(.resign-panel #confirmResign,[data-action="remove"]) {
    background: var(--tc-danger-surface);
    color: var(--tc-danger);
    border-color: var(--tc-danger);
  }
  html .restart-panel #confirmNewGame { background: var(--tc-warning-surface); color: var(--tc-warning); border-color: var(--tc-warning); }
  html .resign-panel #confirmResign:hover:not(:disabled) { background: var(--tc-danger-surface); color: var(--tc-focus); border-color: var(--tc-danger); }
  html .restart-panel #confirmNewGame:hover:not(:disabled) { background: var(--tc-warning-surface); color: var(--tc-focus); border-color: var(--tc-warning); }
  html .training-success #nextTraining { background:var(--tc-green);color:var(--tc-screen);-webkit-text-fill-color:currentColor;border-color:var(--tc-green);text-shadow:none; }
  html .training-success #nextTraining:hover { background:var(--tc-text);border-color:var(--tc-text); }
  html :is(.panel .close,.library-panel .close) { font-size: 24px; color: var(--tc-text); background: transparent; }
  html :is(button,a,input,select,textarea,summary):focus-visible {
    outline: 2px solid var(--tc-focus);
    outline-offset: 3px;
  }
  /* Board focus already has an inset outline; do not change its geometry. */
  html button.square:focus-visible { outline-offset: -4px; }
  html :is(.mode-switch button.active,.onboard-sides button.active,.sides button.active,.clock-choices button.active,.mission-primary>.selected,.config-tabs button[aria-selected="true"],.training-chapter button[aria-current="step"],.move-list button[aria-current="step"]):focus-visible {
    outline: 2px solid var(--tc-focus);
    outline-offset: 3px;
  }

  /* A shared field treatment and readable, non-native-white range controls. */
  html :is(select,textarea,input[type="text"],input[type="email"],input:not([type])) {
    color: var(--tc-text);
    -webkit-text-fill-color: currentColor;
    background: var(--tc-control);
    border-color: var(--tc-edge);
    border-radius: 0;
    font-family: var(--tc-font);
    text-shadow: none;
  }
  html :is(select,textarea,input)::placeholder { color: var(--tc-muted); opacity: .85; }
  html option { background: var(--tc-control); color: var(--tc-text); }
  html input[type="range"] { appearance: none; -webkit-appearance: none; min-height: 32px; background: transparent; accent-color: var(--tc-green); cursor: pointer; }
  html input[type="range"]::-webkit-slider-runnable-track { height: 6px; background: var(--tc-raised); border: 1px solid var(--tc-edge); border-radius: 0; }
  html input[type="range"]::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; height: 18px; width: 18px; margin-top: -7px; border: 2px solid var(--tc-text); border-radius: 0; background: var(--tc-green); box-shadow: none; }
  html input[type="range"]::-moz-range-track { height: 4px; background: var(--tc-raised); border: 1px solid var(--tc-edge); border-radius: 0; }
  html input[type="range"]::-moz-range-thumb { height: 14px; width: 14px; border: 2px solid var(--tc-text); border-radius: 0; background: var(--tc-green); }
  html input[type="checkbox"] { accent-color: var(--tc-green); }
  html a { color: var(--tc-text); text-underline-offset: 4px; }
  html a:hover { color: var(--tc-focus); }
  html :is(.page-nav,.mission-links,.review-shell>footer,.training-shell>footer) a { font-size: 12px; line-height: 1.6; }
  html :is(.page-nav,.mission-links) { gap: 8px 20px; }
  /* Footer links stay readable and wrap instead of compressing narrow screens. */
  html :is(.mission-links,.console>footer>.site-links) { display:flex; flex-wrap:wrap; gap:4px 16px; }
  html :is(.mission-links,.console>footer>.site-links) a { display:inline-flex; align-items:center; min-height:44px; font-size:12px; line-height:1.6; }
  html :is(.mission-preferences,.mission-support,.terminal-controls,.result-statistics,.result-tools,.config-previews,.config-help,.import-panel)>summary {
    color: var(--tc-text);
    font-size: var(--tc-label);
    line-height: 1.6;
    letter-spacing: .04em;
    text-shadow: none;
  }
  html :is(.training-storage,.terminal-storage,.session-warning,.online-error,.storage-notice,.library-confirm,.alternative-mode) {
    color: var(--tc-warning);
    border-color: var(--tc-warning);
    text-shadow: none;
  }
  html :is(.alternative-mode,.library-confirm) { background: var(--tc-warning-surface); }
  html .training-feedback[data-state="retry"] { color: var(--tc-warning); }
  html .training-feedback[data-state="correct"] { color: var(--tc-text); }
  html .outcome-first :is(#outcomeDetail,.result-final-move) { color: var(--tc-text); text-shadow: none; }
  html .outcome.outcome-first .outcome-panel { border-color: var(--tc-border); }
  html .outcome-first .result-heading { border-left: 3px solid var(--tc-green); padding-left: 12px; }
  html .outcome[data-outcome="loss"] .result-heading { border-color: var(--tc-danger); }
  html .outcome[data-outcome="draw"] .result-heading { border-color: var(--tc-warning); }
  html .outcome[data-outcome="win"] #outcomeTitle,
  html .outcome[data-outcome="win"] #outcomeReason { color: var(--tc-green); }
  html .outcome[data-outcome="loss"] #outcomeTitle,
  html .outcome[data-outcome="loss"] #outcomeReason { color: var(--tc-danger); }
  html .outcome[data-outcome="draw"] #outcomeTitle,
  html .outcome[data-outcome="draw"] #outcomeReason { color: var(--tc-warning); }

  /* Functional readouts use the same readable type scale as their controls. */
  html .cockpit .hud-side strong,
  html .cockpit .captured-list,
  html .cockpit .log-row,
  html .cockpit .empty-log,
  html .cockpit .online-link,
  html .cockpit .online-link b { font-size: var(--tc-label); }
  html .cockpit .log-row { line-height: 1.5; min-height: 28px; }
  html .cockpit .online-link { color: var(--tc-muted); }
  html .cockpit .log-row span { color: var(--tc-text); }
  html .cockpit .log-row b { color: var(--tc-muted); }
  html .cockpit .empty-log { color: var(--tc-muted); opacity: 1; }
  html .config-tabs button,
  html .outcome-first .result-statistics>summary,
  html .outcome-first .result-tools>summary,
  html .outcome-first .result-navigation>button { font-size: var(--tc-label); }

  /* Same terminal texture, deliberately quieter over controls/reading areas.
     Existing game-board scanlines and endgame layers remain unchanged. */
  body:has(.modal:not(.hidden),.startup:not(.dismissed))>.scanlines { opacity: .35; }
  html[data-terminal-effects="low"] body:has(.modal:not(.hidden),.startup:not(.dismissed))>.scanlines { opacity: .12; }
  body:has(>.page,>.review-shell,>.training-shell)::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 1000;
    pointer-events: none;
    background: repeating-linear-gradient(to bottom, #00000012 0, #00000012 1px, transparent 1px, transparent 4px);
  }
  html[data-terminal-effects="low"] body::after { opacity: .35; }
  html[data-terminal-effects="off"] body::after,
  html[data-terminal-motion="reduced"] body::after,
  html[data-terminal-contrast="high"] body::after { display: none; }
}
@media (max-width: 760px) {
  html :is(select,textarea,input[type="text"],input[type="email"]) { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce), (prefers-contrast: more), (forced-colors: active) {
  body::after { display: none; }
}
