/* ========================================
   Night Ledger Design System
   ダークインクの記録帳に、シアン→バイオレットの
   ネオングロー（アプリアイコン由来）を差し色として使う。
   ======================================== */
:root {
  /* Dark theme (default) */
  --bg-primary: #0b0c14;
  --bg-secondary: #12131f;
  --bg-card: #171827;
  --bg-card-hover: #1d1f31;
  --bg-input: #101120;
  --bg-elevated: #1c1e30;

  --text-primary: #f4f2fb;
  --text-secondary: #a8a4c4;
  --text-muted: #6d6a8a;

  --accent-from: #38c6f4;
  --accent-to: #8b5cf6;
  --accent: #7b6bf5;
  --accent-hover: #9284ff;
  --accent-subtle: rgba(123, 107, 245, 0.14);
  --accent-glow: rgba(123, 107, 245, 0.35);
  --accent-gradient: linear-gradient(135deg, var(--accent-from), var(--accent-to));

  --success: #4ddba0;
  --success-subtle: rgba(77, 219, 160, 0.12);
  --success-glow: rgba(77, 219, 160, 0.35);
  --warning: #f2c168;
  --error: #ff7d95;
  --error-subtle: rgba(255, 90, 116, 0.14);
  --error-glow: rgba(255, 90, 116, 0.35);

  --border-color: rgba(226, 222, 255, 0.09);
  --border-active: rgba(123, 107, 245, 0.55);
  --divider: rgba(226, 222, 255, 0.06);

  --shadow-sm: 0 2px 6px rgba(2, 2, 10, 0.3);
  --shadow-md: 0 6px 16px rgba(2, 2, 10, 0.36);
  --shadow-lg: 0 16px 36px rgba(2, 2, 10, 0.48);
  --shadow-card: 0 2px 8px rgba(2, 2, 10, 0.3), 0 0 0 1px rgba(226, 222, 255, 0.03);

  --overlay-bg: rgba(4, 4, 12, 0.62);

  /* Spacing - 4px grid */
  --space-2: 2px;
  --space-4: 4px;
  --space-8: 8px;
  --space-12: 12px;
  --space-16: 16px;
  --space-20: 20px;
  --space-24: 24px;
  --space-32: 32px;
  --space-40: 40px;
  --space-48: 48px;

  --action-button-size: 56px;

  /* Typography */
  --font-primary: 'Zen Kaku Gothic New', 'Hiragino Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Kaisei Decol', 'Hiragino Mincho ProN', serif;
  --font-size-caption: 0.75rem;    /* 12px */
  --font-size-body2: 0.8125rem;    /* 13px */
  --font-size-body1: 0.875rem;     /* 14px */
  --font-size-subtitle2: 1rem;     /* 16px */
  --font-size-subtitle1: 1.25rem;  /* 20px */
  --font-size-title: 1.5rem;       /* 24px */
  --font-size-display: 2rem;       /* 32px */

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Motion */
  --duration-fast: 100ms;
  --duration-normal: 200ms;
  --duration-slow: 300ms;
  --easing: cubic-bezier(0.33, 0, 0.67, 1);
  --easing-decelerate: cubic-bezier(0, 0, 0, 1);
  --easing-accelerate: cubic-bezier(1, 0, 1, 1);

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ========================================
   Light Theme — 和紙のような温かい紙面
   ======================================== */
[data-theme="light"] {
  --bg-primary: #f6f3ee;
  --bg-secondary: #fffcf8;
  --bg-card: #ffffff;
  --bg-card-hover: #f6f1ff;
  --bg-input: #f6f3ee;
  --bg-elevated: #ffffff;

  --text-primary: #241f33;
  --text-secondary: #625d7c;
  --text-muted: #9d97b4;

  --accent-from: #2fa9d6;
  --accent-to: #6f4de0;
  --accent: #5d4bd6;
  --accent-hover: #4c3bc4;
  --accent-subtle: rgba(93, 75, 214, 0.08);
  --accent-glow: rgba(93, 75, 214, 0.16);
  --accent-gradient: linear-gradient(135deg, var(--accent-from), var(--accent-to));

  --success: #12886a;
  --success-subtle: rgba(18, 136, 106, 0.08);
  --success-glow: rgba(18, 136, 106, 0.18);
  --warning: #b1770a;
  --error: #c23a5b;
  --error-subtle: rgba(194, 58, 91, 0.08);
  --error-glow: rgba(194, 58, 91, 0.18);

  --border-color: rgba(36, 31, 51, 0.08);
  --border-active: rgba(93, 75, 214, 0.4);
  --divider: rgba(36, 31, 51, 0.05);

  --shadow-sm: 0 2px 4px rgba(36, 31, 51, 0.04);
  --shadow-md: 0 4px 10px rgba(36, 31, 51, 0.06);
  --shadow-lg: 0 10px 24px rgba(36, 31, 51, 0.09);
  --shadow-card: 0 2px 6px rgba(36, 31, 51, 0.05), 0 0 0 1px rgba(36, 31, 51, 0.02);

  --overlay-bg: rgba(36, 31, 51, 0.32);
}

/* ========================================
   Reset & Base
   ======================================== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-primary);
  background:
    radial-gradient(900px 480px at 12% -8%, var(--accent-subtle), transparent 60%),
    radial-gradient(700px 420px at 108% 8%, rgba(56, 198, 244, 0.08), transparent 55%),
    var(--bg-primary);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--duration-slow) var(--easing),
              color var(--duration-slow) var(--easing);
}

/* ========================================
   Icon utility
   ======================================== */
.icon {
  width: 20px;
  height: 20px;
  display: block;
  flex: 0 0 auto;
}

/* ========================================
   App Container
   ======================================== */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: calc(var(--space-24) + var(--safe-bottom));
}

.app-footer {
  display: flex;
  justify-content: center;
  padding: var(--space-8) var(--space-16) calc(var(--space-16) + var(--safe-bottom));
}

.app-footer a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: var(--space-8) var(--space-12);
  color: var(--text-secondary);
  font-size: var(--font-size-body1);
  text-decoration: underline;
  text-underline-offset: 3px;
  border-radius: var(--radius-md);
}

.app-footer a:hover {
  color: var(--accent-hover);
  background: var(--accent-subtle);
}

.app-footer a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ========================================
   Header
   ======================================== */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--bg-secondary) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 1px 0 rgba(123, 107, 245, 0.06);
  padding: var(--space-12) var(--space-16);
  padding-top: calc(var(--space-12) + env(safe-area-inset-top, 0px));
  transition: background var(--duration-slow) var(--easing);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.logo-image {
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(36px, 8vw, 40px);
  height: clamp(36px, 8vw, 40px);
  flex: 0 0 auto;
  border-radius: 12px;
  background: #ffffff;
  object-fit: contain;
  overflow: hidden;
  box-shadow: 0 0 14px var(--accent-glow);
}

.logo h1 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-normal) var(--easing);
}

.settings-btn .icon {
  width: 19px;
  height: 19px;
}

.settings-btn:hover {
  background: var(--accent-subtle);
  border-color: var(--border-color);
}

.settings-btn:active {
  transform: scale(0.94);
}

.settings-btn.needs-setup {
  background: var(--accent-subtle);
  border-color: var(--accent);
  animation: needsSetup 2.5s ease-in-out infinite;
}

@keyframes needsSetup {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.tasks-btn {
  position: relative;
}

.tasks-btn.is-open {
  background: var(--accent-subtle);
  border-color: var(--border-active);
  color: var(--accent);
}

.tasks-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
}

/* ========================================
   Status Banner
   ======================================== */
.status-banner {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin: var(--space-12) var(--space-16);
  padding: var(--space-12) var(--space-16);
  border-radius: var(--radius-md);
  background: var(--success-subtle);
  border: 1px solid var(--success-glow);
  color: var(--success);
  font-size: var(--font-size-body2);
  animation: bannerIn var(--duration-slow) var(--easing-decelerate);
}

.status-banner #status-text {
  color: var(--text-primary);
}

.status-banner .icon {
  color: inherit;
  width: 18px;
  height: 18px;
}

.status-banner.error {
  background: var(--error-subtle);
  border-color: var(--error-glow);
  color: var(--error);
}

@keyframes bannerIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.hidden {
  display: none !important;
}

/* ========================================
   PWA Install Banner
   ======================================== */
.install-banner {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin: var(--space-12) var(--space-16);
  padding: var(--space-12) var(--space-16);
  border-radius: var(--radius-md);
  background: var(--accent-subtle);
  border: 1px solid var(--border-active);
  font-size: var(--font-size-body2);
  color: var(--text-primary);
  animation: bannerIn var(--duration-slow) var(--easing-decelerate);
}

.install-banner-icon {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent-from), var(--accent));
  color: #ffffff;
}

.install-banner-icon .icon {
  width: 16px;
  height: 16px;
}

.install-banner-text {
  flex: 1;
  min-width: 0;
}

.install-banner-btn {
  flex: 0 0 auto;
  padding: var(--space-8) var(--space-12);
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #ffffff;
  font-family: var(--font-primary);
  font-size: var(--font-size-body2);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration-normal) var(--easing);
}

.install-banner-btn:hover {
  background: var(--accent-hover);
}

.install-banner-close {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
}

.install-banner-close .icon {
  width: 15px;
  height: 15px;
}

/* ========================================
   Cards - Fluent elevated surface
   ======================================== */
.card {
  margin: var(--space-12) var(--space-16);
  padding: var(--space-16);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  transition: all var(--duration-normal) var(--easing);
}

.card-header {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin-bottom: var(--space-12);
}

.card-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 3px 10px var(--accent-glow);
}

.card-icon .icon {
  width: 16px;
  height: 16px;
}

.card-icon[data-icon="star"] {
  background: linear-gradient(135deg, #ffd166, #ff9f5a);
  box-shadow: 0 3px 10px rgba(255, 184, 92, 0.4);
}

.card-icon[data-icon="clipboard"] {
  background: linear-gradient(135deg, var(--accent-from), #4fd1c5);
  box-shadow: 0 3px 10px rgba(56, 198, 244, 0.35);
}

.card-header h2 {
  font-family: var(--font-display);
  font-size: var(--font-size-subtitle2);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

/* ========================================
   Input
   ======================================== */
.input-row {
  display: flex;
  align-items: stretch;
  gap: var(--space-8);
}

.input-group {
  position: relative;
  flex: 1;
  min-width: 0;
}

#activity-input {
  width: 100%;
  padding: var(--space-12);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-bottom: 2px solid var(--text-muted);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: var(--font-size-body1);
  line-height: 1.5;
  resize: none;
  transition: all var(--duration-normal) var(--easing);
  outline: none;
}

#activity-input::placeholder {
  color: var(--text-muted);
}

#activity-input:focus {
  border-bottom-color: var(--accent);
  background: var(--bg-card);
}

.char-count {
  position: absolute;
  bottom: var(--space-4);
  right: var(--space-12);
  font-size: var(--font-size-caption);
  color: var(--text-muted);
}

.register-btn {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: var(--action-button-size);
  height: var(--action-button-size);
  min-width: var(--action-button-size);
  min-height: var(--action-button-size);
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  color: #ffffff;
  font-family: var(--font-primary);
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  cursor: pointer;
  transition: all var(--duration-normal) var(--easing);
}

.register-btn:not(:disabled):hover {
  filter: brightness(1.08);
  box-shadow: var(--shadow-md), 0 0 18px var(--accent-glow);
}

.register-btn:not(:disabled):active {
  transform: scale(0.95);
}

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

.register-btn.has-active {
  background: linear-gradient(135deg, var(--success), #37b98a);
}

.register-btn.has-active:not(:disabled):hover {
  filter: brightness(1.1);
  box-shadow: var(--shadow-md), 0 0 18px var(--success-glow);
}

.register-btn .action-btn-icon .icon {
  width: 22px;
  height: 22px;
}

.register-btn .action-btn-text {
  font-size: var(--font-size-caption);
  font-weight: 600;
}

.register-btn > .icon { width: 22px; height: 22px; }

.range-mode-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin-top: var(--space-12);
  font-size: var(--font-size-body2);
  color: var(--text-secondary);
  cursor: pointer;
}

.range-mode-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ========================================
   Active Event Card
   ======================================== */
.active-card {
  border-left: 3px solid var(--success) !important;
  background: var(--success-subtle);
}

.active-event-line {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.pulse-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 0 4px var(--success-subtle), 0 0 8px var(--success-glow);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.active-event-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--font-size-subtitle2);
  font-weight: 600;
  color: var(--text-primary);
}

.active-event-elapsed {
  flex: 0 0 auto;
  font-size: var(--font-size-body1);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  letter-spacing: 1px;
}

.active-stop-btn {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: var(--action-button-size);
  min-height: var(--action-button-size);
  width: var(--action-button-size);
  height: var(--action-button-size);
  border-radius: var(--radius-full);
  border: 1px solid var(--error);
  background: var(--bg-card);
  color: var(--error);
  font-family: var(--font-primary);
  cursor: pointer;
  transition: all var(--duration-normal) var(--easing);
}

.active-stop-btn:hover {
  background: var(--error-subtle);
}

.active-stop-btn:active {
  transform: scale(0.93);
}

.active-stop-btn .action-btn-icon .icon {
  width: 17px;
  height: 17px;
}

.active-stop-btn .action-btn-text {
  font-size: 0.65rem;
  font-weight: 600;
}

.active-stop-btn .action-btn-icon .icon { width: 21px; height: 21px; }

/* ========================================
   Async Tasks Page
   ======================================== */
.tasks-view {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-16);
  padding-bottom: calc(var(--space-24) + var(--safe-bottom));
}

.tasks-view-header {
  justify-content: space-between;
  margin-bottom: var(--space-12);
}

.tasks-view-header h2 {
  font-size: var(--font-size-subtitle2);
  font-weight: 600;
  color: var(--text-primary);
}

.tasks-sync-bar {
  position: sticky;
  top: calc(var(--space-12) + env(safe-area-inset-top, 0px));
  z-index: 10;
  background: var(--bg-primary);
  padding-bottom: var(--space-8);
}

.tasks-list-heading {
  font-size: var(--font-size-caption);
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: var(--space-8);
  padding-left: var(--space-4);
}

.pending-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ========================================
   Templates - dropdown select
   ======================================== */
.templates-row {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.templates-row .card-icon {
  flex: 0 0 auto;
}

.templates-select {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  width: auto;
  margin-bottom: 0;
  cursor: pointer;
}

.add-template-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  padding: var(--space-8);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--duration-normal) var(--easing);
}

.add-template-btn .btn-icon .icon {
  width: 16px;
  height: 16px;
}

.add-template-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-subtle);
}

/* ========================================
   Loading Overlay
   ======================================== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-16);
  z-index: 1000;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay p {
  color: var(--text-secondary);
  font-size: var(--font-size-body1);
}

/* ========================================
   Settings Modal - Fluent dialog
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn var(--duration-normal) var(--easing);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  background: var(--bg-secondary);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border: 1px solid var(--border-color);
  border-bottom: none;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp var(--duration-slow) var(--easing-decelerate);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-16) var(--space-20);
  border-bottom: 1px solid var(--divider);
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 1;
}

.modal-header h2 {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-title-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 3px 10px var(--accent-glow);
}

.modal-title-icon .icon {
  width: 16px;
  height: 16px;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-normal) var(--easing);
}

.modal-close .icon {
  width: 16px;
  height: 16px;
}

.modal-close:hover {
  background: var(--error-subtle);
  color: var(--error);
}

.modal-body {
  padding: var(--space-20);
  padding-bottom: calc(var(--space-40) + var(--safe-bottom));
}

.settings-section {
  margin-bottom: var(--space-24);
}

.settings-section h3 {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  font-size: var(--font-size-body1);
  font-weight: 600;
  margin-bottom: var(--space-8);
  color: var(--text-primary);
}

.section-icon {
  display: flex;
  color: var(--accent);
}

.section-icon .icon {
  width: 16px;
  height: 16px;
}

.section-icon[data-icon="star"] {
  color: #ff9f5a;
}

.settings-summary {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  cursor: pointer;
  font-weight: 600;
  padding: var(--space-4) 0;
  color: var(--text-primary);
}

.settings-summary .section-icon {
  color: var(--warning);
}

.settings-summary::-webkit-details-marker {
  color: var(--text-muted);
}

.settings-desc {
  font-size: var(--font-size-body2);
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: var(--space-12);
}

.settings-desc a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.settings-desc a:hover {
  text-decoration: underline;
}

.help-content { margin-top: 15px; font-size: var(--font-size-body2); line-height: 1.6; }
.help-flows { display: grid; gap: var(--space-12); }
.help-flow { min-width: 0; margin: 0; padding: var(--space-12); border: 1px solid var(--border-color); border-radius: var(--radius-md); background: var(--bg-card); }
.help-flow figcaption { display: flex; align-items: center; gap: var(--space-8); margin-bottom: var(--space-8); color: var(--text-primary); font-weight: 700; }
.help-flow-steps { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-8); padding: 0; margin: 0 0 var(--space-8); list-style: none; }
.help-flow-card { display: flex; align-items: center; gap: var(--space-4); min-height: 44px; padding: var(--space-8); border: 1px solid var(--border-active); border-radius: var(--radius-sm); color: var(--text-primary); background: var(--bg-input); }
.help-flow-card .icon { flex: 0 0 auto; width: 16px; height: 16px; color: var(--accent); }
.help-flow-arrow { color: var(--accent); font-size: 1.2rem; font-weight: 700; }
.help-flow p { margin: 0; color: var(--text-secondary); overflow-wrap: anywhere; }
.help-steps { padding-left: 1.35rem; margin: var(--space-16) 0 0; color: var(--text-secondary); }
.help-steps li { padding: var(--space-4) 0; }

/* Keep touch targets usable without making the flow cards interactive. */
.settings-btn, .modal-close, .install-banner-close { min-width: 44px; min-height: 44px; }

.setup-steps {
  list-style: none;
  counter-reset: steps;
  font-size: var(--font-size-body2);
  color: var(--text-secondary);
  padding: 0;
}

.setup-steps li {
  counter-increment: steps;
  padding: var(--space-8) 0;
  padding-left: var(--space-32);
  position: relative;
  line-height: 1.5;
  border-bottom: 1px solid var(--divider);
}

.setup-steps li::before {
  content: counter(steps);
  position: absolute;
  left: 0;
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-caption);
  font-weight: 600;
  color: white;
  top: var(--space-8);
}

.settings-label {
  display: block;
  font-size: var(--font-size-body2);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

.settings-input {
  width: 100%;
  padding: var(--space-12);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-bottom: 2px solid var(--text-muted);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: var(--font-size-body2);
  outline: none;
  transition: all var(--duration-normal) var(--easing);
  margin-bottom: var(--space-12);
}

.settings-input--inline {
  margin-bottom: 0;
  flex: 1;
}

.settings-input::placeholder {
  color: var(--text-muted);
}

.settings-input:focus {
  border-bottom-color: var(--accent);
  background: var(--bg-card);
}

.settings-status {
  min-height: 20px;
  margin-bottom: var(--space-12);
  font-size: var(--font-size-body2);
  text-align: center;
}

.settings-status.success {
  color: var(--success);
}

.settings-status.error {
  color: var(--error);
}

.settings-actions {
  display: flex;
  gap: var(--space-8);
}

.settings-save-btn {
  flex: 2;
  padding: var(--space-12);
  background: var(--accent-gradient);
  border: none;
  border-radius: var(--radius-md);
  color: #ffffff;
  font-family: var(--font-primary);
  font-size: var(--font-size-body1);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration-normal) var(--easing);
}

.settings-save-btn:hover {
  filter: brightness(1.08);
  box-shadow: 0 0 14px var(--accent-glow);
}

.settings-save-btn:active {
  transform: scale(0.98);
}

.settings-save-btn--compact {
  flex: 0 0 auto;
  padding: 0 var(--space-16);
}

.settings-clear-btn {
  flex: 1;
  padding: var(--space-12);
  background: var(--error-subtle);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--error);
  font-family: var(--font-primary);
  font-size: var(--font-size-body2);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration-normal) var(--easing);
}

.settings-clear-btn:hover {
  border-color: var(--error);
}

.settings-clear-btn--icon {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-12);
}

.settings-clear-btn--icon .icon {
  width: 15px;
  height: 15px;
}

.settings-inline-row {
  display: flex;
  gap: var(--space-8);
  margin-bottom: var(--space-12);
}

.settings-templates-list {
  margin-bottom: var(--space-8);
}

.settings-template-row {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin-bottom: var(--space-8);
}

.settings-version {
  text-align: center;
  margin-top: var(--space-20);
  font-size: var(--font-size-caption);
  color: var(--text-muted);
}

.visually-hidden-file {
  position: fixed;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  padding: 0;
  margin: -1px;
}

/* ========================================
   Theme Toggle - segmented
   ======================================== */
.theme-toggle {
  display: flex;
  gap: var(--space-4);
  background: var(--bg-input);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.theme-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  padding: var(--space-12);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: var(--font-size-body2);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-normal) var(--easing);
}

.theme-option:hover {
  color: var(--text-primary);
  background: var(--accent-subtle);
}

.theme-option.active {
  background: var(--accent-gradient);
  color: #ffffff;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.theme-option-icon .icon {
  width: 16px;
  height: 16px;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 480px) {
  .card {
    margin: 14px clamp(12px, 4.8vw, 20px);
    padding: 18px;
    border-radius: 18px;
  }

  .input-row,
  .templates-row { gap: 10px; }

  .active-event-line { gap: 10px; }
  .active-event-elapsed { font-size: var(--font-size-body1); }
  .logo-image { width: 36px; height: 36px; }
  .logo h1 { font-size: 1.1rem; }
  #header { padding-inline: clamp(14px, 5vw, 20px); }
  .header-content { flex-wrap: wrap; row-gap: var(--space-4); }
  .header-actions { margin-left: auto; }

  .tasks-view-header {
    padding-bottom: 14px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--divider);
  }
  .pending-list { min-height: 0; gap: 10px; }
  .pending-item { border-radius: 14px; }
  .pending-item-content { padding: 12px 14px; }
  .empty-state { padding: 10px 0; }
  .app-footer { padding-top: 14px; }
}

/* Keep the fixed action target usable when the layout viewport is extremely narrow. */
@media (max-width: 360px) {
  .active-event-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--action-button-size);
    align-items: center;
  }

  .active-event-title,
  .active-event-elapsed {
    grid-column: 1;
  }

  .active-event-title { grid-row: 1; }
  .active-event-elapsed { grid-row: 2; }
  .active-stop-btn { grid-column: 2; grid-row: 1 / span 2; }
  .pulse-dot { display: none; }
}

/* ========================================
   Scrollbar - minimal
   ======================================== */
::-webkit-scrollbar {
  width: 3px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: var(--radius-full);
}

/* ========================================
   Empty state
   ======================================== */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: var(--font-size-body2);
  padding: var(--space-24);
}
/* Keyboard focus must remain visible across every control. */
:focus-visible, :focus { outline: 3px solid var(--accent, #5b5fc7) !important; outline-offset: 2px; }

.batch-sync-btn { display: inline-flex; align-items: center; justify-content: center; width: var(--action-button-size); height: var(--action-button-size); min-width: var(--action-button-size); min-height: var(--action-button-size); padding: 0; margin: 0; border-radius: 12px; border: none; background: var(--accent-gradient); box-shadow: var(--shadow-sm); color: #fff; font-family: var(--font-primary); font-weight: 700; cursor: pointer; transition: all var(--duration-normal) var(--easing); }
.batch-sync-btn > .icon { width: 22px; height: 22px; }
.batch-sync-btn:not(:disabled):hover { filter: brightness(1.08); box-shadow: 0 0 14px var(--accent-glow); }
.batch-sync-btn:disabled { opacity: .4; cursor: not-allowed; filter: none; box-shadow: none; }
.batch-result { padding: .75rem; margin-bottom: .75rem; border-radius: 10px; background: var(--bg-card); color: var(--text-primary, #fff); }
.pending-item { margin-bottom: .65rem; border: 1px solid var(--border-color); border-radius: 12px; background: var(--bg-card); overflow: hidden; }
.pending-item-swipe { position: relative; overflow: hidden; }
.pending-item-content {
  position: relative; z-index: 1; display: flex; align-items: baseline; gap: .5rem;
  padding: .85rem 1rem; background: var(--bg-card); touch-action: pan-y; user-select: none;
  overflow: hidden; white-space: nowrap;
}
.pending-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pending-sub { flex: 0 0 auto; display: flex; gap: .5rem; }
.pending-time, .pending-meta { color: var(--text-secondary); font-size: .86rem; white-space: nowrap; }
.pending-error { display: block; color: var(--error); font-size: .86rem; padding: 0 1rem .6rem; }
.pending-item-actions { position: absolute; top: 0; right: 0; bottom: 0; display: flex; z-index: 2; visibility: hidden; pointer-events: none; }
.pending-item.is-open .pending-item-actions,
.pending-item.is-swiping .pending-item-actions { visibility: visible; pointer-events: auto; }
.pending-item-actions button { min-width: 64px; min-height: 44px; padding: .45rem .8rem; border: 0; background: var(--error, #b42318); color: #fff; cursor: pointer; }
.pending-item-actions button[data-action="edit"] { background: var(--accent, #5b5fc7); }
.pending-item-actions button:disabled { opacity: .5; cursor: not-allowed; }
.pending-item-actions button:focus-visible, .batch-sync-btn:focus-visible { outline: 3px solid var(--accent, #5b5fc7); outline-offset: -3px; }
.pending-edit-modal { z-index: 20; }
#pending-edit-form { max-width: 34rem; }
#pending-edit-form .settings-label { margin-top: .8rem; }
#pending-edit-form .settings-input { width: 100%; box-sizing: border-box; }
#pending-edit-error { min-height: 1.4em; margin: .75rem 0; }
@media (max-width: 480px) { #pending-edit-form { width: calc(100% - 1.5rem); max-height: 90vh; overflow: auto; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; } }

/* Pending queue on the main screen */
.tasks-view { scroll-margin-top: 72px; }
.tasks-view-header h2 { font-size: var(--font-size-body1); font-weight: 600; }
.pending-list { min-height: 0; }
.pending-item-content { cursor: pointer; touch-action: pan-y; user-select: none; }
.pending-item-content:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
#pending-detail-body { display: grid; gap: .65rem; }
#pending-detail-body p { line-height: 1.45; overflow-wrap: anywhere; }
#pending-heading:focus { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }

/* Final compact geometry for the narrow target layouts. */
@media (max-width: 480px) {
  .templates-row .templates-select { margin-bottom: 0; }
  .templates-card { padding-block: 14px; }
  .tasks-sync-bar { padding-bottom: 0; }
  .tasks-view-header { padding-bottom: 10px; margin-bottom: 12px; }
  .pending-list { gap: 8px; }
  .pending-item { margin-bottom: 0; }
  .tasks-view .pending-item-content { padding: 8px 14px; }
}
