* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  background: #ece3d2;
  font-family: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  color: #2f2a26;
  touch-action: manipulation;
}

.screen {
  position: relative;
  width: 100%;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(12px + env(safe-area-inset-bottom));
}

@media (min-width: 600px) {
  .mood-content {
    gap: 44px;
  }

  .year-grid {
    grid-template-columns: 21px repeat(12, 19px);
  }

  .legend-swatch {
    width: 15px;
    height: 15px;
  }

  .legend-label {
    font-size: 12px;
  }
}

@media (min-width: 1180px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .screen {
    max-width: 520px;
    height: 88vh;
    max-height: 860px;
    padding: calc(18px + env(safe-area-inset-top)) 18px calc(16px + env(safe-area-inset-bottom));
  }

  .year-grid {
    grid-template-columns: 24px repeat(12, 22px);
  }

  .legend-swatch {
    width: 17px;
    height: 17px;
  }

  .legend-label {
    font-size: 13px;
  }

  .header-title {
    font-size: 21px;
  }

  .cover-content h1 {
    font-size: 30px;
  }
}

/* card */
.card {
  flex: 1;
  position: relative;
  background: #fffaf2;
  border-radius: 22px;
  box-shadow: 0 14px 32px rgba(60, 48, 32, 0.14);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.dog-ear {
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 26px 26px 0;
  border-color: transparent #ece3d2 transparent transparent;
  z-index: 6;
}

/* header */
.header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 30px 16px 20px;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--accent) 10%, #fffaf2);
}

.header-title {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 19px;
  letter-spacing: 0.2px;
  color: #2f2a26;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logout {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.3px;
  color: #9c948a;
  text-decoration: none;
  text-transform: uppercase;
  display: flex;
  align-items: center;
}

.header-toc {
  background: none;
  border: none;
  color: #9c948a;
  font-size: 15px;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
}

.header-menu-wrap {
  position: relative;
}

.header-menu-dropdown {
  position: absolute;
  right: 0;
  top: 26px;
  background: #fffaf2;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(40, 32, 22, 0.2);
  padding: 4px;
  display: none;
  flex-direction: column;
  min-width: 130px;
  z-index: 60;
}

.header-menu-dropdown.open {
  display: flex;
}

.dropdown-item {
  background: none;
  border: none;
  text-align: left;
  padding: 8px 10px;
  font-size: 13px;
  color: #2f2a26;
  cursor: pointer;
  border-radius: 6px;
  font-family: inherit;
}

.header-menu {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 18px;
  cursor: pointer;
  padding: 0;
}

.header-stitch {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 0;
  border-bottom: 1px dashed color-mix(in srgb, var(--accent) 40%, transparent);
}

/* flip area */
.flip-area {
  position: relative;
  flex: 1;
  min-height: 0;
  perspective: 2200px;
  overflow: hidden;
  touch-action: pan-y;
}

.pages {
  position: relative;
  width: 100%;
  height: 100%;
}

.page {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: 14px 18px 16px;
  background: #fffaf2;
}

.page.active {
  display: flex;
}

.flip-overlay {
  z-index: 20;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: transform 0.5s ease-in-out;
  transform: rotateY(0deg);
  pointer-events: none;
}

.flip-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, transparent, rgba(60, 48, 32, 0.08), transparent);
  pointer-events: none;
}

/* page contents */
.page-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.cover-content {
  align-items: center;
  text-align: center;
}

.cover-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.cover-mark {
  color: #2f6f5e;
  font-size: 20px;
  margin-bottom: 4px;
}

.cover-content h1 {
  font-family: 'Fraunces', serif;
  font-size: 26px;
  margin: 0;
  font-weight: 600;
}

.cover-content p {
  margin: 0;
  color: #9c948a;
  font-size: 14px;
}

.cover-owner {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 10px;
  color: #9c948a;
  font-size: 13px;
}

.cover-owner-edit {
  background: none;
  border: none;
  color: #b3a89a;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

.mood-content {
  flex-direction: row;
  gap: 45px;
  padding-top: 4px;
  align-items: stretch;
}

.year-grid {
  display: grid;
  grid-template-columns: 18px repeat(12, 16px);
  grid-template-rows: 20px repeat(31, minmax(0, 1fr));
  gap: 2px;
  flex: 0 1 auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.grid-corner {
  /* empty top-left spacer cell */
}

.grid-month-label {
  font-size: 11px;
  font-weight: 500;
  color: #b3a89a;
  text-align: center;
  align-self: center;
}

.grid-day-label {
  font-size: 11px;
  color: #b3a89a;
  text-align: right;
  padding-right: 3px;
  align-self: center;
}

.cell {
  width: 100%;
  height: 100%;
  border-radius: 5px;
}

.cell.empty {
  background: #8a8278;
}

.cell.today {
  box-shadow: 0 0 0 2px #2f2a26;
}

.cell[data-month] {
  cursor: pointer;
}

.sidebar {
  width: 60px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.sidebar-swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
}

.sidebar-label {
  font-size: 11px;
  color: #9c948a;
}

.sidebar-legend {
  display: flex;
  flex-direction: column-reverse;
  gap: 16px;
  width: 100%;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  padding: 2px;
  margin: -2px;
  border-radius: 6px;
}

.legend-row.selected {
  background: rgba(60, 48, 32, 0.06);
}

.legend-swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  flex-shrink: 0;
}

.legend-row.selected .legend-swatch {
  box-shadow: 0 0 0 2px #2f2a26;
}

.legend-label {
  flex: 1;
  font-size: 11px;
  color: #9c948a;
  line-height: 1.2;
  min-width: 0;
}

.legend-row.selected .legend-label {
  color: #2f2a26;
  font-weight: 600;
}

.journal-content {
  gap: 8px;
  padding-top: 2px;
}

.journal-content h2 {
  flex: 1;
  text-align: center;
  font-family: 'Fraunces', serif;
  font-size: 19px;
  font-weight: 600;
  margin: 0;
}

.journal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.journal-nav-btn {
  background: none;
  border: none;
  color: #5b7c99;
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 6px;
}

.journal-nav-btn:disabled {
  color: #d8cfb9;
  cursor: default;
}

.journal-paper {
  flex: 1;
  width: 100%;
  border: 1px dashed #d8cfb9;
  border-radius: 6px;
  padding: 0 12px 10px;
  font-family: inherit;
  font-size: 16px;
  color: #4a4439;
  resize: none;
  outline: none;
  line-height: 27px;
  background-image: repeating-linear-gradient(#fffaf2 0 26px, #ece3d2 26px 27px);
  background-position: 0 0;
}

.save-hint {
  font-size: 11px;
  color: #9c948a;
  height: 14px;
  opacity: 0;
  transition: opacity 0.3s;
}

.save-hint.visible {
  opacity: 1;
}

.stats-content {
  align-items: center;
  gap: 12px;
}

.stats-content h2 {
  font-family: 'Fraunces', serif;
  margin: 0;
  font-size: 19px;
  font-weight: 600;
}

.stats-content p {
  margin: auto 0;
  color: #b3a89a;
  font-size: 13px;
  text-align: center;
}

.stats-month-bar {
  display: flex;
  gap: 6px;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.stats-month-bar::-webkit-scrollbar {
  display: none;
}

.stats-month-btn {
  flex-shrink: 0;
  border: 1px solid #e3dcc9;
  background: #fff;
  color: #9c948a;
  font-family: inherit;
  font-size: 11.5px;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.stats-month-btn.selected {
  background: #2f2a26;
  border-color: #2f2a26;
  color: #fffaf2;
  font-weight: 600;
}

.stats-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding-bottom: 8px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px dashed #e3dcc9;
}

.stat-card:last-child {
  border-bottom: none;
}

.stat-donut {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-donut-hole {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fffaf2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(60, 48, 32, 0.06);
}

.stat-donut-icon {
  font-size: 11px;
  line-height: 1;
}

.stat-donut-total {
  font-family: 'Fraunces', serif;
  font-size: 12px;
  font-weight: 600;
  color: #2f2a26;
  line-height: 1.3;
}

.stat-info {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.stat-title {
  font-family: 'Fraunces', serif;
  font-size: 15px;
  font-weight: 600;
  color: #2f2a26;
  margin-bottom: 4px;
}

.stat-legend {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: #9c948a;
}

.stat-legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  flex-shrink: 0;
}

.stat-legend-empty {
  font-style: italic;
}

/* table of contents page */
.toc-content {
  align-items: stretch;
  gap: 10px;
}

.toc-content h2 {
  font-family: 'Fraunces', serif;
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  text-align: center;
}

.toc-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.toc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  border-bottom: 1px dashed #e3dcc9;
  padding: 12px 4px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}

.toc-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.toc-label {
  flex: 1;
  font-family: 'Fraunces', serif;
  font-size: 15px;
  font-weight: 600;
  color: #2f2a26;
}

.toc-add {
  border-bottom: none;
  color: #9c948a;
}

.toc-add .toc-label {
  color: #9c948a;
  font-weight: 500;
}

.toc-add .toc-icon {
  font-size: 18px;
}

.toc-arrow {
  color: #b3a89a;
  font-size: 16px;
}

/* tracker creation modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(40, 32, 22, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 320px;
  max-height: 90vh;
  overflow-y: auto;
  background: #fffaf2;
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(40, 32, 22, 0.3);
}

.modal-card h3 {
  font-family: 'Fraunces', serif;
  font-size: 18px;
  margin: 0 0 14px;
  font-weight: 600;
}

.modal-label {
  display: block;
  font-size: 11px;
  color: #9c948a;
  margin-bottom: 4px;
  margin-top: 12px;
}

.modal-input {
  width: 100%;
  border: 1px solid #e3dcc9;
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 16px;
  color: #2f2a26;
  outline: none;
  background: #fff;
}

.modal-input-icon {
  width: 56px;
}

.icon-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
  max-height: 116px;
  overflow-y: auto;
}

.icon-choice-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid #e3dcc9;
  background: #fff;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-choice-btn.selected {
  border-color: #2f2a26;
  background: #f3ead9;
}

.level-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
  max-height: 220px;
  overflow-y: auto;
}

.level-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.level-color-input {
  width: 30px;
  height: 30px;
  border: 1px solid #e3dcc9;
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
  background: none;
  flex-shrink: 0;
}

.level-label-input {
  flex: 1;
  border: 1px solid #e3dcc9;
  border-radius: 8px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 16px;
  color: #2f2a26;
  outline: none;
  background: #fff;
  min-width: 0;
}

.level-remove-btn {
  border: none;
  background: none;
  color: #b3a89a;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  width: 22px;
}

.preset-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.preset-strip {
  display: flex;
  height: 22px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #e3dcc9;
  padding: 0;
  cursor: pointer;
}

.preset-swatch {
  flex: 1;
}

.level-add-btn {
  margin-top: 8px;
  border: 1px dashed #d8cfb9;
  background: none;
  color: #9c948a;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}

.modal-error {
  color: #b3543f;
  font-size: 12px;
  min-height: 14px;
  margin: 10px 0 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.modal-btn {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

.modal-btn-ghost {
  background: transparent;
  color: #9c948a;
}

.modal-btn-primary {
  background: #2f2a26;
  color: #fffaf2;
}

/* login page */
.login-screen {
  width: 100%;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 320px;
  background: #fffaf2;
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: 0 14px 32px rgba(60, 48, 32, 0.14);
  text-align: center;
}

.login-card h1 {
  font-family: 'Fraunces', serif;
  font-size: 26px;
  font-weight: 600;
  margin: 4px 0 20px;
}

.login-card form {
  text-align: left;
}

.password-field {
  position: relative;
}

.password-field .modal-input {
  padding-right: 52px;
}

.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #9c948a;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  cursor: pointer;
  padding: 4px 6px;
}

.login-submit {
  width: 100%;
  margin-top: 18px;
  padding: 10px 14px;
}

.login-error {
  text-align: center;
}

.login-switch-link {
  display: block;
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
  color: #766f64;
  text-decoration: none;
}

.login-switch-link:hover {
  text-decoration: underline;
}
