:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1d21;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --border: #e2e5ea;
  --danger: #dc2626;
  --input-bg: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Yu Gothic', sans-serif;
  background: var(--bg);
  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;
}

h1 {
  font-size: 1.5rem;
  margin-bottom: 0.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;
}

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

.mode-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.mode-tab {
  flex: 1;
  padding: 0.6rem 0.5rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
}

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

.mode-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

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

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

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

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

.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(--accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

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

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-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.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;
  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;
}

.notice {
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #9a3412;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  margin-top: 1rem;
}

.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: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.history-header button:hover {
  background: transparent;
  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: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
}

.history-delete:hover {
  background: transparent;
  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;
}

.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-external {
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: none;
  white-space: nowrap;
}

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

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

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

.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;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101214;
    --surface: #17191c;
    --text: #f2f3f5;
    --muted: #9aa0a8;
    --border: #33373c;
    --notice-bg: #3a2a10;
    --input-bg: #1c1f23;
  }

  .qr-image {
    background: white;
  }

  .notice {
    background: #2a1e0f;
    border-color: #7c4a12;
    color: #fdba74;
  }
}
