/* ── 1. DESIGN SYSTEM ────────────────────────────────────────────────── */
:root {
  --sp: 1rem;
  /* base spacing unit  */
  --sp-sm: 0.75rem;
  --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);
  overflow-x: hidden;
  min-height: 100%;
}

/* ── 2. LAYOUT ───────────────────────────────────────────────────────── */
.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);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

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

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

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

/* Views without a .view-header (e.g. Strategies, Guide) get the same
   top offset the header gives its own content, so the first card lines
   up with the meta box of the headed views instead of jumping up. */
.view.no-header .view-content {
  padding-top: calc(1rem + env(safe-area-inset-top, 0px));
}

/* ── 3. SHARED ATOMS ─────────────────────────────────────────────────── */
/* card = shared base for .section and .eco-list-container */
.card {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--section);
  border: 1px solid var(--border);
}

.section {
  composes: card;
  /* logical grouping — both get the card styles below */
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--section);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}

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

  &: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);
  flex-shrink: 0;
  line-height: 1;
  transition: transform var(--ts);
}

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

  .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 */
.item-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 3rem;
  padding: 0 var(--sp);
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border-dim);
  transition: background var(--tf);

  &:last-child {
    border-bottom: none;
  }

  &:active {
    background: var(--border);
  }
}

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

/* btn */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.4rem var(--sp);
  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;
  white-space: nowrap;
  transition: background var(--tb);

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

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

  &:active {
    background: var(--error-dim);
    border-color: var(--error);
    color: var(--text);
  }
}

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

/* ── 4. PROGRESS VIEW ────────────────────────────────────────────────── */
.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;
  box-shadow: 0 0 0.5rem var(--gold-dim);
  transition: width 0.5s var(--ease);
}

.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);

  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);

    svg {
      opacity: 1;
      transform: scale(1);

      path {
        stroke: var(--success) !important;
      }
    }
  }

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

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

.goals-input-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

  &::placeholder {
    color: var(--text-faint);
  }
}

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

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

  &:active {
    color: var(--error);
  }
}

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

/* ── 6. ECONOMY VIEW ─────────────────────────────────────────────────── */
#economy-meta-root {
  height: auto;
  padding: 0.5rem var(--sp);
}

.eco-search-wrap {
  width: 100%;
}

.eco-search-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

  &::placeholder {
    color: var(--text-faint);
  }
}

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

  &.visible {
    display: block;
  }
}

.eco-sentinel {
  height: 1px;
}

.eco-error {
  color: var(--error);
}

.eco-last-updated {
  color: var(--text-faint);
  font-style: italic;
  font-size: 0.9375rem;
}

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

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

.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;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 0.25rem;
  border: 1px solid var(--border);
}

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

.eco-name-block {
  display: flex;
  flex-direction: column;
}

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

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

.eco-val-icon {
  width: 1.125rem;
  height: 1.125rem;
  object-fit: contain;
  flex-shrink: 0;
}

/* ── 6.2 DIVINE VALUE & CALCULATOR ────────────────────────────────────── */
.eco-calc-card {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--section);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}

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

.eco-calc-card-title {
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gold-dim);
}

.eco-calc-reset {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) / 2);
  color: var(--text-dim);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color var(--tb), color var(--tb);

  &:active {
    color: var(--gold);
    border-color: var(--gold-dim);
  }
}

.eco-calc-fields {
  display: flex;
  gap: 0.625rem;
  padding: 1rem var(--sp);
}

.eco-calc-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.eco-calc-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-display);
  font-size: 0.625rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.eco-calc-icon {
  width: 1rem;
  height: 1rem;
  object-fit: contain;
  flex-shrink: 0;
}

.eco-calc-input {
  width: 100%;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) / 2);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1rem;
  padding: 0.5rem 0.5rem;
  outline: none;
  transition: border-color var(--tb);

  &:focus {
    border-color: var(--gold-dim);
  }

  &::placeholder {
    color: var(--text-faint);
  }

  /* hide native number spinner arrows for a cleaner look */
  &::-webkit-outer-spin-button,
  &::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }

  &[type="number"] {
    -moz-appearance: textfield;
  }
}

/* eco-list-container shares card styles with .section (no margin-bottom) */
.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;

  &:active {
    background: transparent;
  }
}

/* ── 6.1 PULL TO REFRESH ─────────────────────────────────────────────── */
#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;
  color: var(--text-faint);
  transition: transform 0.2s ease;
}

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

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

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

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── 7. STRATEGIES VIEW ──────────────────────────────────────────────── */
.strat-empty {
  padding: var(--sp);
  color: var(--text-dim);
}

.strat-grid {
  padding: 0.5rem var(--sp) 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.strat-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.55rem 0.5rem;
  border-radius: calc(var(--radius) / 2);
  transition: background var(--tb);

  &:hover {
    background: var(--border-dim);
  }
}

.strat-icon {
  font-size: 0.7rem;
  color: var(--gold-dim);
  flex-shrink: 0;
  padding-top: 0.3rem;
}

.strat-body {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}

.strat-label {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gold-dim);
  line-height: 1.2;
}

.strat-value {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.5;
}

.strat-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;

  li {
    font-family: var(--font-serif);
    font-size: 0.9rem;
    color: var(--text);
    line-height: 1.5;
    padding-left: 0.85rem;
    position: relative;

    &::before {
      content: "·";
      position: absolute;
      left: 0.1rem;
      color: var(--gold-dim);
      font-size: 1.1rem;
      line-height: 1.3;
    }
  }
}

/* ── 7. SHELL: TOAST & TABS ──────────────────────────────────────────── */
.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;
  z-index: 999;
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.6);
  transition: opacity 0.25s ease, transform 0.25s var(--ease);

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

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

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

  &.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;
  gap: 0.5rem;
  z-index: 500;
  box-shadow: 0 0 3.5rem 0.5rem rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.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;
  padding: 1rem 0;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--tf) var(--ease);

  &.active {
    color: var(--text-dim);

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

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

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

/* ── 7.1 PRELOADER ───────────────────────────────────────────────────── */
.preloader {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--bg);
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.preloader-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: 0 0 1.5rem var(--gold-dim);
  text-align: center;
}

.preloader-league {
  font-family: var(--font-display);
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: -1rem;
  min-height: 1em;
  text-align: center;
}

.preloader-bar {
  margin-top: .5rem;
  width: 8rem;
  height: 0.1875rem;
  background: var(--border);
  border-radius: 0.125rem;
  overflow: hidden;
}

.preloader-bar-fill {
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold));
  border-radius: 0.125rem;
  animation: preloader-slide 1.1s ease-in-out infinite;
}

@keyframes preloader-slide {
  0% {
    transform: translateX(-120%);
  }

  100% {
    transform: translateX(350%);
  }
}

.preloader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ── 7.2 SKELETONS ───────────────────────────────────────────────────── */
@keyframes skel-pulse {

  0%,
  100% {
    opacity: 0.5;
  }

  50% {
    opacity: 1;
  }
}

.skel {
  background: var(--border-dim);
  border-radius: 0.25rem;
  animation: skel-pulse 1.3s ease-in-out infinite;
}

.skel-section {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--section);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}

.skel-section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem var(--sp);
}

.skel-title {
  width: 40%;
  height: 0.75rem;
}

.skel-badge {
  width: 2.5rem;
  height: 0.7rem;
  margin-left: auto;
}

.skel-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 3rem;
  padding: 0 var(--sp);
  border-bottom: 1px solid var(--border-dim);

  &:last-child {
    border-bottom: none;
  }
}

.skel-check {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 0.5rem;
  flex-shrink: 0;
}

.skel-label {
  width: 60%;
  height: 0.85rem;
}

.skel-icon {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.25rem;
  flex-shrink: 0;
}

.skel-name {
  width: 45%;
  height: 0.8rem;
}

.skel-val {
  width: 2.5rem;
  height: 0.8rem;
  margin-left: auto;
}

@media (prefers-reduced-motion: reduce) {

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