:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #5d6676;
  --border: #dde1e7;
  --primary: #1f4fd6;
  --primary-text: #ffffff;
  --green: #1e8a4c;
  --green-bg: #e6f5ec;
  --yellow: #8a6500;
  --yellow-bg: #fff6d6;
  --yellow-bar: #e0a800;
  --red: #b4232a;
  --red-bg: #fde8e8;
  --black-panel: #0e1014;
  --black-text: #ffffff;
  --black-muted: #c3c9d3;
  --black-edge: #0e1014;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
      --bg: #12151b;
      --surface: #1b2029;
      --text: #e8ebf0;
      --muted: #9aa3b2;
      --border: #2c3340;
      --primary: #5b84f5;
      --green: #4cc982;
      --green-bg: #15301f;
      --yellow: #f2c84b;
      --yellow-bg: #3a3011;
      --yellow-bar: #f2c84b;
      --red: #f27378;
      --red-bg: #3d1a1c;
      --black-panel: #000000;
      --black-edge: #e8ebf0;
      color-scheme: dark;
  }
}

:root[data-theme="dark"] {
    --bg: #12151b;
    --surface: #1b2029;
    --text: #e8ebf0;
    --muted: #9aa3b2;
    --border: #2c3340;
    --primary: #5b84f5;
    --green: #4cc982;
    --green-bg: #15301f;
    --yellow: #f2c84b;
    --yellow-bg: #3a3011;
    --yellow-bar: #f2c84b;
    --red: #f27378;
    --red-bg: #3d1a1c;
    --black-panel: #000000;
    --black-edge: #e8ebf0;
    color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

.container {
  position: relative;
  max-width: 880px;
  margin: 0 auto;
  padding-block: 32px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.brand {
  font-family: "Instrument Serif", Georgia, "Times New Roman", serif;
  font-weight: 400;
  font-size: 2.8125rem; /* 25% larger than 2.25rem */
  line-height: 1.1;
  letter-spacing: 0.01em;
  margin: 0 0 6px;
}
.brand, .page-header h1 { text-align: center; text-wrap: balance; }
/* Brand links share one quiet style: text color, no underline. */
.brand a,
.copyright a {
  color: inherit;
  text-decoration: none;
  border-radius: 4px;
}
.brand a:focus-visible,
.copyright a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
h1 { font-size: 1.5rem; margin: 0 0 8px; } /* 24px at the default text size, on all screens */
h2 { font-size: 1.15rem; margin: 0; }
.lede { color: var(--muted); margin: 0 0 24px; }

/* Light and dark mode button, upper right corner */
.theme-toggle {
  position: absolute;
  top: 16px;
  right: max(16px, env(safe-area-inset-right, 0px));
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.theme-toggle:hover { border-color: var(--muted); }
.theme-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.theme-toggle svg { fill: currentColor; stroke: currentColor; }
.theme-toggle .icon-moon { stroke: none; }
/* Show the moon in light mode (tap for dark) and the sun in dark mode (tap for light). */
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* Summary */
.summary {
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  border: 2px solid var(--accent);
  background: var(--accent-bg);
  transition: background .2s, border-color .2s;
}
.status-green  { --accent: var(--green);  --accent-bg: var(--green-bg);  --bar: var(--green); }
.status-yellow { --accent: var(--yellow); --accent-bg: var(--yellow-bg); --bar: var(--yellow-bar); }
.status-red    { --accent: var(--red);    --accent-bg: var(--red-bg);    --bar: var(--red); }
.status-black  { --accent: var(--black-text); --accent-bg: var(--black-panel); --bar: var(--black-text); border-color: var(--black-edge); }
.status-black .summary-label,
.status-black .summary-limit,
.status-black .summary-window,
.status-black .summary-remaining { color: var(--black-muted); }
.status-black .meter { background: #3a404b; }

.summary-main { display: flex; flex-direction: column; gap: 2px; }
.summary-label { font-weight: 600; color: var(--muted); }
.summary-total {
  font-size: 3.5rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.summary-limit { font-size: 1.5rem; font-weight: 600; color: var(--muted); }
.status-emoji { font-size: 2rem; margin-left: 12px; vertical-align: 0.15em; }
.status-text { font-weight: 700; color: var(--accent); font-size: 1.1rem; }

.meter {
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin: 16px 0 12px;
}
.meter-fill {
  height: 100%;
  width: 0;
  background: var(--bar);
  transition: width .25s ease;
}
.summary-window, .summary-remaining { margin: 0; color: var(--muted); }

/* Warning */
.warning {
  background: var(--red-bg);
  border-left: 6px solid var(--red);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}
.warning h2 { color: var(--red); margin-bottom: 6px; }
.warning p { margin: 0; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-footer {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}
.hint { color: var(--muted); font-size: .9rem; margin: 8px 0 0; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: .9rem; color: var(--muted); }

input[type="date"], select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 42px;
  width: 100%;
  min-width: 0;
}
input:focus, select:focus, .btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
#reference-date { max-width: 240px; }

/* Buttons */
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  padding: 8px 14px;
  min-height: 40px;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost.confirming { color: var(--red); border-color: var(--red); }
.btn-remove { background: transparent; color: var(--red); border-color: var(--border); }

/* Trips */
.trip-list { list-style: none; margin: 0; padding: 0; }
/* Country spans the full row so long native names stay readable;
   dates, day count, and the remove button share the row below. */
.trip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 110px 90px;
  gap: 10px;
  align-items: end;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.trip:first-child { border-top: 0; padding-top: 0; }
.trip .field:first-child { grid-column: 1 / -1; }
.trip .field-label { font-size: .85rem; color: var(--muted); }
.trip-days {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 42px;
  font-variant-numeric: tabular-nums;
}
.trip-days-value { font-weight: 700; }
.trip-error { grid-column: 1 / -1; color: var(--red); margin: 0; font-size: .9rem; }
.trip.invalid input { border-color: var(--red); }
.empty { color: var(--muted); text-align: center; padding: 16px 0; margin: 0; }

/* Export */
.export-hint { margin: 0 0 14px; }
.export-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
}
.export-format { flex: 1 1 220px; max-width: 320px; }
.export-actions { display: flex; gap: 10px; margin-left: auto; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.export-status { margin: 12px 0 0; color: var(--green); font-weight: 600; }

.disclaimer { color: var(--muted); font-size: .85rem; }
.disclaimer p { margin: 0 0 6px; }
.footer-icon { display: block; width: 75px; height: 75px; margin: 24px auto 0; }
/* One blank line (1.5em = the footer line height) between the icon and the copyright. */
.copyright {
  margin-top: 1.5em !important;
  text-align: center;
  /* Instrument Serif has a single regular weight and runs small, so it is set
     at regular weight and a little larger than the rest of the footer. */
  font-family: "Instrument Serif", Georgia, "Times New Roman", serif;
  font-weight: 400;
  font-size: 1.125rem; /* 18px at the default text size */
  letter-spacing: 0.01em;
}

@media (max-width: 680px) {
  .container { padding-top: 68px; }
  .theme-toggle { top: 14px; }
  .brand { font-size: 2.375rem; } /* 25% larger than 1.9rem */
  .summary-total { font-size: 2.8rem; }
  .trip { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  #reference-date { max-width: none; }
  .export-format { max-width: none; flex-basis: 100%; }
}

/* Add to Home Screen banner */
.install-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 20px rgba(0, 0, 0, .12);
  padding-top: 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.install-icon { width: 48px; height: 48px; border-radius: 11px; flex: none; }
.install-text { display: flex; flex-direction: column; flex: 1 1 220px; min-width: 0; font-size: .95rem; }
.install-text span { color: var(--muted); }
.install-actions { display: flex; gap: 8px; margin-left: auto; }
.share-glyph {
  display: inline-block;
  width: 14px;
  height: 17px;
  vertical-align: -2px;
  background: var(--primary);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 17'%3E%3Cpath d='M7 0l3.5 3.5-1 1L7.7 2.7V11H6.3V2.7L4.5 4.5l-1-1z'/%3E%3Cpath d='M1 6h3.5v1.4H2.4v8.2h9.2V7.4H9.5V6H13v11H1z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 17'%3E%3Cpath d='M7 0l3.5 3.5-1 1L7.7 2.7V11H6.3V2.7L4.5 4.5l-1-1z'/%3E%3Cpath d='M1 6h3.5v1.4H2.4v8.2h9.2V7.4H9.5V6H13v11H1z'/%3E%3C/svg%3E") center / contain no-repeat;
}
body.has-install-banner { padding-bottom: 140px; }

@media (prefers-reduced-motion: reduce) {
  .summary, .meter-fill { transition: none; }
}
