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

:root {
  --bg: #1a1a2e;
  --surface: #252542;
  --surface2: #2f2f4f;
  --text: #eaeaea;
  --text-muted: #9a9ab0;
  --accent: #6bcb77;
  --accent-dim: #4a9a54;
  --danger: #e74c6f;
  --border: #3a3a5c;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
}

#main {
  flex: 1;
  padding: 1.25rem;
}

.screen-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.screen-sub {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

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

.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.card-link:hover, .card-link:active {
  background: var(--surface2);
}

.card-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.card-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.match-badge {
  display: inline-block;
  background: var(--accent);
  color: #111;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-top: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.85rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-bottom: 0.5rem;
}

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

.btn-primary {
  background: var(--accent);
  color: #111;
}

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

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-sm {
  width: auto;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

.back-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.95rem;
  cursor: pointer;
  margin-bottom: 1rem;
  padding: 0;
}

.back-btn:hover {
  color: var(--text);
}

/* Signal list */
.signal-list {
  list-style: none;
}

.signal-item {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.signal-item:last-child {
  border-bottom: none;
}

.signal-toggle {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  font-size: 1.1rem;
  transition: all 0.15s;
}

.signal-toggle.active {
  border-color: var(--accent);
  background: rgba(107, 203, 119, 0.15);
  color: var(--accent);
}

.signal-label {
  font-size: 1rem;
}

.signal-match {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: transparent;
}

.signal-match.matched {
  color: var(--accent);
}

.match-banner {
  background: rgba(107, 203, 119, 0.12);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  text-align: center;
}

.match-banner h3 {
  color: var(--accent);
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.match-banner p {
  font-size: 1.1rem;
  font-weight: 500;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.input {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
}

.select {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.recovery-box {
  background: var(--surface2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: monospace;
  font-size: 0.85rem;
  word-break: break-all;
  margin: 1rem 0;
  line-height: 1.8;
}

.warning {
  background: rgba(231, 76, 111, 0.1);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  color: var(--danger);
  margin-bottom: 1rem;
}

.info {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.suggestion-chip {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.suggestion-chip:hover {
  border-color: var(--accent);
}

.suggestion-chip.used {
  opacity: 0.4;
  pointer-events: none;
}

.edit-signal-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.edit-signal-item input {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.25rem;
  opacity: 0.6;
}

.delete-btn:hover {
  opacity: 1;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 100;
  max-width: 90%;
  text-align: center;
}

.toast[hidden] {
  display: none;
}

.toast .undo {
  color: var(--accent);
  cursor: pointer;
  margin-left: 0.5rem;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}

.section-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 1.5rem 0 0.75rem;
}

.link-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.link-row .input {
  margin-bottom: 0;
  font-size: 0.85rem;
}

.duration-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.duration-row label {
  font-size: 0.9rem;
  white-space: nowrap;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.card-title-row .screen-title {
  margin-bottom: 0;
  flex: 1;
}

.title-row {
  margin-bottom: 0.5rem;
}

.title-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.settings-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.15rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

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

.settings-hint {
  margin-top: -0.75rem;
  margin-bottom: 1rem;
}

.rename-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  flex-shrink: 0;
}

.rename-btn:hover {
  color: var(--accent);
}

.pending-badge {
  display: inline-block;
  background: rgba(255, 193, 7, 0.2);
  color: #ffc107;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-top: 0.5rem;
}

.pending-banner {
  border-left: 3px solid #ffc107;
}

.tab-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab-btn {
  flex: 1;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
}

.tab-btn.active {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--accent);
}

.link-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.link-actions .btn {
  flex: 1;
  margin-bottom: 0;
}

.add-signal-box {
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.add-signal-box .input {
  margin-bottom: 0.75rem;
}

.add-signal-box .btn {
  margin-bottom: 0;
}

.signal-item.signal-changed {
  background: rgba(107, 203, 119, 0.08);
  border-radius: 8px;
}

.signal-hint {
  margin-top: -0.5rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.confirm-title {
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.confirm-change {
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.confirm-add {
  color: var(--accent);
}

.confirm-remove {
  color: var(--text-muted);
}

.confirm-duration {
  margin: 0.75rem 0;
}

.confirm-duration .select {
  margin-bottom: 0;
}

.signal-item.signal-pending {
  background: rgba(107, 203, 119, 0.08);
  border-radius: 8px;
}

.signal-toggle.pending {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(107, 203, 119, 0.3);
}

.confirm-bar {
  position: sticky;
  bottom: 0;
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1rem 0;
}

.confirm-bar p {
  margin-bottom: 0.75rem;
  font-weight: 500;
}

.confirm-actions {
  display: flex;
  gap: 0.5rem;
}

.confirm-actions .btn {
  flex: 1;
  margin-bottom: 0;
}

.copy-input {
  font-size: 0.8rem;
  user-select: all;
  -webkit-user-select: all;
}

@media (min-width: 481px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
