:root {
  color-scheme: dark;
  --bg: #060d07;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-solid: #1c2b23;
  --surface-2: rgba(255, 255, 255, 0.08);
  --text: #eef3ef;
  --text-dim: #8fa39a;
  --accent: #4fd393;
  --accent-ink: #082016;
  --era: #f0a960;
  --zsozs: #4fd393;
  --danger: #e5626b;
  --border: rgba(255, 255, 255, 0.09);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background-color: #060d07;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button { cursor: pointer; font-family: inherit; }
button:active { transform: scale(0.96); }

.glass {
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border);
}

.username-field {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-dim);
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0;
  margin-top: -2px;
}
.username-field::placeholder { color: var(--text-dim); }

.ptr-indicator {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  left: 50%;
  transform: translate(-50%, -70px);
  opacity: 0;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 50;
  transition: transform 0.2s ease, opacity 0.2s ease;
  pointer-events: none;
}
.ptr-indicator.ready { color: var(--accent); border-color: var(--accent); }

.screen {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex;
  flex-direction: column;
}

/* Login */
#login-screen {
  align-items: center;
  justify-content: center;
}
#login-form {
  width: 100%;
  max-width: 320px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  align-items: center;
}
.login-badge {
  width: 60px;
  height: 60px;
  border-radius: 20px;
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border);
  color: var(--accent);
  font-weight: 800;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
  box-shadow: 0 0 40px -8px rgba(79, 211, 147, 0.35);
}
#login-form h1, #setup-form h1 { margin: 0 0 8px; font-size: 1.4rem; }
.hint { color: var(--text-dim); margin: 0 0 8px; }

.user-picker {
  display: flex;
  gap: 8px;
  width: 100%;
  margin-bottom: 4px;
}
.user-btn {
  flex: 1;
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 16px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.user-btn.active {
  border-color: var(--accent);
  color: var(--text);
  background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--accent) inset, 0 0 24px -6px rgba(79, 211, 147, 0.5);
}

#login-form input, #setup-form input {
  width: 100%;
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 16px;
  padding: 14px;
  font-size: 1rem;
}
#login-form button[type="submit"], #setup-form button[type="submit"] {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 999px;
  padding: 15px;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 0 0 1px rgba(79,211,147,0.4), 0 10px 30px -8px rgba(79, 211, 147, 0.6);
}
.error { color: var(--danger); font-size: 0.9rem; margin: 4px 0 0; }
.success { color: var(--accent); font-size: 0.95rem; margin: 4px 0 0; }

/* App */
header {
  padding: 14px 16px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
header h1 { margin: 0; font-size: 1.25rem; flex: 1; letter-spacing: -0.01em; }
header button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.3rem;
  padding: 4px 8px;
}

.app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
}

.balance-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0 24px;
  text-align: center;
  min-height: 0;
}
.balance-line1 {
  margin: 0;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.4;
}
.balance-line2 {
  margin: 8px 0 0;
  color: var(--accent);
  font-size: 2.3rem;
  font-weight: 800;
  line-height: 1.1;
}

.entry-form-wrap {
  flex: 0 0 auto;
  padding: 0 16px 16px;
}

#add-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.amount-input {
  background: var(--surface);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 20px;
  padding: 22px 16px;
  font-size: 1.8rem;
  font-weight: 700;
  text-align: center;
  width: 100%;
}
.amount-input::placeholder { color: var(--text-dim); font-weight: 700; }

.note-input {
  background: var(--surface);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 16px;
  padding: 14px;
  font-size: 1rem;
  text-align: center;
  width: 100%;
}

.split-picker {
  display: flex;
  gap: 8px;
}
.split-btn {
  flex: 1;
  background: var(--surface);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 14px;
  padding: 13px;
  font-size: 0.9rem;
  font-weight: 600;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.split-btn.active {
  border-color: var(--accent);
  color: var(--text);
  background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--accent) inset, 0 0 24px -6px rgba(79, 211, 147, 0.5);
}

.bottom-bar {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 0 16px calc(12px + env(safe-area-inset-bottom));
  padding: 8px;
  background: var(--surface);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border: 1px solid var(--border);
  border-radius: 30px;
  box-shadow: 0 16px 40px -16px rgba(0,0,0,0.65);
}

.secondary-btn {
  flex: none;
  width: 52px;
  aspect-ratio: 1 / 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.secondary-btn svg { width: 22px; height: 22px; }

.primary-btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 999px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
}
.primary-btn.btn-large {
  flex: 1;
  height: 52px;
  padding: 0;
  font-size: 1.08rem;
  box-shadow: 0 0 0 1px rgba(79,211,147,0.4), 0 10px 28px -8px rgba(79, 211, 147, 0.65);
}

#history-list {
  list-style: none;
  margin: 0;
  padding: 8px 12px 24px;
  flex: 1;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px 14px;
  margin-bottom: 8px;
  transition: opacity 0.2s ease;
}

.history-item.deleted,
.history-item.archived { opacity: 0.5; }
.history-item.deleted .history-note,
.history-item.deleted .history-amount,
.history-item.deleted .history-payer,
.history-item.archived .history-note,
.history-item.archived .history-amount,
.history-item.archived .history-payer {
  text-decoration: line-through;
  text-decoration-color: var(--text-dim);
}
.history-item.deleted .history-avatar,
.history-item.archived .history-avatar { filter: grayscale(1); }

.history-avatar {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--accent-ink);
}
.history-avatar.era { background: var(--era); }
.history-avatar.zsozs { background: var(--zsozs); }

.history-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.history-payer {
  font-weight: 700;
}
.history-payer.era { color: var(--era); }
.history-payer.zsozs { color: var(--zsozs); }

.history-amount {
  font-weight: 700;
  white-space: nowrap;
}

.history-note {
  color: var(--text);
  font-size: 0.95rem;
  word-break: break-word;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-dim);
  font-size: 0.78rem;
}

.history-delete,
.history-edit-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1rem;
  padding: 2px 6px;
}

.history-edit-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.history-edit-form input {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  width: 100%;
  color-scheme: dark;
}
.edit-error {
  color: var(--danger);
  font-size: 0.82rem;
  margin: 0;
}
.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.edit-save-btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  font-weight: 700;
  font-size: 0.85rem;
}
.edit-cancel-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 0.85rem;
}

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 32px;
}
