/* Plank Track - Molten Core Theme */

:root {
  /* Color Palette */
  --ember-900: #1a0a0a;
  --ember-800: #2d1810;
  --ember-700: #4a2519;
  --ember-600: #8b3a1d;
  --molten-500: #e85a24;
  --molten-400: #ff7f3f;
  --gold-300: #ffd699;
  --ash-100: #f5ebe6;
  --ash-200: #d4c4ba;

  /* Gradients */
  --forge-gradient: radial-gradient(ellipse at bottom, #3d1a0d 0%, #1a0a0a 70%);
  --molten-gradient: linear-gradient(135deg, var(--molten-500) 0%, var(--molten-400) 100%);
  --glow-shadow: 0 0 40px rgba(232, 90, 36, 0.4);

  /* Typography */
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Sizing */
  --timer-size: 280px;
  --ring-stroke: 8;
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  background-color: #1a0a0a;  /* ember-900 - fills notch + overscroll areas */
}

body {
  font-family: var(--font-body);
  background: var(--forge-gradient);
  background-attachment: fixed;
  background-color: #1a0a0a;  /* Prevents white flash on overscroll */
  color: var(--ash-100);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* App Container */
.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 20px;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 20px);
  position: relative;
}

/* Spark Particles Container */
#spark-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
  overflow: hidden;
}

.spark {
  position: absolute;
  width: 6px;
  height: 6px;
  background: var(--gold-300);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--molten-400), 0 0 12px var(--molten-500);
  animation: spark-rise 1s ease-out forwards;
}

@keyframes spark-rise {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-100px) scale(0);
  }
}

/* Hero Section */
.hero {
  text-align: center;
  padding: 40px 0 20px;
}

.streak-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.flame-icon {
  font-size: 2rem;
  animation: flame-flicker 2s ease-in-out infinite;
}

@keyframes flame-flicker {
  0%, 100% { transform: scale(1) rotate(-2deg); opacity: 1; }
  25% { transform: scale(1.05) rotate(1deg); opacity: 0.9; }
  50% { transform: scale(0.98) rotate(-1deg); opacity: 1; }
  75% { transform: scale(1.02) rotate(2deg); opacity: 0.95; }
}

.streak-count {
  font-family: var(--font-display);
  font-size: 3.5rem;
  font-weight: 400;
  color: var(--gold-300);
  text-shadow: 0 0 30px rgba(255, 214, 153, 0.5);
  line-height: 1;
}

.streak-label {
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--ash-200);
  text-transform: uppercase;
}

.best-streak {
  margin-top: 8px;
  font-size: 0.875rem;
  color: var(--ember-600);
}

/* Timer Section */
.timer-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0 40px;
}

.timer-ring-container {
  position: relative;
  width: var(--timer-size);
  height: var(--timer-size);
  margin-bottom: 48px;
}

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

.timer-ring-bg {
  fill: none;
  stroke: var(--ember-800);
  stroke-width: var(--ring-stroke);
}

.timer-ring-progress {
  fill: none;
  stroke: url(#molten-gradient);
  stroke: var(--molten-500);
  stroke-width: var(--ring-stroke);
  stroke-linecap: round;
  stroke-dasharray: 565.48;
  stroke-dashoffset: 565.48;
  transition: stroke-dashoffset 0.1s linear;
  filter: drop-shadow(0 0 8px var(--molten-500));
}

.timer-display {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.timer-time {
  display: block;
  font-family: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 3.5rem;
  font-variant-numeric: tabular-nums;
  color: var(--ash-100);
  line-height: 1;
  min-width: 4.5ch;
  text-align: center;
}

.timer-status {
  display: block;
  font-size: 0.875rem;
  color: var(--ember-600);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 4px;
}

.timer-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 70%;
  height: 70%;
  background: radial-gradient(circle, rgba(232, 90, 36, 0.15) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.timer-glow.active {
  opacity: 1;
  animation: glow-pulse 2s ease-in-out infinite;
}

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

/* Primary Button */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  min-width: 320px;
  padding: 18px 32px;
  background: var(--molten-gradient);
  border: none;
  border-radius: 16px;
  color: white;
  font-family: var(--font-body);
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  box-shadow: var(--glow-shadow), 0 4px 20px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
}

.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 0 20px rgba(232, 90, 36, 0.3), 0 2px 10px rgba(0, 0, 0, 0.3);
}

.btn-primary.running {
  background: var(--ember-700);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.btn-primary.running:active {
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.btn-icon {
  font-size: 1rem;
}

/* Manual Entry */
.manual-entry {
  margin-top: 24px;
  text-align: center;
  width: 100%;
  max-width: 280px;
}

.manual-divider {
  display: block;
  font-size: 0.8125rem;
  color: var(--ember-600);
  margin-bottom: 12px;
}

.manual-input-group {
  display: flex;
  gap: 10px;
}

.manual-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--ember-800);
  border: 1px solid var(--ember-700);
  border-radius: 12px;
  color: var(--ash-100);
  font-family: var(--font-body);
  font-size: 1rem;
  text-align: center;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.manual-input:focus {
  border-color: var(--molten-500);
  box-shadow: 0 0 0 3px rgba(232, 90, 36, 0.2);
}

.manual-input::placeholder {
  color: var(--ember-600);
}

.btn-add {
  width: 48px;
  height: 48px;
  background: var(--ember-700);
  border: 1px solid var(--ember-600);
  border-radius: 12px;
  color: var(--molten-400);
  font-size: 1.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
}

.btn-add:active {
  transform: scale(0.95);
  background: var(--ember-600);
}

/* Section Titles */
.section-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--ash-100);
  margin-bottom: 16px;
}

/* History Section */
.history-section {
  padding: 20px 0;
}

.plank-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.plank-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--ember-800);
  border-radius: 12px;
  border-left: 3px solid var(--molten-500);
  animation: card-stamp 0.3s ease-out;
}

@keyframes card-stamp {
  0% { transform: scale(0.95); opacity: 0; }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); opacity: 1; }
}

.plank-card-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--ember-700) 0%, var(--ember-800) 100%);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
}

.plank-card-details {
  flex: 1;
}

.plank-card-duration {
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--ash-100);
}

.plank-card-time {
  font-size: 0.8125rem;
  color: var(--ember-600);
}

.plank-card-delete {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--ember-600);
  font-size: 1.25rem;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.plank-card-delete:hover,
.plank-card-delete:active {
  opacity: 1;
  background: var(--ember-700);
}

.empty-state {
  text-align: center;
  padding: 30px 20px;
  color: var(--ember-600);
  font-style: italic;
}

/* Stats Section */
.stats-section {
  padding: 30px 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--ember-800);
  border-radius: 12px;
  padding: 16px 12px;
  text-align: center;
}

.stat-value {
  display: block;
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--gold-300);
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.6875rem;
  color: var(--ember-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chart-container {
  background: var(--ember-800);
  border-radius: 16px;
  padding: 20px;
  height: 200px;
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 40px 0 20px;
  color: var(--ember-600);
  font-size: 0.8125rem;
}

.app-logo {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  opacity: 0.6;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 360px) {
  :root {
    --timer-size: 240px;
  }

  .streak-count {
    font-size: 2.5rem;
  }

  .timer-time {
    font-size: 2.5rem;
  }

  .stat-value {
    font-size: 1.25rem;
  }
}

@media (min-width: 481px) {
  .app {
    padding-top: max(env(safe-area-inset-top, 0), 20px);
  }
}

/* Landscape Layout - Mobile only: simplified timer + button only */
@media (orientation: landscape) and (max-height: 500px) {
  .app {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 40px;
    max-width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 16px;
    padding-left: max(env(safe-area-inset-left, 0px), 16px);
    padding-right: max(env(safe-area-inset-right, 0px), 16px);
  }

  /* Hide everything except timer section */
  .hero,
  .history-section,
  .stats-section,
  .app-footer { display: none; }

  /* Timer section: just timer ring and button side by side */
  .timer-section {
    flex-direction: row;
    gap: 40px;
    padding: 0;
  }

  .timer-ring-container {
    margin-bottom: 0;
    flex-shrink: 0;
  }

  /* Hide manual entry in landscape */
  .manual-entry { display: none; }

  /* Large, easy-to-tap button */
  .btn-primary {
    padding: 24px 48px;
    font-size: 1.5rem;
  }
}
