:root {
    --accent: #dc2626;               /* error color */
    --accent-light: #ef4444;
    --accent-dark: #b91c1c;
    --bg: #f9fafb;                   /* light bg */
    --card-bg: #ffffff;
    --hover-bg: #f5f5f5;
    --text: #1f2937;                 
    --muted: #6b7280; 
    --border: #d1d5db;               
    --track: #e5e7eb;       
    
    --link: var(--primary);
    --link-visited: #5a9c9c;

    /* primary palette */
    --primary: #008080;              /* teal */
    --primary-dark: #006666;
    --progress-success: #10b981;     /* green */
    --progress-warning: #f59e0b;     /* amber */
}

/* Utility Class: visually hidden for accessible labels */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 1px, 1px);
  white-space: nowrap;
  border: 0;
}

/* noscript banner */
.noscript-warning {
  padding: 1rem;
  background: #fff3cd;
  border: 1px solid #ffeeba;
}

/* Inline field errors */
.error-text {
    color: var(--accent);
    font-size: 0.9rem;
}

/* -----------------------------------
   Global link styles (accessible)
----------------------------------- */

/* Default link */
a {
  color: var(--link);      /* teal brand color */
  text-decoration: none;         
  transition: color 0.2s ease;   
}

/* Visited link */
a:visited {
  color: var(--link-visited); /* softer teal */
}

/* Hover + focus */
a:hover,
a:focus {
  text-decoration: underline;        
  text-underline-offset: 2px;        
  outline: none;                     /
}

/* Focus ring (uses your theme variable) */
a:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Theme Classes*/
body {
    background: var(--bg);
    color: var(--text);
}

.mode-dark {
    --bg: #0b1220;                   /* deep navy */
    --card-bg: #121a2a;              /* dark card */
    --hover-bg: #1f2a44;
    --text: #e5e7eb;                 /* light text */
    --border: #2c3650;
    --track: #1f2a44;
    --primary: #5ce0df;              /* lighter teal for contrast */
    --primary-dark: #42b7b7;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    margin: 0;
    padding: 1rem;
    
}

/* App logo + compact wordmark */
.app-logo {
    display: flex;
    align-items: center;
    gap: 0;
    font-size: 1.65rem;
    font-weight: bold;
}
.app-logo__icon {
    height: 40px;
    width: auto;
    display: inline-block;
}
.app-logo__text {
    letter-spacing: -0.5px;
    margin-left: -8.25px;
    margin-top: 3.75px;
}

/* Settings gear + dropdown */
.settings {
    position: relative;
    display: inline-block;
    margin-left: auto;
}
.settings__trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    padding: 0.4rem 0.6rem;
    transition: background 0.2s, box-shadow 0.2s;
}
.settings__trigger,
.settings__trigger .settings__label {
  color: var(--text);
}
.settings__trigger [aria-hidden="true"] {
  opacity: 0.8;
  transition: opacity 0.2s, transform 0.2s;
}
.settings__trigger:hover,
.settings__trigger:focus {
    background: var(--hover-bg);
}

/* Hover/focus: brighten + spin gear, pulse background */
.settings__trigger:hover,
.settings__trigger:focus-visible {
  background: var(--hover-bg);
  animation: gearPulseLight 0.35s ease;
}
.settings__trigger:hover [aria-hidden="true"],
.settings__trigger:focus-visible [aria-hidden="true"] {
  opacity: 1;
  transform: rotate(20deg);
}

/* Hover/focus: dark mode */
.mode-dark .settings__trigger:hover,
.mode-dark .settings__trigger:focus-visible {
  animation: gearPulseDark 0.35s ease;
}

/* Hover/focus: subtle highlight + accent bar */
.settings__menu .r-btn--sm:hover,
.settings__menu .r-btn--sm:focus-visible {
  background: var(--hover-bg);
  font-weight: 500;
  position: relative;
}
.settings__menu .r-btn--sm:hover::before,
.settings__menu .r-btn--sm:focus-visible::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

/* Active/checked (e.g. theme toggle): persistent bar + stronger bold */
.settings__menu .r-btn[role="menuitemcheckbox"][aria-checked="true"] {
  background: var(--hover-bg);
  font-weight: 600;
  position: relative;
}
.settings__menu .r-btn[role="menuitemcheckbox"][aria-checked="true"]::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

/* Stronger keyboard focus ring + subtle glow */
.settings__trigger:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
    border-radius: 6px;
    box-shadow: 0 0 0 3px rgba(0, 128, 128, 0.25);
}
.settings__label {
    display: inline;
}

/* Dropdown + animation */
.settings__menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    margin-top: 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    min-width: 170px;
    z-index: 100;

    opacity: 0;
    transform: translateY(-5px);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}
.settings__menu.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.settings__menu [role="separator"] {
    height: 1px;
    background: var(--border);
    margin: 0.4rem 0;
}

.settings__menu #reset-data {
    margin-bottom: 0.25rem;
}

/* Perfs Reset button */
#prefs-reset {
    opacity: 0.9;
}
#prefs-reset:hover {
    opacity: 1;
}

.result-active {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    background: var(--card-bg);
}

/* Base Readr button + small modifier (framework-safe) */
.r-btn {
    font: inherit;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}
.settings__menu, 
.settings__menu .r-btn--sm {
    color: var(--text);
}
.settings__menu .r-btn--sm {
    text-align: left;
    padding: 0.4rem 0.8rem;
    background: transparent;
    border: none;
    border-radius: 0;
    cursor: pointer;
}
.settings__menu .r-btn--sm:hover {
    background: var(--hover-bg);
}
.settings__menu .r-btn--sm:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    background: var(--hover-bg);
    border-radius: 4px;
    box-shadow: 0 0 0 2px rgba(0, 128, 128, 0.2);
}
.settings__menu .r-btn--sm:active {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
    background: var(--hover-bg);
    border-radius: 4px;
    box-shadow: 0 0 0 2px rgba(0, 128, 128, 0.25);
}

/* Visual state for the theme toggle when "checked" (dark active) */
.settings__menu .r-btn[role="menuitemcheckbox"][aria-checked="true"] {
    background: var(--hover-bg);
    font-weight: 600;
}

/* Toolbar with gap */
#toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem;
    margin-bottom: 1rem;
}
#toolbar .spacer {
    flex: 1;
}

h1, h2, h3 {
    color: var(--primary);
    text-align: center;
}

button {
    background: var(--primary);
    color: whitesmoke;
    border: none;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background 0.2s;
}
button:hover {
    background: var(--primary-dark);
}

#clear-runtime-cache {
    opacity: .9;
}
#clear-runtime-cache:hover {
    opacity: 1;
}

/* Keyboard focus styles*/
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
input, select, button {
    padding: 0.5rem;
    font-size: 1rem;
}

ul {
    list-style: none;
    padding: 0;
}
li {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

#books-empty {
    text-align: center;
    padding: 1rem;
}
#books button.delete,
#history-body button.delete {
    background: var(--accent);
    color: #ffffff;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    font-weight: 600;
}
#books button.delete:hover,
#history-body button.delete:hover {
    background: var(--accent-dark);
}

#history-body .row-actions button {
    min-width: 80px;
    height: 2.5rem;
    line-height: 1.2;
    text-align: center;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Inline edit row styling */
.edit-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.edit-row input[type="text"],
.edit-row input[type="month"],
.edit-row select {
    min-width: 120px;
}
.edit-row .btn-ghost {
    color: inherit;
    background: transparent;
    border: 1px solid var(--border);
}
.edit-row .btn-ghost:hover {
    background: var(--hover-bg);
}

.muted {
    color: var(--muted);
}

#controls {
   background: var(--card-bg);
   border: 1px solid var(--border);
   border-radius: 10px;
   padding: 0.75rem;
   margin: 1rem 0; 
}
#controls .row { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 0.5rem; 
    margin-bottom: 0.5rem; 
}
#controls input[type="search"] { 
    flex: 1; 
    min-width: 220px; 
}
#controls select[multiple] { 
    min-width: 160px;
}
#controls label.filter { 
    display: flex; 
    flex-direction: column; 
    gap: 0.25rem; 
}
#tbr-filter {
    align-items: center; 
    gap: 0.5rem; 
    flex-direction: row;
}

#goal-widget, #reading-log {
    background: var(--card-bg); 
    border: 1px solid var(--border);
    border-radius: 10px; 
    padding: 0.75rem; 
    margin: 1rem 0;
}

.nudge-group {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.nudge-group input {
    background: var(--card-bg);
    border: none;
    width: 6ch;
    text-align: center;
    padding: 0.4rem 0.5rem;
}
.nudge-group button {
    background: var(--track);
    color: inherit;
    padding: 0 0.6rem;
    line-height: 1;
    font-weight: bold;
    cursor: pointer;
}
.nudge-group button:hover {
    background: var(--border);
}

#today-bar { 
    width: 100%; 
    height: 10px; 
    position: relative;
    background: var(--track); 
    border-radius: 6px; 
    overflow: hidden; 
}
#today-bar-fill { 
    display: block;
    height: 100%;
    border-radius: 6px 0 0 6px;
    transition: width .35s ease-in-out; 
}
#today-bar-fill.zero {
    width: 2px;
}
/* Today bar state colors */
#today-bar-fill.success { 
    background: var(--progress-success); 
}
#today-bar-fill.warning { 
    background: var(--progress-warning); 
}
#today-bar-fill.error { 
    background: var(--accent); 
}

#today-stats { 
    display: flex; 
    gap: 0.5rem; 
    align-items: baseline; 
    margin-top: 0.25rem; 
}
#streaks { 
    margin-top: 0.5rem; 
    display: flex;
    gap: 1rem; 
}

/* Tooltip */
#today-tooltip {
    bottom: auto;    /* JS sets top explicitly */
    top: auto;
    left: 50%;
    transform: translateX(-50%);
    max-width: min(320px, 90vw);
}

/* flip below when space above is tight */
#today-tooltip.pos-below {
    top: calc(100% + 8px);
    bottom: auto;
}

/* Arrow (default points down since tooltip is above the bar) */
#today-tooltip::after {
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    /* triangle */
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;

    /* default = above the bar, so arrow points DOWN */
    border-top: 8px solid var(--border);
    border-bottom: 0;

    /* sit just under the tooltip box (which is above the bar) */
    bottom: -8px;
}

/* Inner arrow to match background (for a "bordered* arrow look) */
#today-tooltip::before {
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;

    border-top: 7px solid var(--card-bg);
    border-bottom: 0;

    bottom: -7px;
}

/* Flip arrow when tooltip is below the bar */
#today-tooltip.pos-below::after {
    border-top: 0;
    border-bottom: 8px solid var(--border);
    top: -8px;   /* move to top edge of tooltip */
    bottom: auto;
}
#today-tooltip.pos-below::before {
    border-top: 0;
    border-bottom: 7px solid var(--card-bg);
    top: -7px;   
    bottom: auto;
}

#log-form { 
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem; 
}
#log-form select, #log-form input { 
    min-width: 140px; 
}

/* Shared focus style for all settings buttons */
#settings-menu .r-btn:focus {
    outline: 2px solid var(--focus-ring); /* teal ring */
    outline-offset: 2px;
}

/* Install app (constructive): green */
.btn-install {
    background-color: var(--progress-success);
    color: #ffffff;
    transition: background-color .18s ease, color .18s ease, box-shadow .18s ease;
    cursor: pointer;
}

/* Disabled state*/
.btn-install[disabled],
.btn-install.installed {
    background-color: var(--muted);
    color: #ffffff;
    opacity: 0.95;
    cursor: default;       /* grey, not interactive after confirmed install */
    box-shadow: none;
}

/* Make sure hover/focus can't override disabled styling */
.btn-install[disabled]:hover,
.btn-install[disabled]:focus,
.btn-install.installed:hover,
.btn-install.installed:focus {
    background-color: var(--muted);
    box-shadow: none;
}

/* Stop any hover effects from generic rules entirely */
.btn-install[disabled] {
    pointer-events: none; /* removes hover states & tooltips on disabled */
}

/* Slight cue when the browser hasn't fired the event yet */
.btn-install.unavailable {
    opacity: 0.98; /* still looks enabled, but just a hair dimmer */
}

/* --- Install status pill --- */
.status-pill {
  display: inline-block;
  margin-left: .5rem;
  padding: 0 .45rem;
  border-radius: 9999px;
  font-size: .72rem;
  line-height: 1.35;
  vertical-align: middle;
  border: 1px solid transparent;
}
.status-pill.unavailable {
  background: var(--card-bg);
  color: var(--muted);
  border-color: var(--border);
}
.status-pill.ready {
  background: var(--progress-success);
  color: #fff;
  border-color: var(--progress-success);
}
.status-pill.installed {
  background: var(--muted);
  color: #fff;
  border-color: var(--muted);
}

/* Reset Preferences (neutral utility) */
#settings-menu .btn-reset {
  background-color: var(--muted);
  color: #ffffff;
}
#settings-menu .btn-reset:hover,
#settings-menu .btn-reset:focus {
  background-color: #5a6268;
}

#reset {
    margin-top: 1rem;
    text-align: center;
}

/* Reset Profile + Clear Cache buttons */
#reset-profile,
#clear-runtime-cache {
    background: var(--track);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 1rem;
    cursor: pointer;
}
#reset-profile:hover, 
#clear-runtime-cache:hover {
    background: var(--hover-bg);
}

/* Reset Data button*/
#reset-data {
    background: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    margin-top: 0.2rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-weight: 600;
}
#reset-data:hover {
    background: var(--accent-dark);
}

/* Check Updates button */
#check-updates {
    background: var(--primary);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    cursor: pointer;
}
#check-updates:hover {
    background: var(--primary-dark);
}

/* Clear search button */
.search-clear {
    font-size: 18px;
    line-height: 1;
    background: transparent;
    color: var(--text);
    border: none;
    border-radius: 4px;
    margin-left: 6px;
    padding: 2px 6px;
    cursor: pointer;
}
.search-clear:hover,
.search-clear:focus {
    background: var(--border);
    outline: none;
}

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

.no-results {
    display: inline-flex;
    gap: 0.5rem;
    align-items: center;
}

#history-pager {
    justify-content: space-between;
}

/* History table */
.table-wrap {
    overflow-x: auto;
}
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th, .table td {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}
.table tbody tr:hover {
    background: var(--hover-bg);
}

/* Compact inline edit inside table */
.table .row-edit {
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;
}
.table .row-edit input[type="number"],
.table .row-edit input[type="date"] {
    min-width: 8ch;
}
.table .row-actions {
    display: inline-flex;
    gap: 0.4rem;
}

/** Toasts **/
#toasts {
    position: fixed;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
}

/* base */
.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.6rem 0.8rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    min-width: 240px;
    max-width: 90vw;
}
.toast strong {
    margin-right: 0.25rem;
}
.toast .actions {
    margin-left: auto;
    display: inline-flex;
    gap: 0.5rem;
}
.toast .btn-ghost {
    color: #0b1220;
    background: transparent;
    border: 1px solid transparent;
}
.toast .r-btn--sm {
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
}

/* variants */
.toast.info {
    border-color: var(--border);
}
.toast.success {
    border-color: #2e7d32;
}
.toast.error {
    border-color: #c62828;
}

/* entrance/exit */
.toast.enter {
    animation: toast-in 0.18s ease-out both;
}
.toast.exit {
    animation: toast-out 0.16s ease-in both;
}
@keyframes toast-in {
    from {
        opacity: 0;
        transform: translate(-50%, 8px);
    } 
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}
@keyframes toast-out {
    from {
        opacity: 1;
    } 
    to {
        opacity: 0;
    }
}

/* Light mode pulse (slightly darker) */
@keyframes gearPulseLight {
  0%   { background: var(--hover-bg); }
  50%  { background: rgba(0, 0, 0, 0.04); }
  100% { background: var(--hover-bg); }
}

/* Dark mode pulse (slightly lighter) */
@keyframes gearPulseDark {
  0%   { background: var(--hover-bg); }
  50%  { background: rgba(255, 255, 255, 0.08); }
  100% { background: var(--hover-bg); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media (max-width: 600px) {
    .settings__label {
        display: none;
    }
}

/* Accessibility: disable spin + pulse for reduced motion */
@media (prefers-reduced-motion: reduce) {
  .settings__trigger {
    transition: background 0.2s ease;
    animation: none !important;
  }
  .settings__trigger:hover [aria-hidden="true"],
  .settings__trigger:focus-visible [aria-hidden="true"] {
    transform: none;
  }
}