/* ── 1. DESIGN SYSTEM VARIABLES & FOUNDATIONS ────────────────────────── */
:root {
  --size-md: 1rem;
  --radius: 0.75rem;
  --bg: #0a0806;
  --section: #14120f;
  --border: #2e2822;
  --border-dim: #201c1a;
  --gold: #be9d43;
  --gold-dim: #7a622a;
  --success: #4a7c4e;
  --success-dim: #1a2c1c;
  --error: #e8622a;
  --error-dim: #62331f;
  --text: #d4c9b8;
  --text-dim: #7a6e60;
  --text-faint: #4a4038;
  --font-serif: "Crimson Text", Georgia, serif;
  --font-display: "Cinzel", serif;
  --tf: 0.15s;
  --tb: 0.2s;
  --ts: 0.35s;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 1rem;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
  background-color: var(--bg);
}

body {
  font-family: var(--font-serif);
  background: var(--bg);
  color: var(--text);
  padding-top: 0;
  overflow-x: hidden;
  min-height: 100%;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 30rem;
  margin: 0 auto;
  background: var(--bg);
  min-height: 100dvh;
  padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px) + 1.75rem);
}

/* ── 2. GLOBAL LAYOUT COMPONENTS ────────────────────────────────────── */
.view {
  display: none;
}

.view.active {
  display: block;
}

.view-header {
  position: sticky;
  top: 0;
  z-index: 101;
  background: linear-gradient(to bottom, var(--bg) 0%, var(--bg) 80%, rgba(10, 8, 6, 0) 100%);
  padding: calc(1rem + env(safe-area-inset-top, 0px)) var(--size-md) 1.5rem;

  h1 {
    text-align: justify;
    font-family: var(--font-display);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gold-dim);
    margin-bottom: .5rem;
  }
}

.view-meta {
  height: 3.5rem;
  display: flex;
  align-items: center;
  background-color: var(--section);
  border-radius: var(--radius);
  padding: 1rem var(--size-md);
  border: 1px solid var(--text-faint);
}

#economy-meta-root {
  height: auto;
  flex-direction: column;
  gap: 0.5rem;
}

.view-content {
  padding: 0.25rem var(--size-md) 2rem;
}

.btn {
  padding: 0.4rem var(--size-md);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  background: transparent;
  color: var(--gold);
  font-family: var(--font-display);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background var(--tb);
  white-space: nowrap;
}

.btn:active {
  background: var(--gold-dim);
}

.reset-bar {
  display: flex;
  justify-content: center;
  margin-top: 2rem;
}

.btn-negative {
  border-color: var(--error-dim);
  color: var(--text-dim);
  font-size: 0.75rem;
}

.btn-negative:active {
  background: var(--error-dim);
  border-color: var(--error);
  color: var(--text);
}

/* ── 3. REUSABLE ATOMS (SECTIONS & CONTAINER ROWS) ──────────────────── */
.section {
  margin-bottom: 1rem;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--section);
  border: 1px solid var(--border);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem var(--size-md);
  cursor: pointer;
  user-select: none;
  transition: background var(--tb);
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.section-header:active {
  background: var(--border);
}

.section.open .section-header {
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gold-dim);
  flex: 1;
  transition: color var(--tb);
}

.section-badge {
  font-family: var(--font-display);
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
  margin-right: 0.25rem;
}

.section-chevron {
  font-size: 1rem;
  color: var(--text-faint);
  transition: transform var(--ts);
  flex-shrink: 0;
  line-height: 1;
}

.section.open .section-chevron {
  transform: rotate(180deg);
}

.section.open .section-title {
  color: var(--gold);
}

.section-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--ts) var(--ease);
}

.section.open .section-content {
  max-height: 100rem;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 3rem;
  padding: 0 var(--size-md);
  cursor: pointer;
  user-select: none;
  transition: background var(--tf);
  border-bottom: 1px solid var(--border-dim);
}

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

.item-row:active {
  background: var(--border);
}

.item-label {
  font-size: 1rem;
  color: var(--text);
  flex: 1;
  transition: color var(--tb), opacity var(--tb);
}

/* ── 4. PROGRESS VIEW FUNCTIONAL SYSTEM ─────────────────────────────── */
.view-meta .progress-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.progress-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.25rem;
  gap: 0.5rem;
}

.progress-pct {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gold);
  line-height: 1;
}

.progress-counts {
  font-family: var(--font-display);
  font-size: 0.6875rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

.progress-track {
  height: 0.25rem;
  background: var(--border);
  border-radius: 0.125rem;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold));
  border-radius: 0.125rem;
  transition: width 0.5s var(--ease);
  box-shadow: 0 0 0.5rem var(--gold-dim);
}

.check-box {
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
  border: 0.125rem solid var(--border);
  border-radius: 0.5rem;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--tb), background var(--tb), box-shadow var(--tb);
}

.check-box svg {
  opacity: 0;
  transform: scale(0.5);
  transition: opacity var(--tb), transform var(--tb);
}

.item-row.checked .check-box {
  border-color: var(--success);
  background: var(--success-dim);
}

.item-row.checked .check-box svg {
  opacity: 1;
  transform: scale(1);
}

.item-row.checked .check-box svg path {
  stroke: var(--success) !important;
}

.item-row.checked .item-label {
  color: var(--text-dim);
  opacity: 0.6;
  text-decoration-color: var(--text-faint);
}

/* ── 5. GOALS VIEW FUNCTIONAL SYSTEM ────────────────────────────────── */
.view-meta .goals-add {
  width: 100%;
  display: flex;
  gap: 0.5rem;
}

.goals-input {
  flex: 1;
  background: transparent;
  border: 0;
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--text);
  outline: none;
}

#goal-add-btn {
  display: none;
}

.goals-input::placeholder {
  color: var(--text-faint);
}

.goal-del {
  font-size: 1.25rem;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  transition: color var(--tf);
  user-select: none;
}

.goal-del:active {
  color: var(--error);
}

.goals-empty {
  padding: var(--size-md);
  color: var(--text-dim);
  font-size: 0.9375rem;
}

/* ── 6. ECONOMY VIEW FUNCTIONAL SYSTEM ──────────────────────────────── */
.view-meta .eco-search-wrap {
  width: 100%;
  position: relative;
}

.view-meta .eco-search-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

.eco-search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--text);
}

.eco-search-input::placeholder {
  color: var(--text-faint);
}

.eco-search-clear {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 var(--size-md) 0 0.25rem;
  display: none;
}

.eco-search-clear.visible {
  display: block;
}

.eco-search-results {
  background: var(--border-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 1rem;
  display: none;
  max-height: 50vh;
  overflow-y: auto;
}

.eco-search-results.visible {
  display: block;
}

.eco-search-results .eco-search-result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem var(--size-md);
  border-bottom: 1px solid var(--border);
}

.eco-search-result-row:last-child {
  border-bottom: none;
}

.eco-sr-name {
  flex: 1;
  font-size: 0.9375rem;
  color: var(--text);
}

.eco-sr-cat {
  font-family: var(--font-display);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  color: var(--text-faint);
  text-transform: uppercase;
  white-space: nowrap;
}

.eco-search-results .eco-item-meta {
  flex: 1;
}

.eco-item-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.eco-icon-frame {
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 0.25rem;
  border: 1px solid rgba(46, 40, 34, 0.4);
  flex-shrink: 0;
}

.eco-icon {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.eco-name {
  font-size: 0.9375rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.eco-val {
  font-family: var(--font-display);
  font-size: 0.875rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  padding-left: 0.5rem;
}

.eco-val b {
  font-weight: normal;
  opacity: 0.6;
  font-family: var(--font-serif);
}

.eco-search-empty {
  padding: var(--size-md);
  color: var(--text-faint);
  font-style: italic;
  font-size: 0.9375rem;
  text-align: center;
}

.eco-filter-wrap {
  width: 100%;
  margin-top: 0.5rem;
}

.eco-category-select {
  width: 100%;
  height: 2.75rem;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1rem;
  padding: 0 var(--size-md);
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%237a6e60' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'></polyline></svg>");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1.15rem;
}

.eco-category-select:focus {
  border-color: var(--gold-dim);
}

.eco-list-container {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--section);
  border: 1px solid var(--border);
}

.item-row.structural-row {
  cursor: default;
  user-select: text;
}

.item-row.structural-row:active {
  background: transparent;
}

/* ── 6.1 ECONOMY SKELETON LOADERS (REPLACED INLINE STYLES) ───────────── */
.eco-skel-row {
  opacity: 0.15;
}

.eco-skel-container {
  display: flex;
  gap: 0rem;
}

.eco-skel-icon {
  width: 1.75rem;
  height: 1.75rem;
  background: var(--text-faint);
  border-radius: 0.25rem;
}

.eco-skel-label {
  width: 9rem;
  height: 0.8rem;
  background: var(--text-faint);
  border-radius: 0.125rem;
}

.eco-skel-badge {
  width: 3rem;
  height: 0.8rem;
  background: var(--text-faint);
  border-radius: 0.125rem;
}

/* ── 6.2 SYNC / PULL TO REFRESH DRAG INTERFACE ────────────────────────── */
#view-economy {
  position: relative;
}

.ptr-element {
  width: 100%;
  height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: height 0.2s var(--ease), transform 0.1s linear;
}

.ptr-arrow {
  font-size: 1.25rem;
  transition: transform 0.2s ease;
  color: var(--text-faint);
}

.ptr-ready .ptr-arrow {
  transform: rotate(180deg);
  color: var(--gold);
}

.ptr-spinner {
  font-size: 1.5rem;
  color: var(--gold);
  padding: 0.5rem;
}

.spinning {
  animation: eco-spin 0.8s linear infinite;
}

@keyframes eco-spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* ── 7. SYSTEM MESSAGES & SHELL NAVIGATION CONTROLS ──────────────────── */
.toast {
  position: fixed;
  bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translate(-50%, 1rem);
  background: #1c1917;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s var(--ease);
  z-index: 999;
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.6);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.saving {
  border-color: var(--gold-dim);
  color: var(--gold);
}

.toast.saved {
  border-color: var(--success-dim);
  color: var(--success);
  ;
}

.toast.error {
  border-color: var(--error-dim);
  color: var(--error);
}

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: var(--section);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  z-index: 500;
  box-shadow: 0 0 3.5rem .5rem rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  gap: .5rem;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  padding: 1rem 1.5rem;
  transition: color var(--tf) var(--ease);
}

.tab-icon {
  color: var(--text-dim);
  width: 1.5rem;
  height: 1.5rem;
  transition: transform var(--tf) var(--ease);
}

.tab-btn.active .tab-icon {
  color: var(--gold);
}

.tab-label {
  font-family: var(--font-display);
  font-size: 0.4rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.tab-btn.active {
  color: var(--text-dim);
}

.view-panel {
  display: none;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity var(--ts) var(--ease), transform var(--ts) var(--ease);
}

.view-panel.active {
  display: block;
  animation: tabFadeIn var(--ts) var(--ease) forwards;
}

@keyframes tabFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── 8. SYSTEM OVERRIDES & ACCESSIBILITY ─────────────────────────────── */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}