@keyframes jiggle { 0%{transform:rotate(-0.9deg)} 50%{transform:rotate(0.9deg)} 100%{transform:rotate(-0.9deg)} }
@keyframes sheetUp { from{transform:translateY(100%)} to{transform:translateY(0)} }
@keyframes fadeIn { from{opacity:0} to{opacity:1} }
@keyframes screenIn { from{opacity:0; transform:translateX(14px)} to{opacity:1; transform:translateX(0)} }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #DAD5C8;
}
body {
  height: 100dvh;
  display: flex;
  justify-content: center;
  font-family: system-ui, -apple-system, sans-serif;
  color: #211E1A;
  overscroll-behavior: none;
}
input, textarea { font-family: inherit; }
input::placeholder { color: #B8B2A6; }

#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  background: #F4F1EA;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(0,0,0,0.12);
}

.screen { height: 100%; display: flex; flex-direction: column; }
.detail-screen { animation: screenIn .26s ease; }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.grid-header {
  padding: calc(20px + env(safe-area-inset-top)) 20px 10px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 12px;
}
.grid-title {
  font-family: 'Space Grotesk', system-ui;
  font-size: 31px;
  font-weight: 600;
  letter-spacing: -0.6px;
  line-height: 1;
}
.grid-sub { font-size: 13px; color: #8A857C; margin-top: 6px; }

.arrange-btn {
  font-size: 14px;
  font-weight: 600;
  padding: 8px 15px;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  background: #fff;
  color: #5A554C;
  flex-shrink: 0;
  user-select: none;
}
.arrange-btn.active { background: #211E1A; color: #fff; }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: 150px;
  gap: 12px;
  grid-auto-flow: dense;
  padding: 8px 16px 130px;
}

.tile {
  border-radius: var(--radius, 24px);
  padding: 14px 15px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  box-shadow: 0 1px 2px rgba(30,25,20,0.05);
  cursor: pointer;
  user-select: none;
  overflow: hidden;
  position: relative;
  touch-action: manipulation;
}
.tile.arranging { cursor: grab; animation: jiggle .32s ease-in-out infinite; touch-action: none; }
.tile.dragging { opacity: 0.5; cursor: grabbing; z-index: 5; }

.tile-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.tile-label { font-weight: 600; color: #37322B; line-height: 1.15; word-break: break-word; }
.tile-step-chip {
  font-size: 10px; font-weight: 700; background: #fff; padding: 3px 7px;
  border-radius: 8px; letter-spacing: 0.3px; flex-shrink: 0;
}
.tile-num { font-weight: 600; line-height: 1; letter-spacing: -1.5px; }
.tile-handle { font-size: 11px; color: rgba(40,36,30,0.4); text-align: center; padding-top: 2px; }
.tile-actions { display: flex; gap: 8px; align-items: center; }
.round-btn {
  flex: 1; height: 40px; border-radius: 12px; display: flex; align-items: center;
  justify-content: center; font-size: 22px; cursor: pointer; user-select: none;
}

.empty-state { text-align: center; padding: 90px 30px; color: #8A857C; }
.empty-title { font-family: 'Space Grotesk', system-ui; font-size: 20px; color: #211E1A; margin-bottom: 8px; }
.empty-body { font-size: 14px; line-height: 1.5; }

.fab {
  position: absolute; right: 22px; bottom: calc(28px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 20px; background: #211E1A; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 34px;
  font-weight: 200; box-shadow: 0 10px 26px rgba(33,30,26,0.32); cursor: pointer; z-index: 20;
  border: none;
}

.detail-header {
  padding: calc(18px + env(safe-area-inset-top)) 16px 8px;
  display: flex; align-items: center; gap: 11px; flex-shrink: 0;
}
.back-btn {
  width: 38px; height: 38px; border-radius: 12px; background: #fff; display: flex;
  align-items: center; justify-content: center; box-shadow: 0 1px 3px rgba(0,0,0,0.07);
  cursor: pointer; font-size: 24px; color: #211E1A; padding-bottom: 3px; flex-shrink: 0;
}
.detail-dot { width: 13px; height: 13px; border-radius: 5px; flex-shrink: 0; }
.detail-title { font-family: 'Space Grotesk', system-ui; font-size: 20px; font-weight: 600; flex: 1; letter-spacing: -0.3px; }
.edit-btn { font-size: 15px; font-weight: 500; color: #8A857C; cursor: pointer; padding: 6px 8px; }

.detail-body { padding: 8px 16px 44px; }
.big-num-wrap { text-align: center; padding: 14px 0 4px; }
.big-num { font-family: 'Space Grotesk', system-ui; font-weight: 600; line-height: 1; letter-spacing: -2px; font-size: 66px; }
.sub-line { font-size: 12.5px; color: #8A857C; margin-top: 9px; letter-spacing: 0.2px; }
.big-actions { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }
.big-btn { width: 66px; height: 46px; border-radius: 15px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.big-plus { color: #fff; font-size: 26px; }
.big-minus { background: #fff; font-size: 24px; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 22px; }
.stat-card { background: #fff; border-radius: 16px; padding: 13px 8px; text-align: center; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.stat-value { font-family: 'Space Grotesk', system-ui; font-size: 21px; font-weight: 600; line-height: 1; }
.stat-label { font-size: 11px; color: #9A948A; margin-top: 4px; letter-spacing: 0.2px; }

.chart-card { background: #fff; border-radius: 20px; padding: 16px 14px 12px; margin-top: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.chart-title { font-size: 12.5px; color: #8A857C; margin-bottom: 14px; letter-spacing: 0.2px; }
.bars-row { display: flex; gap: 3px; align-items: stretch; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; }
.bar-up-wrap { height: 58px; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.bar-up { width: 62%; max-width: 15px; border-radius: 4px 4px 0 0; }
.bar-mid { height: 1px; width: 100%; background: #EDE7DB; }
.bar-down-wrap { height: 32px; width: 100%; display: flex; align-items: flex-start; justify-content: center; }
.bar-down { width: 62%; max-width: 15px; border-radius: 0 0 4px 4px; background: #E08A7B; }
.bars-letters { display: flex; margin-top: 7px; }
.bar-letter { flex: 1; text-align: center; font-weight: 500; }
.no-events { text-align: center; padding: 24px 0; color: #B5AE9F; font-size: 13px; }

.recent-title { font-size: 12.5px; color: #8A857C; margin: 0 4px 8px; letter-spacing: 0.2px; }
.recent-card { background: #fff; border-radius: 20px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.recent-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.recent-row + .recent-row { border-top: 1px solid #F1ECE2; }
.recent-day { font-size: 14.5px; font-weight: 500; color: #211E1A; }
.recent-sub { font-size: 12px; color: #9A948A; margin-top: 2px; }
.recent-net { font-family: 'Space Grotesk', system-ui; font-size: 16px; font-weight: 600; }

.reset-btn {
  margin-top: 20px; text-align: center; padding: 14px; border-radius: 15px; cursor: pointer;
  font-size: 15px; font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.05); transition: all .15s;
}

.sheet-backdrop { position: absolute; inset: 0; z-index: 40; }
.sheet-overlay { position: absolute; inset: 0; background: rgba(24,21,16,0.38); animation: fadeIn .22s ease; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; background: #F4F1EA;
  border-radius: 28px 28px 0 0; padding: 8px 20px calc(40px + env(safe-area-inset-bottom));
  animation: sheetUp .3s cubic-bezier(.2,.85,.25,1); box-shadow: 0 -12px 44px rgba(0,0,0,0.22);
  max-height: 92%; overflow-y: auto;
}
.sheet-grabber { width: 38px; height: 5px; border-radius: 3px; background: #D8D2C6; margin: 7px auto 16px; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.sheet-cancel { font-size: 15px; color: #8A857C; cursor: pointer; padding: 4px; }
.sheet-title { font-family: 'Space Grotesk', system-ui; font-size: 17px; font-weight: 600; }
.sheet-save { font-size: 15px; font-weight: 700; cursor: pointer; padding: 4px; }

.field-label { font-size: 11.5px; color: #9A948A; text-transform: uppercase; letter-spacing: 0.5px; margin: 20px 2px 7px; }
.text-input {
  width: 100%; padding: 13px 14px; border-radius: 14px; border: none; background: #fff;
  font-size: 16px; color: #211E1A; outline: none; box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.swatches { display: flex; gap: 11px; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 11px; cursor: pointer; transition: transform .12s; border: none; padding: 0; }

.size-row { display: flex; gap: 8px; }
.size-opt {
  flex: 1; text-align: center; padding: 11px 0; border-radius: 12px; font-size: 13px;
  font-weight: 600; cursor: pointer; transition: all .13s; background: #fff; color: #6A655C;
  border: 1px solid #E7E1D5; user-select: none;
}

.step-row {
  display: flex; align-items: center; gap: 14px; background: #fff; border-radius: 14px;
  padding: 8px 12px; box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.step-btn {
  width: 38px; height: 38px; border-radius: 11px; background: #F4F1EA; color: #211E1A;
  display: flex; align-items: center; justify-content: center; font-size: 22px; cursor: pointer;
  flex-shrink: 0; user-select: none;
}
.step-value { font-family: 'Space Grotesk', system-ui; font-size: 22px; font-weight: 600; min-width: 42px; text-align: center; }
.step-hint { flex: 1; text-align: right; font-size: 13px; color: #9A948A; }

.delete-btn {
  margin-top: 24px; text-align: center; padding: 13px; border-radius: 14px; cursor: pointer;
  font-size: 15px; font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.05); transition: all .15s;
}

@media (min-width: 481px) {
  body { background: #DAD5C8; }
  #app { margin: 24px 0; border-radius: 32px; height: min(874px, calc(100dvh - 48px)); }
}
