*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --accent: #e2b714;
  --accent-dim: #b8960e;
  --text-primary: #f0f0f0;
  --text-secondary: #a0a0b8;
  --text-muted: #6a6a80;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

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

/* ---- Header ---- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
  flex-shrink: 0;
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
}

.mode-toggle {
  display: flex;
  background: var(--bg-secondary);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.mode-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 18px;
  cursor: pointer;
  transition: all 0.25s ease;
}

.mode-btn.active {
  background: var(--accent);
  color: var(--bg-primary);
  border-radius: 9px;
}

/* ---- Timer Settings ---- */

.timer-settings {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 8px 20px;
  flex-shrink: 0;
  transition: opacity 0.3s ease, max-height 0.3s ease;
  max-height: 60px;
  overflow: hidden;
}

.timer-settings.hidden {
  opacity: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  pointer-events: none;
}

.time-option {
  background: var(--bg-secondary);
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.time-option.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(226, 183, 20, 0.1);
}

/* ---- Card Area ---- */

.card-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.key-card {
  background: linear-gradient(145deg, var(--bg-card), var(--bg-secondary));
  border-radius: var(--radius);
  padding: 96px 48px;
  text-align: center;
  width: 100%;
  max-width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: transform 0.3s ease, opacity 0.3s ease;
  will-change: transform, opacity;
}

.key-card.slide-out-left {
  animation: slideOutLeft 0.25s ease-in forwards;
}

.key-card.slide-out-right {
  animation: slideOutRight 0.25s ease-in forwards;
}

.key-card.slide-in {
  animation: slideIn 0.3s ease-out forwards;
}

@keyframes slideOutLeft {
  to {
    transform: translateX(-120%);
    opacity: 0;
  }
}

@keyframes slideOutRight {
  to {
    transform: translateX(120%);
    opacity: 0;
  }
}

@keyframes slideIn {
  from {
    transform: translateX(80px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.key-name {
  font-size: 256px;
  font-weight: 800;
  letter-spacing: 2px;
  line-height: 1;
}

/* ---- Progress Bar ---- */

.progress-bar-container {
  width: 80%;
  margin: 32px auto 0;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.progress-bar-container.visible {
  opacity: 1;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 100%;
  transform-origin: left;
  transition: none;
}

.countdown-text {
  font-size: 16px;
  color: var(--text-muted);
  margin-top: 12px;
  min-height: 22px;
  font-variant-numeric: tabular-nums;
}

/* ---- Swipe Hint ---- */

.swipe-hint {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px 0;
  flex-shrink: 0;
  transition: opacity 0.5s ease;
}

.swipe-hint.fade-out {
  opacity: 0;
}

/* ---- Footer ---- */

footer {
  display: flex;
  gap: 12px;
  padding: 12px 20px 20px;
  flex-shrink: 0;
}

.nav-btn {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 0;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.nav-btn:active {
  transform: scale(0.96);
  background: rgba(255, 255, 255, 0.08);
}

.nav-arrow {
  font-size: 22px;
  font-weight: 300;
  line-height: 1;
}

/* ---- Responsive ---- */

@media (max-height: 600px) {
  .key-card {
    padding: 48px 32px;
  }
  .key-name {
    font-size: 192px;
  }
}

@media (min-width: 481px) {
  footer {
    padding-bottom: 24px;
  }
}
