/* Default Theme: Light Mode */
:root {
  --bg-color: #f8f9fa;
  --text-color: #111827;
  --subtext-color: #6b7280;
  --highlight-color: #111827;

  --card-bg: #fff;
  --border-color: #aaa;

  --syncing-bg: #e5e7eb;
  --syncing-text: #4b5563;

  --exact-bg: #dcfce7;
  --exact-text: #15803d;

  --off-bg: #fee2e2;
  --off-text: #b91c1c;

  --brand-color: #7a0c1e;
  --brand-color-hover: #c81e3a;

  --brand-text-color: #fff;
  --brand-box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
  --brand-box-shadow-hover: 0 0 12px rgba(200, 30, 58, 0.6), 0 4px 8px rgba(0, 0, 0, 0.35);
}

/* User Agent Preference: Dark Mode (unless explicitly overridden by JS light mode) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-color: #121212;
    --text-color: #ffffff;
    --subtext-color: #ddd;
    --highlight-color: #ffffff;

    --card-bg: #007;
    --border-color: #e5e7eb;

    --syncing-bg: #333333;
    --syncing-text: #aaaaaa;

    --exact-bg: #1b4d2e;
    --exact-text: #4caf50;

    --off-bg: #4d1b1b;
    --off-text: #f44336;

    --brand-box-shadow: 0 6px 12px rgba(255, 255, 255, 1);
    --brand-box-shadow-hover: 0 0 18px rgba(200, 30, 58, 0.8), 0 4px 8px rgba(255, 255, 255, 1);
  }
}

/* Explicit JS Toggle Overrides */
:root[data-theme="dark"] {
  --bg-color: #121212;
  --text-color: #ffffff;
  --subtext-color: #ddd;
  --highlight-color: #ffffff;

  --card-bg: #007;
  --border-color: #e5e7eb;

  --syncing-bg: #333333;
  --syncing-text: #aaaaaa;

  --exact-bg: #1b4d2e;
  --exact-text: #4caf50;

  --off-bg: #4d1b1b;
  --off-text: #f44336;
}

:root[data-theme="light"] {
  --bg-color: #f8f9fa;
  --text-color: #111827;
  --subtext-color: #6b7280;
  --highlight-color: #111827;

  --card-bg: #fff;
  --border-color: #aaa;

  --syncing-bg: #e5e7eb;
  --syncing-text: #4b5563;

  --exact-bg: #dcfce7;
  --exact-text: #15803d;

  --off-bg: #fee2e2;
  --off-text: #b91c1c;
}

@font-face {
  font-family: 'Noto Serif';
  src: url('/NotoSerif-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'DejaVuSans';
  src: url('/DejaVuSans.ttf') format('truetype');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
  margin: 0; padding: 0;
  transition-duration: 0.25s;
}

body {
  font-family: 'DejaVuSans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  min-height: 100vh;

  /* GRID LAYOUT SETUP */
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: 1fr;
}

/* --- Brand Link Styling --- */
.brand-link {
  grid-row: 1;
  grid-column: 1;
  justify-self: start;
  margin: 20px 0 0 20px;

  /* Typography: Open-Source Serif Font Stack */
  font-family: "Noto Serif", "Liberation Serif", serif;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.2px;
  text-decoration: none;
  color: var(--brand-text-color);

  /* Aesthetics: Hard edges, red velvet background, subtle shadow */
  background-color: var(--brand-color);
  border-radius: 0px;
  padding: 10px 16px;
  box-shadow: var(--brand-box-shadow);
}

/* Lights up on hover */
.brand-link:hover {
  background-color: var(--brand-color-hover);
  box-shadow: var(--brand-box-shadow-hover);
  transform: translateY(-1px);
}

/* --- Theme Toggle Button Styling --- */
.theme-toggle {
  grid-row: 1;
  grid-column: 1;
  justify-self: end;
  margin: 20px 20px 0 0;

  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-color);
  padding: 10px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover {
  background-color: var(--syncing-bg);
  transform: scale(1.05);
}

.theme-toggle svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Icon visibility: Default (Light Theme) shows Moon Icon */
#sun-icon { display: none; }
#moon-icon { display: block; }

/* Dark Theme shows Sun Icon */
:root[data-theme="dark"] #sun-icon { display: block; }
:root[data-theme="dark"] #moon-icon { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #sun-icon { display: block; }
  :root:not([data-theme="light"]) #moon-icon { display: none; }
}

/* --- Centered Clock Content --- */
.main-content {
  grid-row: 2;
  grid-column: 1;
  place-self: center;
  text-align: center;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.status-badge {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 20px;
  padding: 8px 16px;
  border-radius: 20px;
  display: inline-block;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.status-exact { background-color: var(--exact-bg); color: var(--exact-text); }
.status-off { background-color: var(--off-bg); color: var(--off-text); }
.status-syncing { background-color: var(--syncing-bg); color: var(--syncing-text); }

.main-content .clock {
  /*
   * 16vw ensures an 8-character time string (e.g. 12:34:56)
   * occupies ~70% of screen width on large displays.
   * clamp() ensures min font size for mobile and no upper limit limit.
   */
  font-size: clamp(3.5rem, 16vw, 25vw);
  font-family: 'Noto Serif', serif;
  line-height: 1;
  white-space: nowrap;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-bottom: 20px;
}

.details {
  font-size: 1.1rem;
  color: var(--subtext-color);
  line-height: 1.6;
}

.highlight {
  color: var(--highlight-color);
  font-weight: bold;
}
