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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "Libre Baskerville", serif;
  font-optical-sizing: auto;
  background: #f5f0e8;
  color: #1a1a1a;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ---- Header ---- */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: #1a1a1a;
  border-bottom: 2px solid #111;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: #f5f0e8;
  letter-spacing: 0.05em;
  font-family: inherit;
  text-decoration: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-action {
  padding: 0.5rem 0.875rem;
  border-radius: 0;
  border: 1px solid #555;
  background: transparent;
  color: #f5f0e8;
  font-size: 0.75rem;
  font-family: inherit;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  text-decoration: none;
}

/* ---- Main ---- */

.main {
  flex: 1;
}

.content-wrap {
  padding: 1.25rem 1rem;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

/* ---- Section Headers ---- */

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid #1a1a1a;
}

.section-header h2 {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

/* ---- Inputs ---- */

.input {
  padding: 0.75rem;
  border-radius: 0;
  border: 1px solid #c8bfa8;
  background: #faf8f4;
  color: #1a1a1a;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  min-height: 48px;
  width: 100%;
}

.input:focus {
  border-color: #1a1a1a;
}

/* ---- Buttons ---- */

.btn {
  padding: 0.75rem;
  border-radius: 0;
  border: none;
  background: #1a1a1a;
  color: #f5f0e8;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-ghost {
  background: none;
  border: 1px solid #c8bfa8;
  color: #666;
  font-size: 0.75rem;
  padding: 0.5rem 0.75rem;
  min-height: 36px;
}

.btn-danger {
  background: none;
  border: none;
  color: #aaa;
  font-size: 0.75rem;
  padding: 0.5rem 0.75rem;
  min-height: 36px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
}

.btn-danger:hover {
  color: #8b2020;
}

.btn-inline {
  background: none;
  border: none;
  color: #888;
  font-size: 0.75rem;
  padding: 0.5rem 0.75rem;
  min-height: 36px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
}

.btn-inline:hover {
  color: #1a1a1a;
}

.button-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.button-row .btn {
  flex: 1;
}

/* ---- Login ---- */

.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 2rem;
  background: #fff;
  border: 1px solid #c8bfa8;
  width: 100%;
  max-width: 360px;
}

.login-title {
  text-align: center;
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  letter-spacing: 0.05em;
  font-family: inherit;
}

.login-error {
  background: #f8e8e8;
  color: #8b2020;
  padding: 0.625rem 0.875rem;
  border-left: 3px solid #8b2020;
  font-size: 0.875rem;
  display: none;
}

/* ---- Tracker List (index) ---- */

.tracker-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.tracker-card {
  background: #fff;
  padding: 1rem;
  border-bottom: 1px solid #d5cfc3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.tracker-card:first-child {
  border-top: 1px solid #d5cfc3;
}

.tracker-card:hover {
  background: #f0ebe0;
}

.tracker-info {
  flex: 1;
  min-width: 0;
}

.tracker-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.tracker-total {
  font-size: 0.8125rem;
  color: #888;
  font-style: italic;
}

.tracker-actions {
  flex-shrink: 0;
}

/* ---- Create Form ---- */

.create-section {
  margin-top: 2rem;
}

.create-form {
  background: #fff;
  border: 1px solid #c8bfa8;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ---- Tracker Detail ---- */

.detail-wrap {
  padding: 1rem;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.back-link {
  display: flex;
  align-items: center;
  font-size: 0.875rem;
  color: #888;
  padding: 0.5rem 0;
  min-height: 44px;
  margin-bottom: 0.5rem;
  letter-spacing: 0.02em;
}

.back-link:hover {
  color: #1a1a1a;
}

.total-card {
  background: #fff;
  border: 1px solid #c8bfa8;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.total-label {
  font-size: 0.75rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

.total-value {
  font-size: 2.5rem;
  font-weight: 700;
  word-break: break-all;
}

/* ---- Controls Card ---- */

.controls-card {
  background: #fff;
  border: 1px solid #c8bfa8;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ---- Events / History ---- */

.events-section {
  margin-top: 0.5rem;
}

.event-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.event-item {
  background: #fff;
  padding: 1rem;
  border-bottom: 1px solid #d5cfc3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.event-item:first-child {
  border-top: 1px solid #d5cfc3;
}

.event-item:hover {
  background: #f0ebe0;
}

.event-details {
  flex: 1;
  min-width: 0;
}

.event-time {
  font-size: 0.75rem;
  color: #888;
  font-style: italic;
}

.event-note {
  font-size: 0.875rem;
  color: #555;
  margin-top: 0.25rem;
  word-break: break-word;
}

.event-value {
  font-size: 1.125rem;
  font-weight: 700;
  white-space: nowrap;
}

.event-value.positive {
  color: #1a1a1a;
}

.event-value.negative {
  color: #8b2020;
}

.event-actions {
  display: flex;
  gap: 0;
  align-items: center;
}

/* ---- Empty / Loading / Error States ---- */

.empty-state {
  color: #999;
  text-align: center;
  padding: 3rem 1rem;
  font-style: italic;
  font-size: 1rem;
}

.loading {
  padding: 2rem;
  text-align: center;
  color: #999;
  font-style: italic;
}

.error {
  padding: 2rem;
  text-align: center;
  color: #8b2020;
}

/* ---- 404 ---- */

.error-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1rem;
  text-align: center;
}

.error-card {
  background: #fff;
  border: 1px solid #c8bfa8;
  padding: 3rem 2rem;
  max-width: 400px;
  width: 100%;
}

.error-code {
  font-size: 4rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: #1a1a1a;
}

.error-title {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.error-text {
  font-size: 0.875rem;
  color: #888;
  font-style: italic;
  margin-bottom: 1.5rem;
}

.error-card .btn {
  display: inline-flex;
  text-decoration: none;
}

/* ---- Edit inline inputs ---- */

.edit-input {
  width: 100%;
  border: none;
  border-bottom: 1px solid #c8bfa8;
  padding: 0.25rem 0;
  font-family: inherit;
  font-size: 0.875rem;
  background: transparent;
  color: #1a1a1a;
  outline: none;
}

.edit-input:focus {
  border-bottom-color: #1a1a1a;
}

.edit-value-input {
  width: 80px;
  border: none;
  border-bottom: 1px solid #c8bfa8;
  padding: 0.25rem 0;
  font-family: inherit;
  font-size: 1.125rem;
  background: transparent;
  color: #1a1a1a;
  text-align: right;
  outline: none;
}

.edit-value-input:focus {
  border-bottom-color: #1a1a1a;
}

/* ---- Responsive ---- */

@media (min-width: 480px) {
  .header {
    padding: 0.75rem 1.5rem;
  }

  .content-wrap {
    padding: 1.5rem;
  }

  .detail-wrap {
    padding: 1.5rem;
  }

  .total-card {
    padding: 1.75rem;
  }

  .login-form {
    padding: 2.5rem;
  }

  .input {
    font-size: 0.875rem;
    min-height: 44px;
    padding: 0.625rem 0.75rem;
  }

  .btn {
    font-size: 0.8125rem;
    min-height: 44px;
    padding: 0.625rem;
  }

  .tracker-card {
    padding: 1rem 1.25rem;
  }
}

@media (min-width: 768px) {
  .section-header h2 {
    font-size: 1.625rem;
  }

  .total-value {
    font-size: 3rem;
  }
}
