:root {
  color-scheme: light dark;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1c1b19;
  --muted: #8a8377;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e6edfc;
  --border: #e1dcd0;
  --danger: #b3401f;
  --input-bg: #ffffff;
  --button-bg: #2563eb;
  --button-bg-hover: #1d4ed8;
  --button-text: #ffffff;
  --grid-dot: rgba(28, 27, 25, 0.06);
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Yu Gothic', sans-serif;
  background-color: var(--bg);
  background-image: radial-gradient(circle, var(--grid-dot) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.6;
}

main {
  width: 100%;
  max-width: 480px;
  padding: 2rem 1rem;
  box-sizing: border-box;
}

@media (min-width: 860px) {
  main {
    max-width: 600px;
  }
}

@media (min-width: 1400px) {
  main {
    max-width: 720px;
  }
}

/* Once a result exists, there is something worth putting beside the form —
   switch to a two-column layout instead of leaving the wide viewport empty. */
@media (min-width: 1100px) {
  main:has(#result:not(.hidden)) {
    max-width: 980px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
    gap: 2rem;
  }

  main:has(#result:not(.hidden)) > .site-footer {
    grid-column: 1 / -1;
  }
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 1.25rem;
}

p.lead {
  color: var(--muted);
  margin-top: 0;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

form label {
  margin-top: 0.9rem;
}

form label:first-of-type {
  margin-top: 0;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.4rem 1rem;
  margin-top: 0.9rem;
}

.form-field label {
  margin-top: 0;
}

.field-heading {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.hint-wrap {
  position: relative;
  display: inline-flex;
}

.hint-trigger {
  width: 1.15rem;
  height: 1.15rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: help;
}

.hint-trigger:hover,
.hint-trigger:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.hint-bubble {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: 5;
  width: max-content;
  max-width: 220px;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.45;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}

.hint-trigger:hover + .hint-bubble,
.hint-trigger:focus-visible + .hint-bubble {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .hint-bubble {
    transition: none;
  }
}

#submit-button {
  margin-top: 0.6rem;
}

.mode-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.25rem;
}

.mode-tab {
  flex: 1;
  padding: 0.55rem 0.5rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 6px;
  transition: background 0.15s ease, color 0.15s ease;
}

.mode-tab:hover {
  background: transparent;
  color: var(--text);
}

.mode-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.mode-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 6px;
}

label {
  font-size: 0.875rem;
  font-weight: 600;
}

input[type="url"],
input[type="text"],
input[type="email"],
textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: var(--font-mono);
  background: var(--input-bg);
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 6rem;
}

input[type="url"]:focus-visible,
input[type="text"]:focus-visible,
input[type="email"]:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Honeypot field for spam bots: hidden from sighted users and screen readers alike, but
   still present in the DOM/tab order for naive bots that fill in every field they can see. */
.hp-field {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin: -0.4rem 0 0;
}

button {
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--button-bg);
  color: var(--button-text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

button:hover {
  background: var(--button-bg-hover);
}

@media (prefers-reduced-motion: reduce) {
  button {
    transition: none;
  }
}

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

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

.error {
  color: var(--danger);
  font-size: 0.9rem;
  min-height: 1.2em;
}

.hidden {
  display: none !important;
}

.qr-image {
  display: block;
  width: 240px;
  height: 240px;
  margin: 0 auto 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.field {
  margin-bottom: 1rem;
}

.field:last-child {
  margin-bottom: 0;
}

.field-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.section-heading {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.copy-row {
  display: flex;
  gap: 0.5rem;
}

.copy-row input {
  flex: 1;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  font-family: var(--font-mono);
  background: var(--input-bg);
  color: var(--text);
}

.copy-row input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.copy-row button {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  white-space: nowrap;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
}

.copy-row button:hover {
  background: var(--accent);
  color: var(--surface);
}

.notice {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  margin-top: 1rem;
}

/* viewfinder-framed card: echoes a QR code's 3 finder squares */
.viewfinder-frame {
  position: relative;
  padding: 1.75rem 1.5rem;
  margin-bottom: 1.25rem;
}

.viewfinder-frame > .card {
  margin-bottom: 0;
}

.viewfinder-frame::before,
.viewfinder-frame::after,
.viewfinder-frame .corner-bl {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent);
}

.viewfinder-frame::before {
  top: 0;
  left: 0;
  border-right: none;
  border-bottom: none;
  border-radius: 4px 0 0 0;
}

.viewfinder-frame::after {
  top: 0;
  right: 0;
  border-left: none;
  border-bottom: none;
  border-radius: 0 4px 0 0;
}

.viewfinder-frame .corner-bl {
  bottom: 0;
  left: 0;
  border-right: none;
  border-top: none;
  border-radius: 0 0 0 4px;
}

.stat-total {
  font-size: 2.5rem;
  font-weight: 700;
}

.stat-total-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 140px;
  margin-top: 1rem;
  overflow-x: auto;
  padding-bottom: 1.5rem;
  position: relative;
}

.chart-bar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  flex: 1 0 auto;
  height: 100%;
  min-width: 8px;
  position: relative;
}

.chart-bar {
  width: 100%;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
}

.chart-bar-wrap .chart-date {
  position: absolute;
  bottom: -1.3rem;
  font-size: 0.6rem;
  color: var(--muted);
  writing-mode: horizontal-tb;
  white-space: nowrap;
}

.target-url {
  word-break: break-all;
  font-size: 0.9rem;
}

a.back-link {
  color: var(--accent);
  font-size: 0.85rem;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.history-header button {
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}

.history-header button:hover {
  background: var(--border);
  color: var(--text);
  border-color: var(--muted);
}

.history-empty {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

.history-item {
  padding: 0.85rem 0;
  border-top: 1px solid var(--border);
}

.history-item:first-child {
  padding-top: 0;
  border-top: none;
}

.history-item-meta {
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 0.5rem;
  word-break: break-all;
}

.history-item .copy-row {
  margin-bottom: 0.4rem;
}

.history-actions {
  display: flex;
  justify-content: flex-end;
}

.history-delete {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  background: var(--bg);
  color: var(--danger);
  border: 1px solid var(--border);
}

.history-delete:hover {
  background: var(--danger);
  color: var(--surface);
  border-color: var(--danger);
}

.site-nav {
  width: 100%;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.site-nav-inner {
  max-width: 480px;
  margin: 0 auto;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  box-sizing: border-box;
}

@media (min-width: 860px) {
  .site-nav-inner {
    max-width: 600px;
  }
}

@media (min-width: 1400px) {
  .site-nav-inner {
    max-width: 720px;
  }
}

.site-nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
  min-width: 0;
}

.site-nav-brand span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-nav-logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
}

.site-nav-links {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.site-nav-external {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: none;
  white-space: nowrap;
}

.site-nav-external:hover {
  color: var(--text);
}

.site-nav-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.site-footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 0.5rem;
}

.site-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  justify-content: center;
}

@media (min-width: 500px) {
  .site-footer {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .site-footer-links {
    justify-content: flex-end;
  }
}

.site-footer-links a {
  color: var(--muted);
  font-size: 0.8rem;
}

.site-footer-external {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
}

.external-icon {
  font-size: 0.75em;
}

.site-footer-copyright {
  color: var(--muted);
  font-size: 0.75rem;
  margin: 0;
}

.ad-slot {
  margin-top: 2rem;
  max-width: 100%;
  overflow-x: auto;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #1e2023;
    --text: #f1efe9;
    --muted: #9a978c;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --accent-soft: #1e2a3f;
    --border: #34373a;
    --danger: #e2795a;
    --input-bg: #1c1f23;
    --grid-dot: rgba(255, 255, 255, 0.05);
  }

  .qr-image {
    background: white;
  }
}
