:root {
  --bg: #0f172a;
  --bg-elev: #1e293b;
  --bg-elev-2: #334155;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --accent: #fbbf24;
  --accent-dim: #78350f;
  --success: #22c55e;
  --danger: #ef4444;
  --border: #334155;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header / Balance ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(var(--safe-top) + 16px) 20px 16px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg) 70%, rgba(15, 23, 42, 0.95) 100%);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.balance {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.balance__icon {
  font-size: 28px;
  align-self: center;
}

.balance__value {
  font-size: 40px;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  transition: transform 0.2s ease;
}

.balance__value.bump-up {
  animation: bump-up 0.4s ease;
}

.balance__value.bump-down {
  animation: bump-down 0.4s ease;
}

@keyframes bump-up {
  0% { transform: scale(1); color: var(--accent); }
  40% { transform: scale(1.2); color: var(--success); }
  100% { transform: scale(1); color: var(--accent); }
}

@keyframes bump-down {
  0% { transform: scale(1); color: var(--accent); }
  40% { transform: scale(0.85); color: var(--danger); }
  100% { transform: scale(1); color: var(--accent); }
}

.balance__label {
  font-size: 16px;
  color: var(--text-dim);
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  padding: 0 16px;
  gap: 8px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}

.tab {
  flex: 1;
  padding: 14px 16px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
  font-family: inherit;
}

.tab--active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ===== Content ===== */
.content {
  flex: 1;
  padding: 20px 16px calc(var(--safe-bottom) + 24px);
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.panel {
  display: none;
}

.panel--active {
  display: block;
}

/* ===== Add form ===== */
.add-form {
  display: grid;
  grid-template-columns: 1fr 90px 48px;
  gap: 8px;
  margin-bottom: 20px;
}

.add-form input {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  min-width: 0;
}

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

.add-form input::placeholder {
  color: var(--text-dim);
}

.add-form__cost {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Remove number spinner for cleaner mobile look */
.add-form__cost::-webkit-outer-spin-button,
.add-form__cost::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.add-form__cost {
  -moz-appearance: textfield;
}

.add-form__submit {
  background: var(--accent);
  color: #1a1a1a;
  border: none;
  border-radius: var(--radius);
  font-size: 28px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: transform 0.1s ease, background 0.15s ease;
}

.add-form__submit:active {
  transform: scale(0.94);
  background: #f59e0b;
}

/* ===== List ===== */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item {
  background: var(--bg-elev);
  border-radius: var(--radius);
  padding: 14px 14px 14px 6px;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  grid-template-rows: auto auto;
  grid-template-areas:
    "handle name action"
    "handle cost action";
  column-gap: 8px;
  row-gap: 4px;
  border: 1px solid transparent;
  transition: opacity 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  will-change: transform;
}

.item--removing {
  opacity: 0;
  transform: translateX(20px);
}

.item--dragging {
  transition: none !important;
  z-index: 10;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  border-color: var(--accent);
}

.item__handle {
  grid-area: handle;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  letter-spacing: -3px;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  font-family: inherit;
  padding: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.item__handle:active {
  cursor: grabbing;
  color: var(--accent);
}

.item__name {
  grid-area: name;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.item__cost {
  grid-area: cost;
  font-size: 14px;
  color: var(--accent);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 4px;
}

.item__cost::before {
  content: "🪙";
  font-size: 14px;
}

.item__actions {
  grid-area: action;
  display: flex;
  align-items: center;
  gap: 6px;
}

.item__btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s ease, background 0.15s ease, opacity 0.15s ease;
  min-height: 40px;
  white-space: nowrap;
}

.item__btn:active:not(:disabled) {
  transform: scale(0.94);
}

.item__btn--do {
  background: var(--success);
  color: #0a2a14;
}

.item__btn--use {
  background: var(--accent);
  color: #1a1a1a;
}

.item__btn--use:disabled {
  background: var(--bg-elev-2);
  color: var(--text-dim);
  cursor: not-allowed;
  opacity: 0.6;
}

.item__btn--delete {
  background: transparent;
  color: var(--text-dim);
  padding: 8px 10px;
  font-size: 18px;
  line-height: 1;
}

.item__btn--delete:active {
  color: var(--danger);
}

/* ===== Footer ===== */
.app-footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px calc(var(--safe-bottom) + 16px);
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.footer-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.footer-btn:active {
  transform: scale(0.96);
  color: var(--accent);
  border-color: var(--accent);
}

/* ===== History ===== */
.history-group {
  margin-bottom: 24px;
}

.history-group__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.history-group__date {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.history-group__total {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

.history-group__total--positive { color: var(--success); }
.history-group__total--negative { color: var(--danger); }

.history-entries {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-entry {
  background: var(--bg-elev);
  border-radius: 10px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 12px;
}

.history-entry__time {
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.history-entry__name {
  font-size: 15px;
  color: var(--text);
  word-break: break-word;
  min-width: 0;
}

.history-entry__name--reward {
  color: var(--text-dim);
}

.history-entry__delta {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.history-entry__delta--positive { color: var(--success); }
.history-entry__delta--negative { color: var(--danger); }

/* ===== Empty state ===== */
.empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 15px;
  margin: 40px 16px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 24px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev-2);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: calc(100vw - 32px);
  text-align: center;
}

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

.toast--success {
  background: var(--success);
  color: #0a2a14;
}

.toast--error {
  background: var(--danger);
  color: #2a0a0a;
}

/* ===== Responsive: tablet/desktop ===== */
@media (min-width: 600px) {
  .balance__value {
    font-size: 48px;
  }

  .item__btn {
    padding: 10px 18px;
  }
}
