:root {
  --color-bg: #eef0f2;
  --color-surface: #ffffff;
  --color-surface-elevated: #f7f8f9;
  --color-border: #c8cdd3;
  --color-text: #1a1f24;
  --color-text-muted: #5c6570;
  --color-accent: #c45c26;
  --color-accent-hover: #a84d1f;
  --color-accent-muted: #f4e8df;
  --color-success: #2d6a4f;
  --color-warning-bg: #fff8e6;
  --color-warning-border: #e6c84a;
  --color-warning-text: #5c4a12;
  --color-idle: #5c6570;
  --color-scanning: #c45c26;
  --color-completed: #2d6a4f;
  --font-sans: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 6px;
  --shadow-footer: 0 -4px 24px rgba(26, 31, 36, 0.08);
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --touch-min: 44px;
  --app-max-width: 640px;
  --list-max-height: clamp(240px, 45vh, 480px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: var(--app-max-width);
  margin: 0 auto;
  background: var(--color-surface);
  box-shadow: 0 0 0 1px var(--color-border);
}

@media (min-width: 641px) {
  body {
    padding: var(--space-lg);
  }

  .app {
    min-height: calc(100dvh - var(--space-xl));
    border-radius: var(--radius);
    overflow: hidden;
  }
}

/* Header */
.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-lg) var(--space-md) var(--space-md);
  border-bottom: 3px solid var(--color-accent);
  background: var(--color-surface-elevated);
}

.header__title {
  margin: 0;
  font-size: clamp(1.25rem, 4vw, 1.5rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.header__subtitle {
  margin: var(--space-xs) 0 0;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.badge {
  flex-shrink: 0;
  padding: 0.35em 0.75em;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-radius: var(--radius);
  border: 2px solid currentColor;
}

.badge--idle {
  color: var(--color-idle);
  background: var(--color-surface);
}

.badge--scanning {
  color: var(--color-scanning);
  background: var(--color-accent-muted);
  animation: pulse-badge 1.5s ease-in-out infinite;
}

.badge--completed {
  color: var(--color-completed);
  background: #e8f4ee;
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

@media (prefers-reduced-motion: reduce) {
  .badge--scanning {
    animation: none;
  }
}

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  padding: var(--space-md);
  overflow: hidden;
}

.counter-panel {
  text-align: left;
  padding: var(--space-lg);
  background: var(--color-text);
  color: var(--color-surface);
  border-radius: var(--radius);
}

.counter-panel__label {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.75;
}

.counter-panel__value {
  margin: var(--space-xs) 0 0;
  font-family: var(--font-mono);
  font-size: clamp(2.5rem, 12vw, 3.5rem);
  font-weight: 500;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.banner {
  padding: var(--space-md);
  border-radius: var(--radius);
  font-size: 0.875rem;
}

.banner--warning {
  background: var(--color-warning-bg);
  border: 1px solid var(--color-warning-border);
  color: var(--color-warning-text);
}

.banner p {
  margin: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(120px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(8px);
  max-width: min(90vw, 360px);
  padding: var(--space-sm) var(--space-md);
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
  color: var(--color-surface);
  background: var(--color-text);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(26, 31, 36, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast--duplicate {
  background: var(--color-warning-text);
}

.toast--error {
  background: #9b2c2c;
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: opacity 0.01ms;
  }
}

/* List */
.list-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.list-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-sm);
}

.list-section__title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
}

.list-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.9375rem;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  min-height: 120px;
}

.list-empty p {
  margin: 0;
  max-width: 28ch;
}

.tag-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  max-height: var(--list-max-height);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-elevated);
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 641px) {
  .tag-list {
    --list-max-height: clamp(320px, 50vh, 520px);
  }
}

.tag-list__item {
  display: grid;
  grid-template-columns: 2.5rem 1fr auto;
  align-items: center;
  gap: var(--space-sm) var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9375rem;
}

.tag-list__item:last-child {
  border-bottom: none;
}

.tag-list__item--highlight {
  background: var(--color-accent-muted);
  animation: highlight-row 0.6s ease-out;
}

@keyframes highlight-row {
  from { background: #f9d4b8; }
  to { background: var(--color-accent-muted); }
}

@media (prefers-reduced-motion: reduce) {
  .tag-list__item--highlight {
    animation: none;
    background: var(--color-accent-muted);
  }
}

.tag-list__index {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.tag-list__id {
  font-family: var(--font-mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.tag-list__time {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* Footer */
.footer {
  position: sticky;
  bottom: 0;
  padding: var(--space-md);
  padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: var(--shadow-footer);
}

.footer__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-min);
  padding: 0.625rem 1.25rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--full {
  width: 100%;
}

.btn--primary {
  color: var(--color-surface);
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.btn--primary:hover:not(:disabled) {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}

.btn--secondary {
  color: var(--color-text);
  background: var(--color-surface);
  border-color: var(--color-border);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--color-surface-elevated);
  border-color: var(--color-text-muted);
}

.btn--ghost {
  color: var(--color-text-muted);
  background: transparent;
  border-color: transparent;
  font-weight: 500;
}

.btn--ghost:hover:not(:disabled) {
  color: var(--color-text);
  background: var(--color-surface-elevated);
}

.btn--small {
  min-height: 36px;
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}
