:root {
  --bg-top: #fff8f3;
  --bg-bottom: #ffe1ec;
  --card: rgba(255,255,255,0.75);
  --card-border: rgba(255,150,175,0.22);
  --text: #6b4657;
  --text-dim: #b98a9a;
  --accent-a: #ff9166;
  --accent-b: #ffc66b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Apple SD Gothic Neo", "Pretendard", sans-serif;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  padding-top: var(--safe-top);
}

.app-header {
  position: relative;
  text-align: center;
  padding: 8px 20px 2px;
  flex-shrink: 0;
}
.app-header h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.app-header .tagline {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
}
.settings-btn {
  position: absolute;
  right: 16px;
  top: 12px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--card);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.settings-btn:active {
  transform: scale(0.92);
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: 8px 20px 12px;
}
.view[hidden] {
  display: none;
}

/* ---------- Home / syringe ---------- */

.syringe-stage {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

#syringe-svg {
  height: 100%;
  max-height: 100%;
  width: auto;
  max-width: 94vw;
  position: relative;
  z-index: 2;
  filter: drop-shadow(0 6px 18px rgba(0,0,0,0.25));
  transition: transform 0.35s ease;
  animation: syringe-idle-bob 3.2s ease-in-out infinite;
  transform-origin: 50% 90%;
}

@keyframes syringe-idle-bob {
  0%, 100% { transform: rotate(0deg) translateY(0); }
  50% { transform: rotate(-1.5deg) translateY(-3px); }
}

.ready-glow {
  position: absolute;
  width: 80%;
  aspect-ratio: 1;
  max-width: 340px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,145,102,0.4), rgba(255,198,107,0.0) 70%);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.6s ease, transform 0.6s ease;
  z-index: 1;
  pointer-events: none;
}

#app.state-ready .ready-glow {
  opacity: 1;
  transform: scale(1);
  animation: pulse-glow 1.8s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.12); opacity: 1; }
}

#app.state-ready #syringe-svg {
  animation: syringe-breathe 1.6s ease-in-out infinite;
}
@keyframes syringe-breathe {
  0%, 100% { transform: rotate(-2deg) translateY(0); }
  50% { transform: rotate(2deg) translateY(-5px); }
}

#app.state-injecting #syringe-svg {
  transform: translateY(6px);
  animation: none;
}

#app.state-preparing #syringe-svg {
  animation: syringe-idle-bob 3.2s ease-in-out infinite;
}

#app.state-preparing #syringe-svg,
#app.state-injecting #syringe-svg {
  filter: drop-shadow(0 8px 22px rgba(255,145,102,0.4));
}

#syringe-svg.bounce-pop {
  animation: bounce-pop 0.45s cubic-bezier(.36,1.8,.4,1);
}
@keyframes bounce-pop {
  0% { transform: scale(1); }
  35% { transform: scale(0.92, 1.08); }
  60% { transform: scale(1.06, 0.94); }
  100% { transform: scale(1); }
}

#plunger-rod, #plunger-head, #liquid, #droplet {
  transition: none;
}

.sparkle {
  position: absolute;
  z-index: 3;
  font-size: 14px;
  color: #fff6e6;
  text-shadow: 0 0 8px rgba(255,198,107,0.9);
  opacity: 0;
  pointer-events: none;
}
.sparkle-1 { top: 18%; left: 22%; }
.sparkle-2 { top: 28%; right: 18%; font-size: 10px; }
.sparkle-3 { bottom: 30%; left: 16%; font-size: 11px; }
.sparkle-4 { bottom: 20%; right: 22%; font-size: 16px; }

#app.state-ready .sparkle {
  animation: sparkle-twinkle 1.6s ease-in-out infinite;
}
#app.state-ready .sparkle-1 { animation-delay: 0s; }
#app.state-ready .sparkle-2 { animation-delay: 0.35s; }
#app.state-ready .sparkle-3 { animation-delay: 0.7s; }
#app.state-ready .sparkle-4 { animation-delay: 1.05s; }

@keyframes sparkle-twinkle {
  0%, 100% { opacity: 0; transform: scale(0.5) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.15) rotate(20deg); }
}

.status-text {
  margin: 2px 0 12px;
  font-size: 14px;
  color: var(--text-dim);
  text-align: center;
  min-height: 18px;
  flex-shrink: 0;
}

.action-btn {
  flex-shrink: 0;
  border: none;
  border-radius: 999px;
  padding: 13px 40px;
  font-size: 15.5px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  box-shadow: 0 8px 24px rgba(255,145,102,0.35);
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease, box-shadow 0.2s ease;
  -webkit-user-select: none;
  user-select: none;
}
.action-btn:active {
  transform: scale(0.96);
}
.action-btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.action-btn.ready-state {
  background: linear-gradient(135deg, #ffc66b, #ff9166);
  box-shadow: 0 8px 28px rgba(255,198,107,0.45);
}

.today-summary {
  flex-shrink: 0;
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-dim);
  padding-bottom: 4px;
}
.today-summary strong {
  color: var(--text);
  font-weight: 700;
}

/* ---------- Tab bar ---------- */

.tabbar {
  flex-shrink: 0;
  display: flex;
  border-top: 1px solid var(--card-border);
  background: var(--card);
  backdrop-filter: blur(20px);
  padding-bottom: calc(var(--safe-bottom) + 6px);
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px 0 4px;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.tab-btn .tab-icon {
  font-size: 20px;
  filter: grayscale(1) opacity(0.6);
}
.tab-btn.active {
  color: var(--text);
}
.tab-btn.active .tab-icon {
  filter: none;
}

/* ---------- History ---------- */

.segmented {
  flex-shrink: 0;
  display: flex;
  width: 100%;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 3px;
  margin: 6px 0 16px;
}
.seg-btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 0;
  border-radius: 9px;
  cursor: pointer;
}
.seg-btn.active {
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  color: #fff;
}

#history-content {
  width: 100%;
  padding-bottom: 20px;
}

.period-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.period-nav button {
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}
.period-nav .period-label {
  font-size: 16px;
  font-weight: 700;
}
.period-total {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 14px;
}
.period-total strong {
  color: var(--text);
  font-size: 15px;
}

/* day list */
.day-group {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.day-group-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.day-group-head .date {
  font-weight: 700;
  font-size: 14.5px;
}
.day-group-head .count {
  font-size: 12.5px;
  color: var(--accent-b);
  font-weight: 700;
}
.time-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.time-chip {
  font-size: 11.5px;
  color: var(--text-dim);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--card-border);
  padding: 3px 9px;
  border-radius: 999px;
}
.empty-msg {
  text-align: center;
  color: var(--text-dim);
  font-size: 13.5px;
  padding: 40px 10px;
}

/* month calendar */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-bottom: 14px;
}
.cal-dow {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  padding-bottom: 4px;
}
.cal-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  background: var(--card);
  border: 1px solid transparent;
  position: relative;
  cursor: default;
}
.cal-cell.blank { background: none; border: none; }
.cal-cell.has-record {
  border-color: var(--card-border);
}
.cal-cell.today {
  border-color: var(--accent-b);
}
.cal-cell .badge {
  position: absolute;
  bottom: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
}
.cal-cell .badge.count2::after { content: ""; }

.day-detail {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 12px 14px;
}
.day-detail .date {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 8px;
}

/* chart / bar graph */
.chart-section {
  width: 100%;
  margin-bottom: 16px;
}
.chart-title {
  text-align: center;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.chart-title strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.year-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 160px;
  margin-bottom: 6px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 10px 8px 6px;
}
.year-bars.compact {
  height: 130px;
  gap: 2px;
}
.year-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 4px;
  min-width: 0;
}
.year-bar-count {
  font-size: 10px;
  color: var(--text-dim);
  min-height: 12px;
}
.year-bars.compact .year-bar-count {
  font-size: 8px;
  min-height: 10px;
}
.year-bar {
  width: 100%;
  border-radius: 5px 5px 2px 2px;
  background: linear-gradient(180deg, var(--accent-a), var(--accent-b));
  min-height: 2px;
}
.year-bar-col.zero .year-bar {
  background: var(--card-border);
}
.year-bar-col.highlight .year-bar {
  box-shadow: 0 0 0 2px var(--accent-a);
}
.year-bar-label {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}
.year-bars.compact .year-bar-label {
  font-size: 8px;
}
.year-bar-col.highlight .year-bar-label {
  color: var(--accent-a);
  font-weight: 700;
}

/* ---------- Healing overlay ---------- */

.healing-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  z-index: 999;
  overflow: hidden;
  background: radial-gradient(circle at 50% 55%, rgba(255,198,107,0.0) 0%, rgba(35,21,14,0.0) 100%);
}
.healing-overlay.show {
  opacity: 1;
  transition: opacity 0.5s ease;
}
.healing-glow {
  position: absolute;
  width: 60vmax;
  height: 60vmax;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,198,107,0.55), rgba(255,145,102,0.35) 45%, rgba(35,21,14,0) 72%);
  transform: scale(0);
  opacity: 0;
}
.healing-overlay.show .healing-glow {
  animation: glow-expand 3.6s ease-out forwards;
}
@keyframes glow-expand {
  0% { transform: scale(0); opacity: 0; }
  25% { opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}
.healing-text {
  position: relative;
  color: #fff;
  font-size: 19px;
  font-weight: 600;
  text-align: center;
  letter-spacing: -0.01em;
  text-shadow: 0 2px 18px rgba(255,145,102,0.8);
  opacity: 0;
  transform: translateY(8px) scale(0.97);
  padding: 0 32px;
}
.healing-subtext {
  display: block;
  margin-top: 10px;
  font-size: 12.5px;
  font-weight: 700;
  color: rgba(255,255,255,0.85);
  letter-spacing: 0.01em;
}
.healing-overlay.show .healing-text {
  animation: text-rise 3.6s ease-out forwards;
}
@keyframes text-rise {
  0% { opacity: 0; transform: translateY(8px) scale(0.97); }
  14% { opacity: 1; transform: translateY(0) scale(1); }
  55% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px) scale(1); }
}
.healing-particles {
  position: absolute;
  inset: 0;
}
.particle {
  position: absolute;
  bottom: 40%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff, var(--accent-b));
  opacity: 0;
  animation: particle-float 2s ease-out forwards;
}
@keyframes particle-float {
  0% { opacity: 0; transform: translate(0,0) scale(0.4); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.1); }
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 100px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(58,38,26,0.92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 1000;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Settings modal ---------- */

.settings-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(35,20,10,0.55);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 1100;
  padding: 20px;
}
.settings-overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.settings-card {
  width: 100%;
  max-width: 340px;
  background: var(--bg-top);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 22px 22px 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  transform: translateY(12px) scale(0.97);
  transition: transform 0.25s ease;
}
.settings-overlay.show .settings-card {
  transform: translateY(0) scale(1);
}
.settings-card h2 {
  margin: 0 0 16px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}
.settings-label {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.name-row {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}
.name-row input {
  flex: 1;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
}
.name-row input::placeholder {
  color: var(--text-dim);
}
.name-row button {
  border: none;
  border-radius: 10px;
  padding: 0 16px;
  font-size: 13.5px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  cursor: pointer;
}
.sound-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 20px;
}
.toggle-btn {
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}
.toggle-btn[aria-pressed="false"] {
  opacity: 0.6;
}
.settings-close {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 12px 0;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--card-border);
  cursor: pointer;
}

/* ---------- Dose tag / caption (symptom-based prescription) ---------- */

.dose-tag {
  position: absolute;
  top: 4%;
  right: 4%;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 14px;
  border-radius: 14px;
  background: var(--dose-color, var(--accent-a));
  color: #fff;
  box-shadow: 0 6px 16px rgba(0,0,0,0.18);
  pointer-events: none;
}
.dose-tag[hidden] { display: none; }
.dose-tag-mg {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.1;
}
.dose-tag-label {
  font-size: 10px;
  font-weight: 600;
  opacity: 0.92;
  white-space: nowrap;
}

.dose-caption {
  width: 100%;
  max-width: 320px;
  margin: 0 auto 10px;
  padding: 11px 18px;
  border-radius: 14px;
  background: var(--dose-color, var(--accent-a));
  color: #fff;
  font-size: 14.5px;
  font-weight: 700;
  text-align: center;
  line-height: 1.4;
  flex-shrink: 0;
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
}
.dose-caption[hidden] { display: none; }

/* ---------- Arm poke target ---------- */

.arm-target {
  position: absolute;
  bottom: 2%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.arm-target[hidden] { display: none; }
.arm-target:active .arm-svg {
  transform: scale(0.94);
}
.arm-svg {
  width: 112px;
  height: auto;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,0.15));
  transition: transform 0.12s ease;
}
.arm-site-ring {
  fill: rgba(239,106,84,0.28);
  animation: arm-pulse 1.3s ease-in-out infinite;
}
@keyframes arm-pulse {
  0%, 100% { r: 9; opacity: 0.9; }
  50% { r: 15; opacity: 0.25; }
}
.arm-hint {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--card-border);
  padding: 4px 12px;
  border-radius: 999px;
}

/* ---------- Symptom picker modal ---------- */

.symptom-card {
  max-width: 360px;
}
.symptom-sub {
  margin: -8px 0 14px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.symptom-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.symptom-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 4px;
  border-radius: 14px;
  border: 1.5px solid var(--card-border);
  background: var(--card);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.symptom-emoji {
  font-size: 22px;
}
.symptom-chip.selected {
  border-color: var(--dose-color, var(--accent-a));
  background: var(--dose-color, var(--accent-a));
  color: #fff;
}
.dose-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--card-border);
  margin-bottom: 16px;
}
.dose-preview[hidden] { display: none; }
.dose-preview-badge {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--dose-color, var(--accent-a));
  color: #fff;
  font-weight: 800;
  font-size: 14px;
}
.dose-preview-caption {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  margin: 0;
}
.symptom-confirm-btn {
  width: 100%;
}
.symptom-confirm-btn:disabled {
  opacity: 0.45;
}
