:root {
  color-scheme: light;
  --bg: #f6fbff;
  --surface: #ffffff;
  --surface-soft: #eef8ff;
  --line: #d8e7ef;
  --text: #153242;
  --muted: #668190;
  --primary: #1496cf;
  --primary-deep: #0578ad;
  --accent: #16b39a;
  --warning: #df8b21;
  --danger: #d94b60;
  --shadow: 0 10px 30px rgba(24, 86, 118, 0.12);
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

body.is-locked {
  overflow: hidden;
}

body.is-locked .app-shell {
  display: none;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  touch-action: manipulation;
}

.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #f6fbff 0%, #e9f8ff 100%);
}

body:not(.is-locked) .lock-screen {
  display: none;
}

.lock-panel {
  width: min(100%, 390px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 22px;
  box-shadow: var(--shadow);
}

.lock-panel h1 {
  margin-bottom: 8px;
}

.lock-copy {
  margin-bottom: 16px;
  color: var(--muted);
  font-weight: 750;
}

.lock-form {
  margin-top: 12px;
}

.lock-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.is-hidden {
  display: none !important;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(78px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 18px 12px;
  background: rgba(246, 251, 255, 0.92);
  border-bottom: 1px solid rgba(216, 231, 239, 0.78);
  backdrop-filter: blur(18px);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--primary-deep);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.45rem;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 1.02rem;
  line-height: 1.25;
}

main {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 14px 14px 22px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.panel,
.hero-summary,
.notice {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
}

.hero-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  background: linear-gradient(135deg, #ffffff 0%, #e9f8ff 100%);
}

.label,
.metric span,
label span,
.section-title span,
.record-meta,
.notice p {
  color: var(--muted);
}

.label {
  margin-bottom: 4px;
  font-size: 0.8rem;
  font-weight: 700;
}

.big-number {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-size: clamp(2.1rem, 12vw, 3rem);
  font-weight: 900;
  line-height: 0.95;
}

.big-number small {
  font-size: 0.95rem;
  font-weight: 800;
}

.target-pill {
  max-width: 42%;
  padding: 10px 12px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--primary-deep);
  font-size: 0.88rem;
  font-weight: 800;
  text-align: center;
  box-shadow: inset 0 0 0 1px var(--line);
}

.metrics-grid,
.grid-2,
.calc-grid,
.button-grid {
  display: grid;
  gap: 10px;
}

.metrics-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 14px;
}

.metric {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 1.25rem;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.section-title span {
  flex: 0 0 auto;
  font-size: 0.8rem;
  font-weight: 700;
}

.date-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 14px;
}

.date-row.compact {
  grid-template-columns: minmax(0, 1fr);
}

.date-label {
  display: grid;
  gap: 5px;
  margin: 0;
}

.date-label span {
  font-size: 0.72rem;
  font-weight: 800;
}

.small-button,
.text-button,
.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}

.small-button {
  align-self: end;
  min-height: 44px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--primary-deep);
  font-weight: 800;
  box-shadow: inset 0 0 0 1px var(--line);
}

.text-button {
  padding: 6px 8px;
  background: transparent;
  color: var(--primary-deep);
  font-size: 0.9rem;
  font-weight: 800;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-size: 1.8rem;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(20, 150, 207, 0.28);
}

.stacked-form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  font-weight: 700;
}

label span {
  font-size: 0.78rem;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  outline: none;
  padding: 10px 11px;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20, 150, 207, 0.14);
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-group {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdff;
  padding: 11px;
}

.form-group summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 850;
}

.form-group > * + * {
  margin-top: 12px;
}

.file-card {
  position: relative;
  min-height: 74px;
  align-content: center;
  border: 1px dashed #a9cfe1;
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 12px;
}

.file-card input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-card strong {
  color: var(--primary-deep);
}

.photo-preview {
  min-height: 120px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #edf6fb;
}

.photo-preview.is-empty {
  display: none;
}

.photo-preview img {
  width: 100%;
  max-height: 280px;
  display: block;
  object-fit: cover;
}

.button-row,
.record-actions {
  display: flex;
  gap: 9px;
}

.button-row > button,
.button-grid > button {
  flex: 1 1 0;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 46px;
  padding: 11px 12px;
  font-weight: 850;
}

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

.secondary-button {
  background: var(--surface-soft);
  color: var(--primary-deep);
  box-shadow: inset 0 0 0 1px #c4e1ee;
}

.danger-button {
  background: #fff1f3;
  color: var(--danger);
  box-shadow: inset 0 0 0 1px #ffd1d8;
}

.record-list,
.advice-list,
.meal-breakdown {
  display: grid;
  gap: 10px;
}

.record-card,
.breakdown-card,
.advice-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.record-card {
  display: grid;
  gap: 10px;
  padding: 11px;
}

.record-main {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.record-main.no-photo {
  grid-template-columns: minmax(0, 1fr);
}

.record-thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius);
  background: var(--surface-soft);
  object-fit: cover;
}

.record-title {
  margin-bottom: 4px;
  font-weight: 900;
}

.record-meta {
  font-size: 0.82rem;
  line-height: 1.45;
}

.record-values {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  padding: 5px 7px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
}

.breakdown-card {
  padding: 12px;
}

.breakdown-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 900;
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4eef4;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.photo-tile {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 0;
}

.photo-tile img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.photo-tile span {
  position: absolute;
  left: 5px;
  bottom: 5px;
  max-width: calc(100% - 10px);
  overflow: hidden;
  border-radius: 999px;
  background: rgba(21, 50, 66, 0.74);
  color: #fff;
  padding: 3px 6px;
  font-size: 0.67rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.advice-item {
  padding: 11px;
  line-height: 1.45;
}

.advice-item strong {
  display: block;
  margin-bottom: 2px;
}

.calc-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 13px;
}

.calc-item {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdff;
  padding: 10px;
}

.calc-item span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
}

.calc-item strong {
  display: block;
  margin-top: 4px;
  font-size: 1.08rem;
}

.chart-panel canvas {
  width: 100%;
  height: 220px;
  display: block;
}

.button-grid {
  grid-template-columns: 1fr;
  margin-bottom: 12px;
}

.switch-row {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  margin-top: 10px;
}

.switch-row input {
  width: 20px;
  min-height: 20px;
}

.notice {
  padding: 13px;
  box-shadow: none;
}

.notice p {
  margin-bottom: 7px;
  font-size: 0.82rem;
  line-height: 1.45;
}

.notice p:last-child {
  margin-bottom: 0;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(20px);
}

.nav-button {
  min-width: 0;
  min-height: 54px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 850;
}

.nav-button span {
  display: block;
  margin-bottom: 2px;
  font-size: 1rem;
}

.nav-button strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-button.is-active {
  background: var(--surface-soft);
  color: var(--primary-deep);
}

.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 30;
  min-height: 44px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(21, 50, 66, 0.94);
  color: #fff;
  font-weight: 800;
  text-align: center;
}

.toast.is-visible {
  display: flex;
}

.empty {
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

@media (min-width: 680px) {
  .metrics-grid,
  .button-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .photo-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 360px) {
  main {
    padding-inline: 10px;
  }

  .grid-2,
  .calc-grid {
    grid-template-columns: 1fr;
  }

  .target-pill {
    max-width: 48%;
    font-size: 0.78rem;
  }

  .nav-button {
    font-size: 0.65rem;
  }
}
