:root {
  --bg: #FDF8F3;
  --bg-accent: #F7ECE2;
  --surface: #FFFFFF;
  --surface-soft: #FFFBF7;
  --text: #3E2723;
  --text-muted: #8C6D62;
  --border: rgba(74, 44, 42, 0.09);

  --espresso: #5C3A2E;
  --latte: #C89B7B;
  --blush: #E8A598;
  --blush-soft: #FCEAE5;
  --cream-btn: #FFF7EF;
  --office-soft: #F3F0E8;
  --fake-soft: #FCECE8;
  --danger: #D95B5B;

  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;

  --shadow-card: 0 10px 30px rgba(92, 58, 46, 0.08);
  --shadow-btn: 0 6px 16px rgba(92, 58, 46, 0.07);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tab-height: 68px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: ui-rounded, 'SF Pro Rounded', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  min-height: 100%;
}

button, input {
  font-family: inherit;
  color: inherit;
}

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

.app-shell {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: calc(var(--safe-top) + 14px);
  padding-bottom: calc(var(--tab-height) + var(--safe-bottom) + 20px);
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 20px 14px;
}

.greeting {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.date-title {
  margin: 2px 0 0;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}

.header-badge {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  background: linear-gradient(145deg, #FCECE2, #F3DAC8);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-btn);
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 0 18px;
}

.view {
  display: none;
  animation: fadeIn 220ms ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Hero Counter Card */
.counter-card {
  background: linear-gradient(180deg, #FFFFFF 0%, #FFF9F4 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 20px 18px 18px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.counter-ring {
  position: relative;
  width: 148px;
  height: 148px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: #F3E6DC;
  stroke-width: 10;
}

.ring-fill {
  fill: none;
  stroke: #C88C6B;
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 326.7256;
  stroke-dashoffset: 326.7256;
  transition: stroke-dashoffset 450ms cubic-bezier(0.22, 1, 0.36, 1), stroke 300ms ease;
}

.counter-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.counter-number {
  font-size: 2.55rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--text);
  transition: transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.counter-number.pop {
  transform: scale(1.16);
}

.counter-unit {
  margin-top: 4px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Funny Message Speech Bubble */
.message-bubble {
  width: 100%;
  background: var(--blush-soft);
  border: 1px solid rgba(232, 165, 152, 0.35);
  border-radius: 18px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  transition: transform 150ms ease, background-color 150ms ease;
}

.message-bubble:active {
  transform: scale(0.98);
  background: #FADFD7;
}

.message-sparkle {
  font-size: 1rem;
  flex-shrink: 0;
}

.message-text {
  font-size: 0.94rem;
  font-weight: 600;
  line-height: 1.35;
  color: #5A352C;
}

/* Section Labels */
.section-label {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 10px 4px;
}

.section-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-row .section-label {
  margin-bottom: 0;
}

.section-meta {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* 3 Cute Coffee Buttons */
.coffee-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 11px;
  margin-bottom: 12px;
}

.coffee-btn {
  appearance: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 8px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: var(--shadow-btn);
  transition: transform 140ms cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 140ms ease;
  position: relative;
  overflow: hidden;
}

.coffee-btn:active {
  transform: scale(0.94);
  box-shadow: 0 2px 8px rgba(92, 58, 46, 0.08);
}

.btn-regular {
  background: linear-gradient(180deg, #FFFBF7 0%, #FBECE0 100%);
  border-color: rgba(200, 155, 123, 0.35);
}

.btn-office {
  background: linear-gradient(180deg, #FCFBF8 0%, #EFECE3 100%);
  border-color: rgba(168, 155, 134, 0.35);
}

.btn-fake {
  background: linear-gradient(180deg, #FFFBF9 0%, #FBE6E1 100%);
  border-color: rgba(232, 165, 152, 0.4);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
}

.btn-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.15;
}

.btn-sub {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.btn-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  background: #FFFFFF;
  color: var(--espresso);
  box-shadow: 0 2px 6px rgba(92, 58, 46, 0.08);
}

/* Custom Amount Button */
.custom-trigger {
  width: 100%;
  border: 1.5px dashed rgba(140, 109, 98, 0.35);
  background: rgba(255, 255, 255, 0.75);
  border-radius: var(--radius-md);
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--espresso);
  margin-bottom: 24px;
  transition: transform 140ms ease, background-color 140ms ease;
}

.custom-trigger:active {
  transform: scale(0.98);
  background: #FFFFFF;
}

.custom-trigger-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--blush-soft);
  color: var(--espresso);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 800;
}

/* Today's Log & History Entries */
.today-log-section {
  margin-bottom: 12px;
}

.entry-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.entry-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 12px;
  display: flex;
  align-items: center;
  gap: 11px;
  box-shadow: 0 3px 10px rgba(92, 58, 46, 0.04);
}

.entry-emoji {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.entry-emoji.type-regular { background: #FBECE0; }
.entry-emoji.type-office  { background: #EFECE3; }
.entry-emoji.type-fake    { background: #FBE6E1; }
.entry-emoji.type-custom  { background: #EFE8F6; }

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

.entry-name {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-time {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 1px;
}

.entry-amount {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--espresso);
  background: var(--bg-accent);
  padding: 4px 9px;
  border-radius: 999px;
  flex-shrink: 0;
}

.entry-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.entry-icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 140ms ease, color 140ms ease;
}

.entry-icon-btn:active {
  background: var(--bg-accent);
  color: var(--text);
}

.entry-icon-btn.delete:active {
  background: #FDE8E8;
  color: var(--danger);
}

.empty-state {
  text-align: center;
  padding: 22px 16px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.6);
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

/* History View */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 10px;
  text-align: center;
  box-shadow: 0 4px 14px rgba(92, 58, 46, 0.05);
}

.stat-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.15;
}

.stat-label {
  display: block;
  margin-top: 3px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* 7-Day Chart */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 16px 14px;
  box-shadow: 0 6px 18px rgba(92, 58, 46, 0.05);
  margin-bottom: 18px;
}

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

.chart-title {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--text);
}

.text-btn {
  border: none;
  background: var(--blush-soft);
  color: var(--espresso);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 11px;
  border-radius: 999px;
}

.text-btn:active {
  transform: scale(0.96);
}

.week-chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  align-items: end;
  height: 108px;
}

.chart-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  gap: 5px;
}

.chart-val {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  min-height: 14px;
}

.chart-bar-wrap {
  width: 100%;
  max-width: 26px;
  height: 62px;
  background: #F7EFE8;
  border-radius: 999px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.chart-bar {
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(180deg, #E8A598, #C88C6B);
  transition: height 350ms cubic-bezier(0.22, 1, 0.36, 1);
}

.chart-col.is-today .chart-bar {
  background: linear-gradient(180deg, #D98A7A, #7B4B3A);
}

.chart-day {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
}

.chart-col.is-today .chart-day {
  color: var(--text);
}

/* History Day Groups */
.history-groups {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.day-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 8px;
}

.day-group-title {
  font-size: 0.94rem;
  font-weight: 800;
  color: var(--text);
}

.day-group-total {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--espresso);
  background: #F5E6D8;
  padding: 3px 10px;
  border-radius: 999px;
}

/* Bottom Tab Bar */
.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  max-width: 460px;
  margin: 0 auto;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(253, 248, 243, 0.86);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.tab-item {
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #A68D83;
  font-size: 0.74rem;
  font-weight: 700;
  transition: color 150ms ease;
}

.tab-item.active {
  color: var(--espresso);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-height) + var(--safe-bottom) + 14px);
  transform: translateX(-50%);
  z-index: 30;
  background: #3E2723;
  color: #FFFDFB;
  padding: 10px 14px 10px 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 10px 28px rgba(62, 39, 35, 0.25);
  max-width: calc(100vw - 32px);
  animation: toastIn 200ms cubic-bezier(0.22, 1, 0.36, 1);
}

.toast[hidden] {
  display: none;
}

.toast-text {
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast-undo {
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #FDE5DC;
  font-size: 0.82rem;
  font-weight: 800;
  padding: 5px 11px;
  border-radius: 999px;
  flex-shrink: 0;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* iOS Bottom Sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(62, 39, 35, 0.35);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fadeIn 180ms ease;
}

.sheet-backdrop[hidden],
.bottom-sheet[hidden] {
  display: none;
}

.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-width: 460px;
  margin: 0 auto;
  background: #FFFDFB;
  border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(22px + var(--safe-bottom));
  box-shadow: 0 -10px 40px rgba(62, 39, 35, 0.18);
  animation: sheetUp 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  width: 40px;
  height: 5px;
  border-radius: 999px;
  background: #E2D5CC;
  margin: 0 auto 12px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.sheet-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text);
}

.icon-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: #F4EAE2;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sheet-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 4px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--espresso);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 6px 11px;
  border-radius: 999px;
}

.chip.selected {
  background: var(--espresso);
  color: #FFFFFF;
  border-color: var(--espresso);
}

.text-input {
  width: 100%;
  border: 1.5px solid #E8DCD3;
  background: #FFFFFF;
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  font-size: 1rem; /* >= 16px prevents iOS Safari auto-zoom on focus! */
  font-weight: 600;
  color: var(--text);
  outline: none;
  transition: border-color 140ms ease;
}

.text-input:focus {
  border-color: var(--latte);
}

.form-error {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--danger);
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.primary-btn {
  width: 100%;
  border: none;
  border-radius: var(--radius-md);
  padding: 14px;
  background: linear-gradient(135deg, #6E4537, #4A2C2A);
  color: #FFFFFF;
  font-size: 1rem;
  font-weight: 800;
  box-shadow: 0 6px 16px rgba(74, 44, 42, 0.22);
}

.primary-btn:active {
  transform: scale(0.98);
}

.danger-btn {
  width: 100%;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px;
  background: #FDECEC;
  color: var(--danger);
  font-size: 0.95rem;
  font-weight: 800;
}

.danger-btn[hidden] {
  display: none;
}

/* Floating +amount burst animation */
.burst-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}

.burst-pill {
  position: fixed;
  font-size: 1.05rem;
  font-weight: 800;
  color: #5C3A2E;
  background: #FFF7EF;
  border: 1.5px solid #E8A598;
  padding: 4px 11px;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(92, 58, 46, 0.14);
  animation: floatUp 780ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes floatUp {
  0%   { opacity: 0; transform: translate(-50%, 0) scale(0.7); }
  20%  { opacity: 1; transform: translate(-50%, -18px) scale(1.06); }
  100% { opacity: 0; transform: translate(-50%, -74px) scale(0.95); }
}
