:root {
  --bg: #faf6f1;
  --card: #ffffff;
  --ink: #2a2724;
  --muted: #6b645c;
  --line: #e7dfd5;
  --teal: #2f8f83;
  --teal-dark: #1f6f65;
  --teal-soft: #e3f2ef;
  --coral: #c93f37;
  --coral-dark: #a8322b;
  --sev-low: #f7e7a8;
  --sev-mid: #f2a65a;
  --sev-high: #c93f37;
  --sev-none: #e9e3da;
  --radius: 16px;
  --tabbar-h: 68px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', 'Noto Sans CJK SC', sans-serif;
  overscroll-behavior-y: contain;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px
    calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}

.page.no-tabs {
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

/* ---------- header ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  margin-bottom: 8px;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 20px;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-size: 14px;
  white-space: nowrap;
}

.pill.warn {
  background: #fdebd2;
  color: #8a4b08;
}

.pill.bad {
  background: #fbdedc;
  color: var(--coral-dark);
}

/* ---------- buttons ---------- */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 56px;
  padding: 0 20px;
  border: 2px solid var(--teal);
  border-radius: 14px;
  background: var(--card);
  color: var(--teal-dark);
  font-size: 18px;
  font-weight: 600;
}

.btn:active {
  filter: brightness(0.94);
}

.btn.primary {
  background: var(--teal);
  color: #fff;
}

.btn.danger {
  border-color: var(--coral);
  color: var(--coral-dark);
}

.btn.danger.solid {
  background: var(--coral);
  color: #fff;
}

.btn.link {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
}

.btn[disabled] {
  opacity: 0.55;
}

.btn-row {
  display: flex;
  gap: 12px;
}

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

.btn-row .btn.grow {
  flex: 2;
}

.stack {
  display: grid;
  gap: 12px;
}

/* ---------- the big record button ---------- */

.record {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: min(42vh, 300px);
  margin: 12px 0;
  border: 0;
  border-radius: 28px;
  background: var(--coral);
  color: #fff;
  box-shadow: 0 6px 0 var(--coral-dark);
}

.record:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--coral-dark);
}

.record.stop {
  background: var(--teal);
  box-shadow: 0 6px 0 var(--teal-dark);
}

.record.stop:active {
  box-shadow: 0 2px 0 var(--teal-dark);
}

.record .big {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.record .sub {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  opacity: 0.95;
}

/* ---------- cards ---------- */

.card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.card h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.card p {
  margin: 0 0 12px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 14px;
}

h2.section {
  margin: 24px 4px 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}

.disclaimer {
  margin: 24px 8px 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.empty {
  padding: 24px 8px;
  color: var(--muted);
  text-align: center;
}

/* ---------- entry rows ---------- */

.entries {
  display: grid;
  gap: 10px;
}

.entry {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  min-height: 64px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  text-align: left;
}

.entry:active {
  background: #f3ede5;
}

.sev {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--sev-none);
  font-size: 20px;
  font-weight: 700;
}

.sev-low {
  background: var(--sev-low);
}

.sev-mid {
  background: var(--sev-mid);
}

.sev-high {
  background: var(--sev-high);
  color: #fff;
}

.entry-main {
  display: grid;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.entry-time {
  font-weight: 600;
}

.entry-tags,
.entry-by {
  color: var(--muted);
  font-size: 14px;
}

.entry-note {
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live {
  color: var(--coral-dark);
}

/* ---------- calendar ---------- */

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

.month-nav h2 {
  margin: 0;
  font-size: 20px;
}

.icon-btn {
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 24px;
  line-height: 1;
}

.cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal .dow {
  padding: 4px 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 2px 0;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--card);
  font-size: 16px;
  line-height: 1.15;
}

.day.blank {
  visibility: hidden;
}

.day .n {
  font-weight: 500;
}

.day .s {
  min-width: 20px;
  margin-top: 1px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
}

.day.today {
  border-color: var(--teal);
}

.day.selected {
  border-color: var(--ink);
}

.day.has-low {
  background: var(--sev-low);
}

.day.has-mid {
  background: var(--sev-mid);
}

.day.has-high {
  background: var(--sev-high);
  color: #fff;
}

.day.has-none {
  background: var(--sev-none);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 13px;
}

.legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  border-radius: 4px;
  vertical-align: -1px;
}

.day-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 20px 4px 8px;
}

.day-heading h3 {
  margin: 0;
  font-size: 15px;
  color: var(--muted);
}

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabbar > div {
  display: flex;
  width: 100%;
  max-width: 560px;
}

.tab {
  flex: 1;
  height: var(--tabbar-h);
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
}

.tab .ico {
  display: block;
  font-size: 22px;
  line-height: 1.2;
}

.tab[aria-current='page'] {
  color: var(--teal-dark);
  font-weight: 700;
}

/* ---------- forms and chips ---------- */

.field {
  margin: 0 0 20px;
}

.field > label,
.field > .label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

.field .hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

input[type='text'],
input[type='datetime-local'],
textarea {
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 17px;
}

input:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--teal);
  outline: 3px solid rgba(47, 143, 131, 0.35);
  outline-offset: 1px;
}

textarea {
  resize: vertical;
}

.code-input {
  font-size: 22px !important;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
}

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

.chip {
  min-width: 52px;
  min-height: 52px;
  padding: 0 16px;
  border: 2px solid var(--line);
  border-radius: 26px;
  background: #fff;
  font-size: 17px;
}

.chip[aria-pressed='true'] {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
  font-weight: 600;
}

.chips.scale .chip {
  min-width: 0;
  flex: 0 0 calc((100% - 40px) / 6);
  padding: 0;
  border-radius: 14px;
  font-weight: 700;
}

.error {
  margin: 0 0 12px;
  color: var(--coral-dark);
  font-weight: 600;
}

.code {
  display: block;
  margin: 8px 0 12px;
  padding: 14px;
  border-radius: 12px;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font: 700 28px/1.2 ui-monospace, 'SF Mono', Menlo, monospace;
  letter-spacing: 0.1em;
  text-align: center;
  user-select: all;
}

.seg {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.seg .chip {
  flex: 1;
}

/* ---------- overlay (editor) and dialog ---------- */

#overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow-y: auto;
  background: var(--bg);
  scroll-padding-bottom: 96px; /* keep focused fields clear of the sticky buttons */
  -webkit-overflow-scrolling: touch;
}

.sheet {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

.sheet h1 {
  margin: 0 0 16px;
  font-size: 22px;
}

.sheet .actions {
  position: sticky;
  bottom: 0;
  margin: 0 -16px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: rgba(30, 26, 22, 0.5);
}

.dialog {
  width: 100%;
  max-width: 520px;
  padding: 20px;
  border-radius: 20px;
  background: #fff;
}

.dialog h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.dialog p {
  margin: 0 0 16px;
}

/* ---------- toast ---------- */

#toast {
  position: fixed;
  right: 16px;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  left: 16px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 528px;
  margin: 0 auto;
  padding: 8px 8px 8px 16px;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
}

#toast button {
  min-width: 80px;
  min-height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}

.noscript {
  padding: 24px;
}

.lg-low {
  background: var(--sev-low);
}

.lg-mid {
  background: var(--sev-mid);
}

.lg-high {
  background: var(--sev-high);
}

.lg-none {
  background: var(--sev-none);
}
