/* =========================================================
   CPS Tester — styles.css
   ========================================================= */

/* ---------------------------------------------------------
   Reset / base
   --------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Visually hidden utility — keeps content available to screen
   readers without rendering it on screen */
.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;
}

/* ---------------------------------------------------------
   Design tokens (CSS custom properties)
   --------------------------------------------------------- */
:root {
    --color-bg:           #f4f6f8;
    --color-text:         #222;
    --color-muted:        #666;
    --color-border:       #ccc;
    --color-border-strong: #333;

    --color-primary:      #0077ff;
    --color-primary-dark: #0060cc;
    --color-success:      #00a86b;
    --color-success-dark: #008f57;
    --color-warning:      #ff6b00;
    --color-danger:       #c0392b;
    --color-danger-dark:  #a93226;

    --color-stat-timer:   var(--color-primary);
    --color-stat-cps:     var(--color-success);
    --color-stat-clicks:  var(--color-warning);

    --font-family:        Arial, Helvetica, sans-serif;
    --border-radius:      5px;
    --border-radius-sm:   4px;

    --transition-fast:    0.15s ease;
}

/* ---------------------------------------------------------
   Reduced-motion preference
   --------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration:  0.01ms !important;
    }
}

/* ---------------------------------------------------------
   Body / layout
   --------------------------------------------------------- */
body {
    font-family: var(--font-family);
    text-align: center;
    background: var(--color-bg);
    color: var(--color-text);
    padding: 40px 10px 60px;
    line-height: 1.5;
}

main {
    max-width: 900px;
    margin: 0 auto;
}

h1 {
    font-size: 2rem;
    margin-bottom: 24px;
}

/* ---------------------------------------------------------
   Controls
   --------------------------------------------------------- */
.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

label {
    font-weight: bold;
    display: block;
}

input {
    padding: 8px 12px;
    font-size: 1rem;
    width: 180px;
    text-align: center;
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius);
    background: #fff;
    color: var(--color-text);
    transition: border-color var(--transition-fast),
                box-shadow   var(--transition-fast);
}

input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 119, 255, 0.2);
}

input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #e9ecef;
}

/* ---------------------------------------------------------
   Buttons — shared base
   --------------------------------------------------------- */
button {
    padding: 10px 22px;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    border: none;
    border-radius: var(--border-radius);
    background: var(--color-primary);
    color: #fff;
    transition: background var(--transition-fast),
                opacity      var(--transition-fast),
                box-shadow   var(--transition-fast);
}

button:hover:not(:disabled) {
    background: var(--color-primary-dark);
}

button:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ---------------------------------------------------------
   Status message
   --------------------------------------------------------- */
#status {
    margin-top: 4px;
    font-size: 1.05rem;
    min-height: 1.5em;
    color: var(--color-text);
}

/* ---------------------------------------------------------
   Live stats
   --------------------------------------------------------- */
.stats {
    display: flex;
    justify-content: center;
    gap: 32px;
    flex-wrap: wrap;
    margin: 24px 0;
}

.stat {
    font-size: 1.75rem;
    font-weight: bold;
    min-width: 160px;
}

#timer  { color: var(--color-stat-timer);  }
#cps    { color: var(--color-stat-cps);    }
#clicks { color: var(--color-stat-clicks); }

/* ---------------------------------------------------------
   History section
   --------------------------------------------------------- */
#history {
    margin-top: 40px;
}

#history h2 {
    font-size: 1.4rem;
    margin-bottom: 12px;
}

.history-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

#sorter {
    font-size: 0.9rem;
    padding: 5px 10px;
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    background: #fff;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

#sorter:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

/* Clear history button */
.btn-danger {
    padding: 5px 12px;
    font-size: 0.85rem;
    background: var(--color-danger);
}

.btn-danger:hover:not(:disabled) {
    background: var(--color-danger-dark);
}

/* Column widths: Key | Time | Clicks | CPS | Completed | Actions */
.history-header,
.history-entry {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 2fr 2fr;
    gap: 8px;
    align-items: center;
}

.history-header > div,
.history-entry  > div {
    display: flex;
    justify-content: center;
    align-items: center;
}

.history-header {
    font-weight: bold;
    border-bottom: 2px solid var(--color-border-strong);
    padding: 6px 0;
    /* Compensate for scrollbar so header stays aligned */
    padding-right: 0;
}

#historyList {
    max-height: 360px;
    overflow-y: auto;
    /* Smooth scroll for accessibility */
    scroll-behavior: smooth;
    /* Reserve space for scrollbar to keep header aligned */
    scrollbar-gutter: stable;
}

.history-entry {
    border-bottom: 1px solid var(--color-border);
    padding: 6px 0;
    min-height: 38px;
}

.history-entry:last-child {
    border-bottom: none;
}

/* ---------------------------------------------------------
   Actions cell (Save / Delete)
   --------------------------------------------------------- */
.actions-cell {
    display: flex;
    gap: 6px;
    justify-content: center;
    align-items: center;
}

.save-btn {
    padding: 4px 8px;
    font-size: 0.8rem;
    background: var(--color-success);
    border-radius: var(--border-radius-sm);
}

.save-btn:hover:not(:disabled) {
    background: var(--color-success-dark);
}

.delete-btn {
    padding: 4px 8px;
    font-size: 0.8rem;
    background: transparent;
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
    border-radius: var(--border-radius-sm);
    line-height: 1;
}

.delete-btn:hover:not(:disabled) {
    background: var(--color-danger);
    color: #fff;
}

.saved-label {
    font-size: 0.8rem;
    color: var(--color-muted);
}

/* ---------------------------------------------------------
   Empty state
   --------------------------------------------------------- */
.empty-state {
    margin-top: 20px;
    color: var(--color-muted);
    font-style: italic;
}

/* ---------------------------------------------------------
   Responsive adjustments
   --------------------------------------------------------- */
@media (max-width: 600px) {
    .stat {
        font-size: 1.35rem;
        min-width: 120px;
    }

    .history-header,
    .history-entry {
        /* Drop CPS column on very small screens to prevent overflow */
        grid-template-columns: 2fr 1fr 1fr 2fr 2fr;
    }

    /* Hide the Clicks column header on small screens */
    .history-header > div:nth-child(3),
    .history-entry  > div:nth-child(3) {
        display: none;
    }
}
