*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary:       #0277BD;
  --primary-dark:  #01579B;
  --primary-light: #B3E5FC;
  --primary-xlt:   #E1F5FE;
  --bg:            #F2F7FC;
  --surface:       #FFFFFF;
  --text:          #1A237E;
  --text-body:     #37474F;
  --text-sub:      #78909C;
  --border:        #DDEEFF;
  --shadow:        0 2px 12px rgba(2,119,189,0.10);
  --danger:        #C62828;
  --nav-h:         60px;
  --header-h:      56px;
}

html {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans',
               'Noto Sans JP', 'Yu Gothic UI', sans-serif;
  background: var(--bg);
  color: var(--text-body);
  height: 100%;
}

body {
  height: 100%;
}

/* ===== VIEWS ===== */

.view {
  display: none;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
}

.view.active {
  display: flex;
}

/* ===== HEADER ===== */

.main-header {
  flex-shrink: 0;
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.main-header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.header-date {
  font-size: 13px;
  opacity: 0.85;
  font-weight: 500;
}

/* ===== HOME ===== */

.home-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--nav-h) + 20px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

/* ===== SUMMARY CARD ===== */

.summary-card {
  background: var(--surface);
  border-radius: 18px;
  padding: 16px 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.summary-period-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.period-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--primary);
  background: var(--primary-xlt);
  padding: 3px 9px;
  border-radius: 20px;
  flex-shrink: 0;
}

.period-text {
  font-size: 13px;
  color: var(--text-body);
  font-weight: 500;
}

.summary-main {
  display: flex;
  align-items: center;
}

.summary-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-sep {
  width: 1px;
  height: 52px;
  background: var(--border);
  margin: 0 16px;
  flex-shrink: 0;
}

.summary-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sub);
  letter-spacing: 0.04em;
}

.summary-value {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.big-num {
  font-size: 34px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.big-num.small {
  font-size: 22px;
}

.unit {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sub);
}

.baseline-tag {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-sub);
  line-height: 1.5;
}

/* ===== REGISTER BUTTON ===== */

.register-btn {
  width: 100%;
  min-height: 56px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border: none;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(2,119,189,0.35);
  letter-spacing: 0.04em;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.register-btn:active {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(2,119,189,0.20);
}

.register-btn.recorded {
  background: linear-gradient(135deg, #1B5E20, #2E7D32);
  box-shadow: 0 4px 16px rgba(27,94,32,0.30);
}

.register-icon {
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
}

/* ===== CHART ===== */

.chart-card {
  background: var(--surface);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.chart-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-body);
}

.chart-subtitle {
  font-size: 12px;
  color: var(--primary);
  font-weight: 600;
}

.chart-wrap {
  width: 100%;
  height: 160px;
  position: relative;
}

#usage-chart {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-empty {
  display: none;
  text-align: center;
  color: var(--text-sub);
  font-size: 13px;
  padding: 20px 0 4px;
}

.chart-empty.show {
  display: block;
}

/* ===== LIST SCROLL (History / Settings) ===== */

.list-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px calc(var(--nav-h) + 14px);
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.settings-scroll {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ===== HISTORY ===== */

#history-list {
  display: flex;
  flex-direction: column;
}

.month-group {
  margin-bottom: 18px;
}

.month-header {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  color: var(--text-sub);
  padding: 4px 4px 8px;
}

.reading-row {
  background: var(--surface);
  border-radius: 14px;
  padding: 13px 14px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.reading-row:last-child {
  margin-bottom: 0;
}

.r-date {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 40px;
}

.r-day {
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.r-month {
  font-size: 10px;
  color: var(--text-sub);
  font-weight: 500;
  margin-top: 1px;
}

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

.r-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-body);
}

.r-diff {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 2px;
}

.r-diff.up {
  color: #00838F;
}

.r-edit-btn, .r-del-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  transition: color 0.15s, background 0.15s;
}

.r-edit-btn {
  color: var(--primary);
}

.r-edit-btn:active {
  background: var(--primary-xlt);
}

.r-del-btn {
  color: #CFD8DC;
}

.r-del-btn:active {
  color: var(--danger);
  background: #FFEBEE;
}

/* ===== SETTINGS ===== */

.settings-desc {
  font-size: 13px;
  color: var(--text-sub);
  line-height: 1.65;
  background: var(--primary-xlt);
  padding: 12px 14px;
  border-radius: 12px;
}

.add-btn {
  width: 100%;
  min-height: 52px;
  background: var(--surface);
  border: 2px dashed var(--primary-light);
  border-radius: 14px;
  color: var(--primary);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.04em;
  transition: background 0.15s;
}

.add-btn:active {
  background: var(--primary-xlt);
}

#baseline-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bl-row {
  background: var(--surface);
  border-radius: 14px;
  padding: 14px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.bl-row.current {
  border-color: var(--primary-light);
  border-width: 2px;
}

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

.bl-date {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-body);
}

.bl-value {
  font-size: 13px;
  color: var(--text-sub);
  margin-top: 2px;
}

.bl-note {
  font-size: 11px;
  color: var(--primary);
  font-weight: 600;
  margin-top: 2px;
}

.bl-badge {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-xlt);
  padding: 3px 9px;
  border-radius: 20px;
}

.bl-edit-btn, .bl-del-btn {
  flex-shrink: 0;
  height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  transition: color 0.15s, background 0.15s;
}

.bl-edit-btn {
  font-size: 12px;
  color: var(--primary);
  padding: 0 8px;
  min-width: 44px;
}

.bl-edit-btn:active {
  background: var(--primary-xlt);
}

.bl-del-btn {
  width: 36px;
  font-size: 14px;
  color: #CFD8DC;
}

.bl-del-btn:active {
  color: var(--danger);
  background: #FFEBEE;
}

/* ===== EMPTY STATE ===== */

.empty-state {
  text-align: center;
  color: var(--text-sub);
  font-size: 14px;
  padding: 48px 20px 0;
}

/* ===== BOTTOM NAV ===== */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
  flex: 1;
  height: 100%;
  min-height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-sub);
  font-family: inherit;
  transition: color 0.15s;
  padding: 0;
}

.nav-btn.active {
  color: var(--primary);
}

.nav-icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* ===== MODALS ===== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.hidden {
  display: none;
}

.modal-sheet {
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 12px 20px 36px;
  width: 100%;
  max-width: 600px;
  animation: slideUp 0.22s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-handle {
  width: 38px;
  height: 4px;
  background: #DDD;
  border-radius: 2px;
  margin: 0 auto 18px;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin-bottom: 22px;
}

.modal-desc {
  font-size: 15px;
  color: var(--text-body);
  text-align: center;
  margin-bottom: 24px;
  line-height: 1.6;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 22px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-body);
}

.form-input {
  width: 100%;
  height: 50px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 0 14px;
  font-size: 16px;
  color: var(--text-body);
  font-family: inherit;
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

.form-input:focus {
  border-color: var(--primary);
  background: #fff;
}

/* ===== SPLIT INPUT ===== */

.split-row {
  display: flex;
  align-items: center;
  height: 56px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
  transition: border-color 0.15s;
}

.split-row:focus-within {
  border-color: var(--primary);
  background: #fff;
}

.split-int {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: none;
  background: transparent;
  outline: none;
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  text-align: right;
  padding: 0 4px 0 12px;
  font-family: inherit;
}

.split-dot {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  flex-shrink: 0;
  padding: 0 2px;
  line-height: 1;
  user-select: none;
}

.split-dec {
  width: 82px;
  flex-shrink: 0;
  height: 100%;
  border: none;
  border-left: 1px solid var(--border);
  background: transparent;
  outline: none;
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  text-align: left;
  padding: 0 12px 0 6px;
  font-family: inherit;
  letter-spacing: 0.05em;
}

.form-error {
  font-size: 12px;
  color: var(--danger);
  font-weight: 500;
  padding: 0 2px;
}

.form-error.hidden { display: none; }

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-btn {
  flex: 1;
  height: 52px;
  min-height: 44px;
  border: none;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s ease;
}

.modal-btn:active { transform: scale(0.97); }

.modal-btn.secondary {
  background: var(--bg);
  color: var(--text-sub);
  border: 1px solid var(--border);
}

.modal-btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 3px 12px rgba(2,119,189,0.30);
}

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

/* ===== RESPONSIVE ===== */

@media (min-width: 480px) {
  .main-header h1 { font-size: 22px; }
  .big-num { font-size: 38px; }
  .big-num.small { font-size: 26px; }
}
