:root {
  color-scheme: light dark;
  --cli-font: ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono", "Noto Mono", monospace;
  --cli-font-size: 14px;
  --cli-line-height: 1.45;
  --cli-spacing: 8px;
  --cli-bg: #0b0f12;
  --cli-text: #e6edf3;
  --cli-accent: #9bdcff;
  --cli-warning: #ffcc00;
  --cli-focus: #ffd166;
  /* CLI-specific overrides for snackbar theming */
  --cli-snackbar-primary: #9bdcff;
  --cli-snackbar-bg: #101820;
  --cli-snackbar-text: #dce6ef;
  --cli-snackbar-radius: 4px;
}
#cli-controls-hint:focus {
  outline: 3px solid #3cff9b;
  outline-offset: 2px;
}

:focus {
  outline: none;
  box-shadow:
    0 0 0 3px rgba(255, 209, 102, 0.12),
    0 0 0 1px var(--cli-focus);
  border-radius: 3px;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
    monospace;
  background: #050505;
  color: #d6f5d6; /* ≈17.36:1 contrast ratio on #050505 (WCAG AAA) */
  line-height: 1.45; /* Enhanced readability for monospace */
  font-size: 14px; /* Consistent base size */
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
#cli-root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  font-family: var(--cli-font);
  font-size: var(--cli-font-size);
  line-height: var(--cli-line-height);
  color: var(--cli-text);
  background: var(--cli-bg);
  padding: calc(var(--cli-spacing) * 2);
}
#cli-root > * {
  max-width: 100%;
}
.cli-header {
  padding: 12px 16px; /* Increased for better touch targets */
  border-bottom: 1px solid #1f1f1f;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 18ch; /* reserve width for longest state (prevents wrap/jump) */
  box-sizing: border-box; /* include padding in fixed height */
  height: 64px; /* Slightly increased for better proportions */
  position: relative; /* allow absolute-centering children like #cli-round */
  background: #040404;
}
.cli-title {
  font-weight: 600; /* Slightly reduced for cleaner look */
  font-size: 15px;
  color: #d6f5d6; /* Terminal green */
}
.verbose-indicator {
  background: #ffcc00;
  color: #000;
  font-size: 12px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 8px;
}
/* Enhanced countdown styling with terminal aesthetics */
#cli-countdown {
  min-height: 1.2em !important; /* Force em units for PRD compliance */
  font-weight: 600;
  color: #9cff9c; /* Warning color for timer */
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap; /* Prevent wraps when using the longer [TIMER] label */
  min-width: 12ch; /* Reserves space so header layout stays stable */
}
#cli-countdown:before {
  content: "[TIMER]"; /* ASCII timer indicator */
  opacity: 0.8;
  margin-right: 0; /* rely on flex gap for spacing */
}
.state-badge {
  font-size: 12px;
  opacity: 0.8;
  margin-left: 8px;
  /* DEPRECATED: min-height was here to reserve space, but it bloated the header. Space is reserved by #cli-stats. */
}
.cli-main {
  flex: 1;
  display: flex;
  width: 100%;
  max-width: 100%;
  margin: 0;
  flex-direction: column;
  padding: 16px 20px; /* Consistent 8px rhythm */
  gap: 16px; /* 8px rhythm maintained */
}
.cli-main > * {
  max-width: 100%;
}
/* Retro theme: green-on-black optional class and global retro theme */
#cli-root.cli-retro,
#cli-root[data-theme="retro"] {
  background: #000 !important;
  color: #8cff6b !important;
}
#cli-root.cli-retro a,
#cli-root[data-theme="retro"] a {
  color: #8cff6b;
}
#cli-root.cli-retro .cli-stat,
#cli-root.cli-retro .cli-block,
#cli-root[data-theme="retro"] .cli-stat,
#cli-root[data-theme="retro"] .cli-block {
  background: #000;
  color: #8cff6b;
  border-color: #8cff6b;
}
#cli-root.cli-retro .cli-stat.selected,
#cli-root[data-theme="retro"] .cli-stat.selected {
  background: #001900;
  border-color: #8cff6b;
}
.cli-block {
  padding: 12px 16px; /* Consistent 8px rhythm */
  border: 1px solid #1f1f1f;
  background: #030303;
  border-radius: 0; /* Flat panels for terminal feel */
  margin-bottom: 4px; /* Better section separation */
}
.cli-settings {
  background: #050505;
  color: #c8ecc8;
  font-size: 13px;
}
.cli-settings:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cli-settings[hidden] {
  display: none;
}
.cli-settings-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 8px 0;
  border-bottom: 1px solid #1f1f1f;
}

.cli-settings-row:last-child {
  border-bottom: none;
}

.cli-settings-row label {
  min-width: 80px;
  font-weight: 500;
}

/* Terminal-style separators with enhanced visual hierarchy */
.ascii-sep {
  font-family: inherit;
  color: #2f5f2f; /* Slightly more visible separators */
  padding: 8px 0;
  text-align: center;
  font-size: 12px;
  letter-spacing: 1px; /* Reduced spacing for authenticity */
  opacity: 0.7;
}
/* Enhanced round message styling */
#round-message {
  min-height: 1.4em !important; /* Force em units */
  font-weight: 500;
  color: #ffffff; /* Enhanced contrast for important messages */
}
#round-message:not(:empty):before {
  content: ">> "; /* ASCII indicator for results */
  opacity: 0.8;
  color: #9cffcf;
}

/* CLI snackbar overrides */
.cli-root #snackbar-container .snackbar {
  background: var(--cli-snackbar-bg, var(--color-tertiary));
  color: var(--cli-snackbar-text, var(--color-text));
  border: 1px solid var(--cli-snackbar-primary, var(--color-primary));
  border-radius: var(--cli-snackbar-radius, var(--radius-lg));
}

/* Standard Scoreboard nodes - Phase 1: Hidden but styled for CLI theme */
.standard-scoreboard-nodes {
  /* Hidden during Phase 1, styled for future CLI theme consistency */
  display: none;
}
.standard-scoreboard-nodes #next-round-timer,
.standard-scoreboard-nodes #round-counter,
.standard-scoreboard-nodes #score-display {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  color: #f2f2f2;
  background: transparent;
  border: none;
}
.standard-scoreboard-nodes #next-round-timer:not(:empty):before {
  content: "[TIMER] ";
  color: #9cffcf;
}
.standard-scoreboard-nodes #round-counter:not(:empty):before {
  content: "[ROUND] ";
  color: #9cffcf;
}
.standard-scoreboard-nodes #score-display:not(:empty):before {
  content: "[SCORE] ";
  color: #9cffcf;
}
/* Add prompt indicator for stat selection */
.cli-block[aria-label="Stat Selection"]:before {
  content: ">> Choose your stat:";
  display: block;
  color: #9cffcf;
  font-weight: 500;
  margin-bottom: 8px;
  opacity: 0.9;
}
#cli-verbose-section {
  position: relative;
  padding: 16px;
  border: 1px solid rgba(60, 255, 155, 0.2);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(6, 18, 12, 0.95) 0%, rgba(4, 10, 7, 0.92) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(60, 255, 155, 0.06),
    0 4px 20px rgba(3, 15, 10, 0.55);
  overflow: hidden;
}
#cli-verbose-section::before,
#cli-verbose-section::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  height: 18px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 1;
}
#cli-verbose-section::before {
  top: 16px;
  background: linear-gradient(180deg, rgba(6, 18, 12, 0.85) 0%, rgba(6, 18, 12, 0) 100%);
}
#cli-verbose-section::after {
  bottom: 16px;
  background: linear-gradient(0deg, rgba(6, 18, 12, 0.85) 0%, rgba(6, 18, 12, 0) 100%);
}
#cli-verbose-section[data-scrollable="true"][data-scroll-top="false"]::before {
  opacity: 1;
}
#cli-verbose-section[data-scrollable="true"][data-scroll-bottom="false"]::after {
  opacity: 1;
}
/* Make verbose section scrollable so newest entries are visible */
#cli-verbose-log {
  max-height: 35vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-gutter: stable both-edges;
  scrollbar-color: #3cff9b rgba(18, 36, 28, 0.6);
  padding: 12px 16px;
  margin: 0;
  border-radius: 6px;
  background: rgba(9, 24, 16, 0.9);
  box-shadow:
    inset 0 0 0 1px rgba(60, 255, 155, 0.12),
    inset 0 8px 28px rgba(3, 12, 8, 0.8);
  color: #d2f1dc;
  font-size: 13px;
  line-height: 1.45;
  letter-spacing: 0.01em;
}

#cli-verbose-log::-webkit-scrollbar {
  width: 6px;
}

#cli-verbose-log::-webkit-scrollbar-track {
  background: rgba(16, 32, 24, 0.7);
}

#cli-verbose-log::-webkit-scrollbar-thumb {
  background: #3cff9b;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(8, 24, 16, 0.8);
}
#cli-stats {
  display: grid;
  /* Smoothly scale card width so tablets gain extra columns without oversized tiles on desktop. */
  grid-template-columns: repeat(auto-fit, minmax(clamp(180px, 24vw, 220px), 1fr));
  grid-auto-rows: minmax(44px, auto);
  gap: 8px;
  min-height: 8rem; /* Reserve space for layout stability and touch targets */
}

@media (min-width: 1200px) {
  #cli-stats {
    /* Allow wider tiles on large displays, but cap growth to avoid full-row stretching. */
    grid-template-columns: repeat(auto-fit, minmax(clamp(200px, 20vw, 260px), 1fr));
  }
}
.cli-stat {
  padding: 6px 10px;
  background: #050505;
  border: 1px solid #1f1f1f;
  min-height: 44px; /* PRD requirement: touch targets >=44px */
  display: flex;
  align-items: center;
  justify-content: space-between; /* Better alignment for terminal look */
  gap: 8px;
  font-family: inherit;
  font-size: 14px;
  border-radius: 0; /* Flat rows */
  transition: background-color 0.1s ease; /* Subtle hover feedback */
  color: inherit;
}
.cli-stat.history-preview {
  border-color: #3cff9b;
  box-shadow:
    0 0 0 1px rgba(60, 255, 155, 0.75),
    0 0 0 3px rgba(60, 255, 155, 0.25);
}
.cli-stat.history-preview:not(.selected) {
  background: #0a1e12;
}
.cli-stat.skeleton {
  opacity: 0.6;
  background: linear-gradient(90deg, #1f1f1f 25%, #2f2f2f 50%, #1f1f1f 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  color: #4d754d;
  font-style: italic;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}
.cli-stat.selected {
  border-color: #3cff9b;
  background: #082508;
  box-shadow: none;
}
.cli-stat:hover {
  background: #0b2a0b; /* Subtle hover feedback */
  border-color: #2f6f2f;
}
/* High-contrast focus state for stat rows */
.cli-stat:focus {
  background: #103a28; /* deep green to ensure strong text contrast */
  border-color: #3cff9b;
  outline: 2px solid #3cff9b;
  outline-offset: 2px;
  box-shadow:
    0 0 0 2px #050505,
    0 0 0 4px #3cff9b;
}
.cli-controls {
  /* make controls lay out horizontally and center-aligned */
  display: flex;
  gap: 8px;
  align-items: center;
}

.cli-status {
  /* keep the status block aligned to the right and vertically centered in header */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;
  text-align: right;
  white-space: pre;
  gap: 4px; /* Consistent 8px rhythm */
  font-size: 13px; /* Slightly smaller for hierarchy */
  color: #d6f5d6; /* Slightly brighter for better contrast */
}
.cli-status > div {
  line-height: 1.2;
  margin: 0;
  padding: 0;
}
/* Center the round indicator in the header on wide viewports. It is positioned
         absolutely so it visually sits in the header center while the status block
         remains right-aligned. On narrow screens we fall back to the normal flow. */
#cli-round {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none; /* keep header controls usable underneath if present */
}
#cli-help {
  margin: 0;
  padding-left: 16px;
}
.cli-footer {
  margin-top: auto;
  border-top: 1px solid #3a3a3a;
}
#cli-controls-hint {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: linear-gradient(to bottom, #040404, #020202);
  border-top: 2px solid #1f1f1f;
  color: #c4e8c4;
  text-align: center;
  font-family: inherit;
  box-shadow:
    inset 0 1px 0 rgba(60, 255, 155, 0.25),
    0 -2px 12px rgba(12, 40, 24, 0.65);
}
#cli-controls-hint .cli-controls-hint__title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #8cffcf;
}
#cli-controls-hint .cli-controls-hint__items {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 16px;
  width: 100%;
}
#cli-controls-hint .cli-controls-hint__item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid rgba(60, 255, 155, 0.6);
  border-radius: 6px;
  background: rgba(60, 255, 155, 0.08);
  color: inherit;
  box-shadow: inset 0 0 0 1px rgba(11, 28, 20, 0.6);
  transition:
    opacity 0.2s ease,
    border-color 0.2s ease,
    background 0.2s ease;
}
#cli-controls-hint .cli-controls-hint__item[aria-disabled="true"],
#cli-controls-hint .cli-controls-hint__item--disabled {
  opacity: 0.45;
  border-color: rgba(60, 255, 155, 0.2);
  background: rgba(60, 255, 155, 0.03);
}
#cli-controls-hint .cli-controls-hint__key {
  font-family: var(--cli-font);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
#cli-controls-hint .cli-controls-hint__item[aria-disabled="true"] .cli-controls-hint__key,
#cli-controls-hint .cli-controls-hint__item--disabled .cli-controls-hint__key {
  color: rgba(200, 236, 200, 0.65);
}
#cli-controls-hint .cli-controls-hint__action {
  font-size: 12px;
  text-transform: none;
  opacity: 0.85;
}
#cli-controls-hint[hidden] {
  display: none !important;
}
/* Enhanced CLI prompt styling */
#cli-prompt {
  padding: 8px 16px;
  font-family: inherit;
  color: #8cffaa;
  background: #040404;
  border-top: 1px solid #1f1f1f;
  font-weight: 500;
}
#cli-cursor {
  color: #8cffaa;
  font-weight: bold;
  animation: blink 1s steps(2, end) infinite;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #cli-cursor {
    animation: none;
  }
}

/* Terminal-style snackbar line at the bottom */
#snackbar-container {
  padding: 8px 12px;
  background: #040404;
  color: #d6f5d6;
}
#snackbar-container .snackbar {
  display: block;
}
/* Shortcuts/help panel: make it a collapsible, in-flow block like `.cli-settings`.
         Visibility is controlled via the `hidden` attribute so tests and scripts can toggle it.
         Keep a modest max-width for readability and stack nicely on small screens. */
#cli-shortcuts {
  position: static; /* participate in normal flow */
  margin: 0; /* align with other .cli-block sections */
  background: transparent; /* `.cli-block` provides visible background/border */
  max-width: 760px;
  width: 100%;
}
#cli-shortcuts-close {
  /* place the close control inline and visually aligned to the right */
  float: none;
  background: none;
  border: 0;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
  display: inline-block;
  margin-left: auto;
}
/* Ensure good contrast for links if any appear */
a {
  color: #8cffaa;
}
a:focus,
button:focus,
input:focus,
select:focus,
[tabindex]:focus {
  outline: 3px solid #3cff9b;
  outline-offset: 2px;
  box-shadow:
    0 0 0 2px #050505,
    0 0 0 4px #3cff9b;
  border-radius: 3px;
}
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #050505;
  color: #d6f5d6;
  padding: 8px;
}
.skip-link:focus {
  top: 0;
}

/* Utility classes for inline style replacement */
.d-flex {
  display: flex;
}
.flex-col {
  flex-direction: column;
}
.align-items-center {
  align-items: center;
}
.justify-content-between {
  justify-content: space-between;
}
.fw-600 {
  font-weight: 600;
}
.button-reset {
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  font-family: inherit;
}
.seed-input {
  width: 6ch;
}
.seed-error {
  color: #f88;
  font-size: 12px;
}

.cli-settings-toggle,
#cli-shortcuts-close {
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pre-wrap {
  margin: 0;
  white-space: pre-wrap;
}

/* Responsive tweaks: improve header wrapping and control spacing on narrow screens */
@media (max-width: 720px) {
  .cli-header {
    flex-direction: column;
    align-items: stretch;
    height: auto;
    gap: 8px;
    padding: 12px; /* Consistent with enhanced padding */
  }
  .cli-title {
    margin-bottom: 4px;
    font-size: 14px; /* Slightly smaller for mobile */
  }
  .cli-controls {
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
  }
  .cli-controls label {
    min-width: 6ch;
    font-size: 12px; /* Consistent sizing */
  }
  .cli-status {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 4px;
  }
  .cli-status > div {
    font-size: 12px; /* Consistent sizing */
    line-height: 1.2;
  }
  .cli-main {
    padding: 12px; /* Consistent 8px rhythm */
  }
  #cli-controls-hint {
    padding: 14px 16px;
    gap: 10px;
  }
  #cli-controls-hint .cli-controls-hint__items {
    gap: 8px;
  }
  #cli-controls-hint .cli-controls-hint__item {
    flex: 1 1 calc(50% - 8px);
    justify-content: center;
    padding: 6px 10px;
  }
  #cli-stats {
    grid-template-columns: repeat(auto-fit, minmax(clamp(140px, 42vw, 180px), 1fr));
    grid-auto-rows: minmax(44px, auto);
    min-height: 8rem; /* Maintain reservation on mobile */
  }
  .ascii-sep {
    font-size: 11px; /* Smaller separators on mobile */
    letter-spacing: 1px;
  }
  /* Disable absolute centering on narrow screens so the round indicator
           participates in normal flow and avoids overlap with stacked header items. */
  #cli-round {
    position: static;
    transform: none;
    left: auto;
    top: auto;
    pointer-events: auto;
  }
}

@media (max-width: 420px) {
  .cli-controls label {
    display: none; /* keep inputs accessible, hide repetitive labels to save space */
  }
  .cli-controls input,
  .cli-controls select {
    min-width: 5ch;
  }
  #cli-controls-hint .cli-controls-hint__item {
    flex: 1 1 100%;
  }
  #cli-score {
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cli-caret,
  .cli-anim {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 640px) {
  /* Small tablet optimizations */
}

@media (max-width: 360px) {
  /* Small phone optimizations */
}
