:root {
  font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans",sans-serif;
  color: #29372f;
  background: #fff;
  --accent: #426a56;
  --sleep: #343b3a;
  --high: #eea04a;
  --up: #e9ce66;
  --steady: #7db68d;
  --down: #79a7d4;
  --low: #a58bc5
}

* {
  box-sizing: border-box
}

body {
  margin: 0
}

button,input,textarea {
  font: inherit
}

button {
  cursor: pointer;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 10px;
  min-height: 44px;
  padding: 10px;
}

button:hover {
  background: #eaf0e9
}

button:focus-visible,input:focus-visible,textarea:focus-visible {
  outline: 3px solid #82a991;
  outline-offset: 3px
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round
}

header {
  background: #fafbf9;
  border-bottom: 1px solid #e2e8e0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px max(24px,calc((100vw - 1040px)/2));
  gap: 16px
}

h1 {
  font-size: 23px;
  letter-spacing: .04em;
  margin: 0;
  white-space: nowrap
}

.actions {
  display: flex;
  gap: 14px
}

.actions button {
  display: grid;
  place-items: center;
}

.primary {
  background: var(--accent);
  color: white
}

.primary:hover {
  background: #345541
}

main {
  max-width: 1040px;
  margin: 12px auto 110px;
  padding: 0 24px
}

h2 {
  font-size: 26px;
  margin: 4px 0 10px;
  letter-spacing: .04em
}

.panel {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 0
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px
}

.toolbar h3 {
  font-size: 21px;
  margin: 0
}

.toolbar div {
  display: flex;
  gap: 4px
}

.toolbar button {
  font-size: 24px
}

.toolbar #today,
.toolbar #calendar-today {
  font-size: 12px
}

.chart-heading {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  padding-bottom: 12px
}

.legend {
  padding: 12px 0;
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 12px;
  color: #607064
}

.legend span {
  display: flex;
  align-items: center;
  gap: 6px
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--color)
}

.axis {
  margin-left: 64px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #88938b;
  margin-bottom: 0
}

.axis span {
  width: 0;
  display: flex;
  justify-content: center;
}

.day-row {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  min-height: 34px
}

.day-label {
  width: 64px;
  flex-shrink: 0;
  font-size: 12px;
  text-align: left;
  padding: 0;
  min-height: 34px
}

.day-label small {
  font-size: 10px;
  color: #9aa49b;
  margin-left: 5px
}

.day-row.current .day-label {
  color: var(--accent);
  font-weight: 700
}

.track {
  position: relative;
  isolation: isolate;
  height: 34px;
  flex: 1;
  background: repeating-linear-gradient(to right,transparent 0,transparent calc(100% / 24 - 1px),#e2e8e0 calc(100% / 24 - 1px),#e2e8e0 calc(100% / 24)),#f6f8f5;
  border-radius: 4px;
  overflow: visible
}

.segment {
  text-align: center;
  position: absolute;
  top: 0;
  height: 100%;
  line-height: 34px;
  min-height: 0;
  border-radius: 0;
  background: var(--color);
  font-size: 11px;
  padding: 0 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #182d20
}

.segment.sleep {
  color: white
}

.segment-text {
  position: relative;
  z-index: 4;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.record-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: 6px;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 1px;
  background: #fff;
  box-shadow: 0 0 0 1px #fff;
}

.record-marker::before {
  content: "";
  position: absolute;
  inset: -4px -9px;
}

.record-marker:hover {
  background: #fff;
}

.target-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  transform: translateX(-50%);
  z-index: 3;
  pointer-events: none;
}

.target-line.wake { background: #dc3535; }
.target-line.bed { background: #2869df; }

#settings-dialog input[type=time] {
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-inline-size: 0;
  inline-size: 100%;
  max-inline-size: 100%;
  margin-top: 10px;
  padding: 12px;
  border: 1px solid #dce3d8;
  border-radius: 10px;
  background: #fafbf8;
  color: inherit;
}

#settings-form,
#settings-dialog .field {
  min-width: 0;
  max-width: 100%;
}

#settings-dialog input[type=time]::-webkit-date-and-time-value {
  min-width: 0;
  text-align: center;
}

#settings-error { color: #a04135; font-size: 13px; }
#clear-data { background: #c83535; color: #fff; }
#clear-data:hover { background: #a82626; }
.settings-help { color: #657367; font-size: 13px; line-height: 1.7; }

.calendar-body {
  border: 1px solid #e8ece6;
}

.calendar-weekdays, .calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.calendar-weekdays {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fafbf9;
  border-bottom: 1px solid #e8ece6;
  text-align: center;
  font-size: 12px;
  color: #89938c;
  padding: 12px 0;
}

.calendar-weekdays span:first-child { color: #ba8582; }
.calendar-weekdays span:last-child { color: #8299b0; }
.calendar-day {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  border-top: 1px solid #e8ece6;
  border-right: 1px solid #e8ece6;
}

.calendar-day:nth-child(7n) { border-right: 0; }
.calendar-day.outside { background: #fafbf9; color: #9ba69c; }
.calendar-day .date-number {
  align-self: flex-start;
  display: grid;
  place-items: center;
  min-height: 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 13px;
}

.calendar-day.today .date-number { background: #547a67; color: #fff; border-radius: 50%; }
.calendar-record {
  width: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0 2px;
  text-align: left;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  border-radius: 5px;
}

.calendar-time { font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.calendar-time.wake { color: #805b2d; }
.calendar-time.bed { color: #5b6485; }
.calendar-mood { font-size: 11px; padding: 4px 8px; border-radius: 5px; }
.calendar-mood.high { background: #f7e1d4; color: #a2633c; }
.calendar-mood.up { background: #f6ecd4; color: #92763a; }
.calendar-mood.steady { background: #e4eddf; color: #527747; }
.calendar-mood.down { background: #e2ecf4; color: #5c7c98; }
.calendar-mood.low { background: #e9e4f2; color: #7f6c9a; }
.calendar-note { font-size: 10px; color: #627468; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

@media(max-width:600px) {
  .calendar-day { padding: 7px 2px; gap: 4px; align-items: center; }
  .calendar-day .date-number { align-self: center; }
  .calendar-record { align-items: center; text-align: center; }
  .calendar-time { font-size: clamp(9px, 2.5vw, 12px); letter-spacing: -.3px; }
  .calendar-mood { font-size: 10px; padding: 4px 1px; width: 100%; }
}

.hint {
  font-size: 11px;
  color: #88918a;
  margin: 22px 0 0
}

.privacy {
  text-align: center;
  color: #8b968e;
  font-size: 11px;
  line-height: 1.8;
  margin: 22px 0
}

nav {
  position: fixed;
  bottom: 0;
  background: #fafbf9f5;
  border-top: 1px solid #e0e7dd;
  backdrop-filter: blur(12px);
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 48px;
  padding: 10px 20px calc(10px + env(safe-area-inset-bottom));
  z-index: 3
}

nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #879187;
  font-size: 13px;
  min-width: 140px;
  justify-content: center
}

nav button[aria-current] {
  background: #e8efe5;
  color: #3d634a;
  font-weight: 600
}

.entry {
  display: flex;
  gap: 20px;
  border-bottom: 1px solid #edf0eb;
  width: 100%;
  text-align: left;
  padding: 24px 4px;
  border-radius: 0
}

.entry:last-child {
  border-bottom: 0
}

.entry-icon {
  font-size: 27px;
  width: 32px;
  color: #7c8b79
}

.entry-main {
  flex: 1;
  min-width: 0
}

.entry strong {
  font-size: 17px;
  font-weight: 600
}

.entry-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 12px 0;
  color: #849084;
  font-size: 13px
}

.badge {
  background: var(--color);
  padding: 4px 12px;
  border-radius: 20px;
  color: #243d2c;
  font-size: 12px
}

.entry p {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.8;
  margin: 8px 0 0
}

.empty {
  text-align: center;
  padding: 65px 20px;
  color: #7b897e;
  line-height: 2
}

.empty button {
  display: block;
  margin: 18px auto
}

dialog {
  width: min(520px,calc(100% - 28px));
  max-height: 90dvh;
  border: 1px solid #e3e8df;
  border-radius: 20px;
  padding: 28px;
  color: inherit;
  background: #fff
}

dialog::backdrop {
  background: #1d322b70;
  backdrop-filter: blur(3px)
}

.dialog-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px
}

.dialog-heading h2 {
  font-size: 20px
}

.dialog-heading button {
  font-size: 24px
}

fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 24px
}

legend,.field {
  font-size: 14px;
  color: #657367;
  font-weight: 600
}

legend {
  margin-bottom: 14px
}

.type-options {
  display: flex;
  background: #f0f3ed;
  border-radius: 12px;
  padding: 4px;
  gap: 4px
}

.type-options label {
  flex: 1;
  text-align: center;
  cursor: pointer
}

.type-options input {
  position: absolute;
  opacity: 0
}

.type-options span {
  display: block;
  padding: 12px;
  border-radius: 9px
}

.type-options input:checked+span {
  background: white;
  box-shadow: 0 2px 6px #23352312;
  color: var(--accent);
  font-weight: 600
}

.type-options input:focus-visible+span {
  outline: 3px solid #82a991
}

.field {
  display: block;
  margin-bottom: 24px
}

input[type=datetime-local],textarea {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 13px 12px;
  background: #fafbf8;
  border: 1px solid #dce3d8;
  border-radius: 10px;
  color: #29372f;
  font-size: 16px
}

textarea {
  resize: vertical
}

.mood-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap
}

.mood-options label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  border: 1px solid #e2e7dd;
  border-radius: 8px;
  padding: 10px 9px;
  cursor: pointer
}

.mood-options label:has(:checked) {
  border-color: var(--color);
  background: color-mix(in srgb,var(--color) 18%,white)
}

input[type=radio] {
  accent-color: var(--accent)
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px
}

.danger {
  color: #a75349;
  margin-right: auto
}

#form-error,#notice {
  color: #a04135;
  font-size: 13px;
  line-height: 1.7
}

#notice {
  background: #fff4e8;
  padding: 15px;
  border-radius: 10px
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%)
}

[hidden] {
  display: none!important
}

@media(max-width:600px) {
  header {
    padding: 18px 16px;
    gap: 4px
  }

  h1 {
    font-size: 18px
  }

  .actions {
    gap: 10px
  }

  .actions button {
    width: 38px;
    padding: 8px;
    min-height: 40px
  }

  main {
    padding: 0 14px;
    margin-top: 8px
  }

  h2 {
    font-size: 23px
  }

  .legend {
    gap: 10px;
    font-size: 10px
  }

  .swatch {
    width: 10px;
    height: 10px
  }

  .day-label {
    width: 47px;
    font-size: 11px
  }

  .day-label small {
    margin-left: 3px;
    font-size: 9px
  }

  .axis {
    font-size: 8px;
    margin-left: 47px
  }

  .segment {
    font-size: 9px;
    line-height: 32px;
    padding: 0 2px
  }

  .day-row,.track {
    height: 32px;
    min-height: 32px
  }

  .privacy {
    font-size: 10px
  }

  nav {
    gap: 14px
  }

  nav button {
    min-width: 135px;
    font-size: 12px
  }

  .entry {
    gap: 12px
  }

  .entry strong {
    font-size: 15px
  }

  dialog {
    padding: 22px
  }

  .mood-options {
    gap: 5px
  }

  .mood-options label {
    padding: 10px 6px;
    font-size: 12px
  }

}

.entry-meta:empty {
  min-height: 18px
}

.entry-comment .badge {
  display: inline-block;
  margin-right: 10px;
  vertical-align: baseline
}

/* Calendar-style record editor */
#editor {
  padding: 28px;
  color: #303e3b
}

#editor .dialog-heading {
  margin-bottom: 24px
}

#editor #close {
  border-radius: 50%;
  background: #f0f3ed;
  color: #7a8780;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 28px
}

#editor .mood-options {
  display: grid;
  grid-template-columns: repeat(5,minmax(0,1fr));
  gap: 6px
}

#editor .mood-options label {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  text-align: center;
  min-width: 0;
  min-height: 78px;
  padding: 12px 2px;
  border: 2px solid transparent;
  border-radius: 8px;
  font-size: 13px
}

#editor .mood-options input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: #4c7565
}

#editor .mood-options .high {
  background: #f7e1d4;
  color: #a2633c
}

#editor .mood-options .up {
  background: #f6ecd4;
  color: #92763a
}

#editor .mood-options .steady {
  background: #e4eddf;
  color: #527747
}

#editor .mood-options .down {
  background: #e2ecf4;
  color: #5c7c98
}

#editor .mood-options .low {
  background: #e9e4f2;
  color: #7f6c9a
}

#editor .mood-options label:has(:checked) {
  border-color: currentColor
}

#editor .optional {
  font-size: 12px;
  font-weight: 400;
  color: #9ba59e
}

#editor input[type=datetime-local],#editor textarea {
  background: #fafbf9;
  border-color: #dbe2d9;
  border-radius: 7px;
  font-weight: 400;
  min-width: 0;
  max-width: 100%
}

#editor .form-actions {
  align-items: center;
  margin-top: 20px
}

#editor .form-actions .primary {
  flex: 1;
  min-height: 50px;
  background: #4c7565;
  font-size: 16px
}

#editor .form-actions .primary:hover {
  background: #3a6152
}

#editor .danger {
  font-size: 13px;
  color: #ad7772;
  padding: 10px 4px
}

body:has(#editor[open]) {
  overflow: hidden
}

@media(max-width:600px) {
  #editor {
    position: fixed;
    inset: 0;
    margin: 0;
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
    padding: max(20px,env(safe-area-inset-top)) max(18px,env(safe-area-inset-right)) max(24px,env(safe-area-inset-bottom)) max(18px,env(safe-area-inset-left));
    overflow-y: auto;
    overscroll-behavior: contain
  }

  #editor .dialog-heading {
    position: sticky;
    top: -1px;
    z-index: 2;
    background: #fff;
    padding-bottom: 12px
  }

  #editor .mood-options {
    gap: 5px
  }

  #editor .mood-options label {
    min-height: 74px;
    font-size: 13px
  }

}

#editor .datetime-field {
  min-width: 0;
  width: 100%
}

#editor #at {
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
  min-inline-size: 0;
  inline-size: 100%;
  max-inline-size: 100%;
  padding-right: 20px
}

#editor #at::-webkit-date-and-time-value {
  min-width: 0;
  text-align: center
}

@media(max-width:600px) {
  #editor #form {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    min-width: 0
  }

  #editor #form>* {
    flex-shrink: 0;
    min-width: 0
  }

  #editor #note-field {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-height: 160px
  }

  #editor #note {
    flex: 1;
    min-height: 120px;
    resize: none
  }

  #editor #form-error:empty {
    display: none
  }

  #editor .form-actions {
    margin-top: auto
  }

}

/* Keep all three navigation buttons within narrow screens. */
nav { gap: 12px; }
nav button { min-width: 0; flex: 1; max-width: 180px; }
@media(max-width:600px) {
  nav { gap: 4px; padding-left: 8px; padding-right: 8px; }
  nav button { min-width: 0; gap: 5px; padding: 10px 4px; font-size: 11px; }
}
