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

:root {
  --c1: #def2d9;
  --c2: #e2daf2;
  --c3: #fce2d4;
  --c4: #d9ebf2;
  --c5: #f2d9de;

  --ink:       #2a2228;
  --ink-mid:   #7a6e76;
  --ink-light: #c0b4bc;
  --bg:        #fdf9f7;
  --white:     #ffffff;

  --active:    #c4714f;
  --active-bg: #fce2d4;

  --radius-card: 22px;
  --radius-btn:  15px;
  --radius-sm:   10px;

  --shadow-card: 0 2px 12px rgba(42,34,40,.06);
  --shadow-btn:  0 4px 16px rgba(196,113,79,.25);

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

/* ===========================
   Base
   =========================== */
html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--safe-bottom) + 24px);
  padding-left:  var(--safe-left);
  padding-right: var(--safe-right);
}

/* ===========================
   Header
   =========================== */
.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 28px 20px 0;
  max-width: 520px;
  margin: 0 auto;
}

.app-title {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(20px, 5vw, 24px);
  font-weight: 400;
  letter-spacing: -0.3px;
}

.app-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-mid);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

/* ===========================
   Main Layout
   =========================== */
.app-main {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ===========================
   Message Slideshow Band
   =========================== */
.message-band {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--c5);
  border-radius: 14px;
  padding: 12px 16px;
  min-height: 48px;
  overflow: hidden;
  position: relative;
}

.msg-icon {
  flex-shrink: 0;
  color: var(--ink-mid);
  opacity: 0.7;
}

.msg-track {
  flex: 1;
  overflow: hidden;
}

.msg-text {
  display: block;
  font-size: 13px;
  font-weight: 400;
  color: var(--ink-mid);
  font-style: italic;
  line-height: 1.5;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.msg-text.fade-out {
  opacity: 0;
  transform: translateY(-6px);
}

.msg-text.fade-in {
  opacity: 0;
  transform: translateY(6px);
}

.msg-text.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===========================
   Hero Card
   =========================== */
.hero-card {
  background: var(--c3);
  border-radius: var(--radius-card);
  padding: clamp(24px, 6vw, 36px) clamp(20px, 5vw, 32px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: background 0.4s ease;
}

.hero-card.active {
  background: var(--active-bg);
}

.hero-deco {
  position: absolute;
  top: -50px;
  right: -50px;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  pointer-events: none;
  transition: transform 0.6s ease;
}

.hero-card.active .hero-deco {
  transform: scale(1.15);
}

/* Status pill */
.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--ink-mid);
}

.pulse-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink-light);
  flex-shrink: 0;
  transition: background 0.3s;
}

.pulse-dot.active {
  background: var(--active);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(1.35); }
}

/* Timer display */
.timer-display {
  text-align: center;
  line-height: 1;
}

.time-value {
  display: block;
  font-family: 'DM Serif Display', serif;
  font-size: clamp(68px, 18vw, 88px);
  letter-spacing: -3px;
  color: var(--ink);
  transition: color 0.3s;
}

.time-value.active {
  color: var(--active);
}

.time-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-mid);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 8px;
}

/* Main button */
.main-btn {
  width: 100%;
  min-height: 58px;
  padding: 16px 20px;
  border: none;
  border-radius: var(--radius-btn);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.2px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  background: var(--ink);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  position: relative;
  z-index: 1;
  transition: background 0.25s, transform 0.15s, box-shadow 0.25s;
}

.main-btn.active-state {
  background: var(--active);
  box-shadow: var(--shadow-btn);
}

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

.btn-icon {
  flex-shrink: 0;
  transition: transform 0.3s;
}

.main-btn.active-state .btn-icon {
  transform: scale(0.9);
}

/* ===========================
   Stats Row
   =========================== */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-card {
  border-radius: var(--radius-card);
  padding: 18px 16px;
  box-shadow: var(--shadow-card);
}

.stat-card.stat-green { background: var(--c1); }
.stat-card.stat-blue  { background: var(--c4); }

.stat-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-mid);
  letter-spacing: 1.1px;
  text-transform: uppercase;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-label svg {
  flex-shrink: 0;
  opacity: 0.6;
}

.stat-value {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(28px, 7vw, 36px);
  letter-spacing: -1px;
  line-height: 1;
  color: var(--ink);
}

/* ===========================
   Average Bar
   =========================== */
.avg-bar {
  display: none;
  background: var(--c2);
  border-radius: var(--radius-card);
  padding: 18px 20px;
  gap: 0;
  align-items: center;
  box-shadow: var(--shadow-card);
}

.avg-bar.visible {
  display: flex;
}

.avg-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.avg-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-mid);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.avg-value {
  font-family: 'DM Serif Display', serif;
  font-size: 22px;
  letter-spacing: -0.5px;
  line-height: 1;
}

.avg-divider {
  width: 1px;
  height: 36px;
  background: rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  margin: 0 14px;
}

/* ===========================
   History Section
   =========================== */
.history-section {}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 0 2px;
}

.section-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-mid);
  letter-spacing: 1.3px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-title svg {
  opacity: 0.6;
}

.clear-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-mid);
  cursor: pointer;
  touch-action: manipulation;
  padding: 6px 10px;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
  min-height: 36px;
}

.clear-btn:hover,
.clear-btn:active {
  background: var(--c5);
  color: var(--ink);
}

/* History List */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 36px 20px;
  color: var(--ink-light);
  font-size: 13px;
  text-align: center;
}

.empty-state svg {
  opacity: 0.3;
}

/* History Item */
.history-item {
  background: var(--white);
  border-radius: 16px;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 26px 1fr 1fr 1fr;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-card);
  animation: slideDown 0.25s ease forwards;
}

.history-item:first-child {
  border-left: 3px solid var(--c5);
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.item-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg);
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.item-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.item-field-label {
  font-size: 9px;
  font-weight: 500;
  color: var(--ink-light);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.item-field-val {
  font-size: 14px;
  font-weight: 400;
  color: var(--ink);
  letter-spacing: -0.2px;
}

.item-field-val.muted {
  color: var(--ink-mid);
  font-size: 13px;
}

/* ===========================
   Responsive tweaks
   =========================== */
@media (max-width: 360px) {
  .app-main {
    padding: 16px 12px;
    gap: 12px;
  }

  .history-item {
    padding: 12px 14px;
  }

  .item-field-val {
    font-size: 13px;
  }
}

@media (min-width: 521px) {
  .app-header,
  .app-main {
    max-width: 520px;
  }

  .hero-card {
    padding: 40px 36px;
  }
}
