:root {
  color-scheme: light dark;
  --ink:  #000;
  --paper: rgba(255,255,255,.92);
  --line: rgba(0,0,0,.12);

  /* glass + table tokens (LIGHT defaults) */
  --glass:         rgba(255,255,255,.35);
  --header-glass:  rgba(255,255,255,.55);
  --row-even:      rgba(255,255,255,.18);
  --row-hover:     rgba(255,255,255,.26);
}

/* DARK theme (applied when <html data-theme="dark">) */
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink:  #fff;
  --paper: rgba(0,0,0,.55);
  --line: rgba(255,255,255,.20);

  --glass:        rgba(0,0,0,.45);
  --header-glass: rgba(0,0,0,.60);
  --row-even:     rgba(255,255,255,.08);
  --row-hover:    rgba(255,255,255,.14);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  padding: 2rem;
  font: 16px system-ui, sans-serif;
  /* Photo by Simon Berger: https://www.pexels.com/photo/silhouette-of-mountains-1323550/ */
  background: url("images/background.jpg") center / cover no-repeat fixed;
  color: var(--ink);
}

/* --- Form glass (index.html) --- */
form {
  max-width: 640px;
  margin: 0 auto;
  background: var(--glass);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  backdrop-filter: blur(6px) saturate(120%);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  box-shadow: 0 10px 28px rgba(0,0,0,.10);
}

label { display:block; margin:.75rem 0 .25rem; }

input, textarea {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid #444;
  border-radius: 8px;
  background: #fff;
  color: #111;
}

/* Dark-mode inputs so text stays readable */
:root[data-theme="dark"] input,
:root[data-theme="dark"] textarea {
  background: #111;
  color: #fff;
  -webkit-text-fill-color: #fff; /* WebKit quirk */
  border-color: var(--line);
}

textarea { min-height: 120px; resize: vertical; }

/* --- Glass button to match form --- */
button,
input[type="submit"] {
  display: inline-block;
  margin-top: .75rem;
  padding: .8rem 1.1rem;
  color: var(--ink);
  background: var(--glass);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  backdrop-filter: blur(6px) saturate(120%);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(0,0,0,.10);
  cursor: pointer;
  transition: background .2s ease, box-shadow .2s ease, transform .04s ease;
}

button:hover,
input[type="submit"]:hover {
  background: var(--header-glass);
  box-shadow: 0 14px 28px rgba(0,0,0,.14);
}

button:active,
input[type="submit"]:active { transform: translateY(1px); }

button:focus,
input[type="submit"]:focus { outline: 2px solid #4a90e2; outline-offset: 2px; }

button:disabled,
input[type="submit"]:disabled {
  color: var(--ink);
  background: rgba(255,255,255,.25);
  box-shadow: none;
  cursor: not-allowed;
  opacity: .85;
}

.hidden { position:absolute; left:-9999px; }

:focus { outline: 2px solid #4a90e2; outline-offset: 2px; }

/* --- Viewer table (view.cgi) — glassy over background --- */
.table-shell {
  background: var(--glass);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  backdrop-filter: blur(6px) saturate(120%);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0,0,0,.10);
  overflow: hidden;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  color: var(--ink);
  background: transparent; /* don't cover the photo */
}

thead th {
  position: sticky; top: 0; z-index: 1;
  color: var(--ink);
  background: var(--header-glass);
  text-align: left;
  font-weight: 700;
  letter-spacing: .01em;
}

th, td {
  border: 1px solid var(--line);
  padding: .65rem .85rem;
  vertical-align: top;
}

/* Zebra + hover using variables */
tbody tr:nth-child(even) td { background: var(--row-even); }
tbody tr:hover td           { background: var(--row-hover); }

/* Fallback if you can't wrap the table */
table.view-card {
  background: var(--glass);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  backdrop-filter: blur(6px) saturate(120%);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0,0,0,.10);
  overflow: hidden;
}

/* --- Mobile tweaks --- */
@media (max-width: 640px) {
  body {
    padding: 1rem;
    /* fixed backgrounds stutter on mobile; switch to scroll */
    background-attachment: scroll;
  }

  form {
    padding: .9rem 1rem;
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(0,0,0,.08);
  }

  label { margin: .6rem 0 .25rem; }

  input, textarea {
    padding: .7rem;
    border-radius: 10px;
    font-size: 16px; /* prevent iOS zoom */
  }

  button,
  input[type="submit"] {
    width: 100%;
    padding: .9rem 1rem;
    font-weight: 600;
    border-radius: 12px;
  }

  /* Table: allow sideways scroll instead of crushing columns */
  .table-shell { overflow-x: auto; }
  table { min-width: 640px; }

  /* Index page: center the toggle above the form on small screens */
  .page-index .theme-toggle {
    float: none;
    display: block;
    margin: 0 auto 1rem;
  }
}

/* Toggle button (default: fixed in corner — used on view page) */
.theme-toggle{
  position: fixed; top: 1rem; right: 1rem;
  color: var(--ink);
  background: var(--glass);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  backdrop-filter: blur(6px) saturate(120%);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .5rem .8rem;
  box-shadow: 0 8px 20px rgba(0,0,0,.10);
  z-index: 100000;
}

/* Index page: place toggle above form in-flow (no overlap) */
.page-index .theme-toggle { position: static; float: right; margin: 0 0 1rem 0; }
.page-index form { clear: both; }
