:root {
  --bg-primary: #0d0f12;
  --bg-elevated: #161a20;
  --bg-card: #1c2128;
  --bg-card-hover: #232a33;
  --bg-card-active: #2a323d;
  --border: #262c34;
  --border-strong: #3a414c;
  --text-primary: #e6e9ef;
  --text-secondary: #9aa3b1;
  --text-tertiary: #6b7280;
  --text-dim: #4b5360;
  --accent-primary: #4ade80;
  --accent-warning: #fbbf24;
  --accent-danger: #f87171;
  --accent-info: #60a5fa;
  --selection: #1f3a2a;
  --mono: "JetBrains Mono", "SF Mono", "Menlo", "Consolas", ui-monospace, monospace;
  --sans: "Inter", -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tap: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#root {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 540px;
  margin: 0 auto;
  position: relative;
}

/* HEADER */
.app-header {
  height: calc(52px + var(--safe-top));
  padding: var(--safe-top) 12px 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.app-header__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
}
.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-primary);
  box-shadow: 0 0 8px var(--accent-primary);
  display: inline-block;
}
.brand-text {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--text-primary);
  font-weight: 500;
}
.app-header__actions {
  display: flex;
  gap: 4px;
}
.icon-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 18px;
  transition: background-color .12s ease, color .12s ease;
}
.icon-btn:hover, .icon-btn:focus-visible {
  background: var(--bg-elevated);
  color: var(--text-primary);
  outline: none;
}
.icon-btn--danger:hover, .icon-btn--danger:focus-visible {
  color: var(--accent-danger);
}

/* VIEW */
.view {
  flex: 1;
  padding: 12px;
  padding-bottom: calc(80px + var(--safe-bottom));
}

/* INDICATOR ROW */
.row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "title badge"
    "meta meta";
  gap: 4px 8px;
  min-height: 56px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.row:hover, .row:focus-visible {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
  outline: none;
}
.row:active { background: var(--bg-card-active); }
.row__title {
  grid-area: title;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row__meta {
  grid-area: meta;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-tertiary);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.row__meta .id {
  color: var(--text-dim);
}
.row__badge {
  grid-area: badge;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent-primary);
  background: rgba(74, 222, 128, 0.08);
  border: 1px solid rgba(74, 222, 128, 0.25);
  border-radius: 4px;
  padding: 2px 6px;
  align-self: start;
  white-space: nowrap;
}

/* SKELETON */
.skel {
  display: block;
  background: linear-gradient(90deg, var(--bg-elevated) 0%, var(--bg-card) 50%, var(--bg-elevated) 100%);
  background-size: 200% 100%;
  animation: skel-pulse 1.4s ease-in-out infinite;
  border-radius: 6px;
  height: 56px;
  margin-bottom: 6px;
  font-family: var(--mono);
}
@keyframes skel-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* EMPTY / ERROR */
.empty, .error-banner {
  padding: 32px 20px;
  text-align: center;
}
.empty-text {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-tertiary);
  margin-bottom: 16px;
}
.error-banner {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 8px;
  color: var(--accent-danger);
  font-family: var(--mono);
  font-size: 12px;
  text-align: left;
  margin-bottom: 12px;
}
.error-banner__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.error-banner__msg { flex: 1; word-break: break-word; }
.error-banner__retry {
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 10px;
  border: 1px solid var(--accent-danger);
  border-radius: 4px;
  color: var(--accent-danger);
  background: transparent;
  min-height: 32px;
  min-width: 64px;
}
.error-banner__retry:hover { background: rgba(248, 113, 113, 0.12); }

/* DETAIL SHEET */
.detail {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.detail__head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
}
.back-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text-secondary);
}
.back-btn:hover, .back-btn:focus-visible {
  background: var(--bg-elevated);
  color: var(--text-primary);
  outline: none;
}
.detail__title {
  flex: 1;
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* PRE BLOCK */
.pre-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.pre-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-tertiary);
}
.pre-head__label {
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.pre-head__badge {
  background: rgba(74, 222, 128, 0.08);
  border: 1px solid rgba(74, 222, 128, 0.25);
  color: var(--accent-primary);
  padding: 2px 6px;
  border-radius: 4px;
}
.pre {
  margin: 0;
  padding: 12px;
  max-height: calc(100vh - 280px);
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-primary);
  white-space: pre;
  word-break: normal;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* ACTION BUTTONS */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}
.btn {
  min-height: var(--tap);
  padding: 0 12px;
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background-color .12s ease, border-color .12s ease;
}
.btn:hover, .btn:focus-visible {
  background: var(--bg-card-hover);
  border-color: var(--text-tertiary);
  outline: none;
}
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--accent-primary);
  color: #062a14;
  border-color: var(--accent-primary);
  font-weight: 600;
}
.btn--primary:hover, .btn--primary:focus-visible {
  background: #5cf096;
  border-color: #5cf096;
}
.btn--ghost {
  background: transparent;
  border-color: var(--border);
}
.btn--full { width: 100%; }

/* SNAPSHOTS TREE */
.tree {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.tree__head {
  width: 100%;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-secondary);
  min-height: var(--tap);
  text-align: left;
}
.tree__head:hover, .tree__head:focus-visible {
  background: var(--bg-card-hover);
  outline: none;
}
.tree__count {
  color: var(--text-tertiary);
}
.tree__caret {
  margin-right: 6px;
  font-family: var(--mono);
  color: var(--text-tertiary);
  display: inline-block;
  width: 12px;
}
.tree__list {
  border-top: 1px solid var(--border);
  display: none;
  max-height: 240px;
  overflow: auto;
}
.tree.open .tree__list { display: block; }
.tree-item {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-secondary);
  min-height: var(--tap);
}
.tree-item:last-child { border-bottom: none; }
.tree-item:hover, .tree-item:focus-visible {
  background: var(--bg-card-hover);
  outline: none;
}
.tree-item__marker {
  color: var(--accent-primary);
  font-size: 14px;
  text-align: center;
}
.tree-item__marker.old { color: var(--text-dim); }
.tree-item__hash {
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-item__date {
  color: var(--text-tertiary);
  white-space: nowrap;
}
.tree-item__size {
  color: var(--text-dim);
  font-size: 10px;
  margin-left: 8px;
}

/* EDIT FORM */
.edit {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.edit__label {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
}
.edit__area {
  width: 100%;
  min-height: calc(var(--tap) * 2);
  padding: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-primary);
  resize: vertical;
  line-height: 1.45;
}
.edit__area:focus { outline: 2px solid var(--accent-primary); outline-offset: -1px; border-color: var(--accent-primary); }
.edit__actions { display: flex; gap: 6px; }

/* FAB */
.fab {
  position: fixed;
  left: 50%;
  bottom: calc(12px + var(--safe-bottom));
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: calc(540px - 24px);
  min-height: var(--tap);
  padding: 0 16px;
  background: var(--accent-primary);
  color: #062a14;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
  z-index: 40;
}
.fab:active { transform: translateX(-50%) translateY(1px); }
.fab[hidden] { display: none; }

/* TOAST */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: var(--mono);
  font-size: 12px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  max-width: calc(100% - 24px);
}
.toast[hidden] { display: none; }
.toast__ok {
  font-family: var(--sans);
  font-size: 12px;
  padding: 6px 12px;
  background: var(--accent-primary);
  color: #062a14;
  border-radius: 4px;
  font-weight: 600;
  min-height: 32px;
}

/* FOCUS RING */
button:focus-visible, .row:focus-visible, .tree-item:focus-visible, .edit__area:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

::selection { background: var(--selection); }

/* SCROLLBAR (Webkit) */
.pre::-webkit-scrollbar, .tree__list::-webkit-scrollbar { width: 8px; height: 8px; }
.pre::-webkit-scrollbar-thumb, .tree__list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.pre::-webkit-scrollbar-track, .tree__list::-webkit-scrollbar-track { background: var(--bg-elevated); }
