/* Sleep-themed calculator styles with enhanced visual design */

/* Main layout and theme variables */
:root {
  --bg: linear-gradient(135deg, #f6f8fc 0%, #f8fbff 100%);
  --bg-radial: radial-gradient(circle at 20% 20%, rgba(59,130,246,0.08) 0%, transparent 40%),
                radial-gradient(circle at 80% 80%, rgba(139,92,246,0.06) 0%, transparent 40%);
  --card: rgba(255, 255, 255, 0.78);
  --card-backdrop: blur(24px);
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --border: rgba(148, 163, 184, 0.2);
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.08), 0 0 1px rgba(0, 0, 0, 0.05);
  --shadow-hover: 0 20px 40px rgba(0, 0, 0, 0.12), 0 0 1px rgba(0, 0, 0, 0.05);
  color-scheme: light;
}

/* Global reset and viewport fixes */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-radial);
  pointer-events: none;
  z-index: -1;
}

.app-container {
  max-width: 480px;
  margin: 0 auto;
  display: block;
  background: transparent;
}

/* Header styles with improved breathing space */
.app-header {
  padding: 32px 16px 20px;
  text-align: center;
  position: relative;
}

.header-content {
  margin-bottom: 16px;
  position: relative;
  z-index: 2;
}

.app-title {
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 8px 0;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.app-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.5;
  opacity: 0.9;
}

.theme-control {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  position: relative;
  z-index: 2;
}

/* Main content styles */
.app-main {
  padding: 0 16px 16px;
  position: relative;
  z-index: 2;
}

.calc-card {
  background: var(--card);
  backdrop-filter: var(--card-backdrop);
  border-radius: 24px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
  width: 100%;
  transition: box-shadow 0.3s ease, transform 0.2s ease;
  position: relative;
  overflow: hidden;
}

.calc-card::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  transform: rotate(30deg);
  pointer-events: none;
  z-index: -1;
}

.calc-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

/* Mode switcher styles */
.mode-switcher {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.mode-btn {
  flex: 1;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

.mode-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.mode-btn:not(.active):hover {
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(148, 163, 184, 0.3);
}

.mode-btn:not(.active):active {
  background: rgba(241, 245, 249, 0.8);
}

/* Input group styles */
.input-group {
  margin-bottom: 24px;
}

.input-field {
  width: 100%;
  padding: 18px;
  font-size: 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  outline: none;
  transition: all 0.2s ease;
  box-sizing: border-box;
  min-height: 56px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  color: var(--text-primary);
}

.input-field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
  background: rgba(255, 255, 255, 0.85);
}

.input-hint {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 8px;
  margin-bottom: 2px;
  opacity: 0.8;
}

/* Primary button styles with subtle gradient */
.primary-btn {
  width: 100%;
  padding: 20px;
  border: none;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  margin-bottom: 24px;
  min-height: 60px;
  position: relative;
  overflow: hidden;
}

.primary-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s;
}

.primary-btn:hover::before {
  left: 100%;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 25px rgba(59, 130, 246, 0.3);
}

.primary-btn:active {
  transform: translateY(0);
  box-shadow: 0 6px 15px rgba(59, 130, 246, 0.25);
}

/* Result container styles */
.result-container {
  margin-top: 0;
  width: 100%;
}

.result-wrapper {
  width: 100%;
}

.result-section {
  margin-bottom: 28px;
}

.result-label {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 16px 0;
  padding: 0;
  display: flex;
  align-items: center;
  position: relative;
}

.result-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
  margin-left: 12px;
  opacity: 0.6;
}

/* Best result card */
.best-result-card {
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 16px;
  text-align: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(12px);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.best-result-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
}

.best-time {
  font-size: 36px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.best-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.5;
}

/* Other results */
.other-results {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.other-result-item {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  backdrop-filter: blur(10px);
}

.other-result-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.06);
}

.other-time {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.other-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0;
  text-align: center;
  line-height: 1.4;
}

/* iOS segmented control for theme */
.ios-seg {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 4px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.15);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
  user-select: none;
  width: 104px;
  backdrop-filter: blur(10px);
}

.ios-seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.ios-seg label {
  min-width: 42px;
  padding: 7px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.ios-seg input:checked + label {
  background: rgba(255, 255, 255, 0.92);
  color: var(--text-primary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.ios-seg input:focus-visible + label {
  outline: 3px solid rgba(59, 130, 246, 0.3);
  outline-offset: 2px;
}

/* Intro section styles */
.intro-section {
  max-width: 480px; /* 与FAQ和主容器保持一致 */
  margin: 32px auto;
  padding: 0 16px;
  width: 100%;
}

.intro-content {
  background: var(--card);
  backdrop-filter: var(--card-backdrop);
  border-radius: 24px;
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  line-height: 1.7;
}

.intro-content h2 {
  color: var(--text-primary);
  font-size: 22px;
  margin: 0 0 16px;
  font-weight: 600;
  line-height: 1.4;
}

.intro-content h3 {
  color: var(--text-primary);
  font-size: 18px;
  margin: 24px 0 12px;
  font-weight: 600;
  line-height: 1.5;
}

.intro-content p {
  color: var(--text-secondary);
  font-size: 15px;
  margin: 0 0 16px;
  line-height: 1.7;
}

/* Mobile responsiveness for intro section */
@media (max-width: 480px) {
  .intro-section {
    margin: 28px auto;
    padding: 0 12px;
  }
  
  .intro-content {
    padding: 24px;
  }
}

/* Footer styles with refined appearance */
.app-footer {
  background: rgba(255, 255, 255, 0.4);
  color: var(--text-secondary);
  padding: 28px 16px;
  text-align: center;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
  backdrop-filter: blur(12px);
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  margin-top: 32px;
  border-radius: 24px 24px 0 0;
}

.footer-content {
  max-width: 920px;
  margin: 0 auto;
}

.footer-info {
  margin-bottom: 16px;
}

.footer-text {
  font-size: 14px;
  color: var(--text-primary);
  margin: 0 0 6px 0;
  opacity: 0.9;
}

.footer-note {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0;
  opacity: 0.7;
}

.footer-links {
  margin-bottom: 12px;
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--accent);
  margin: 0 4px;
  text-decoration: none;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 12px;
  transition: background 0.15s ease, text-decoration 0.15s ease, color 0.15s ease;
}

.footer-links a:hover {
  text-decoration: none;
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent-hover);
}

.footer-links a:focus-visible {
  outline: 2px solid rgba(59, 130, 246, 0.35);
  outline-offset: 2px;
  background: rgba(59, 130, 246, 0.1);
}

.footer-copyright {
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.7;
}

/* Policy Modal styles */
.policy-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
}

.policy-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(4px);
}

.policy-panel {
  position: relative;
  width: min(720px, calc(100% - 24px));
  max-height: min(76vh, 720px);
  margin: 8vh auto 0;
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  backdrop-filter: var(--card-backdrop);
}

.policy-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.policy-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}

.policy-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
  background: rgba(148, 163, 184, 0.1);
  cursor: pointer;
  font-size: 20px;
  line-height: 36px;
  color: var(--text-primary);
  transition: background 0.2s ease;
}

.policy-close:hover {
  background: rgba(148, 163, 184, 0.2);
}

.policy-close:focus-visible {
  outline: 2px solid rgba(59, 130, 246, 0.35);
  outline-offset: 2px;
}

.policy-body {
  padding: 18px 20px 22px;
  overflow: auto;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.7;
  text-align: left;
}

.policy-body h4 {
  margin: 16px 0 10px;
  font-size: 15px;
  color: var(--text-primary);
  font-weight: 600;
}

.policy-body p {
  margin: 10px 0;
}

.policy-body ul {
  margin: 10px 0 10px 18px;
}

/* Explanation card styles */
.explanation-card {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  backdrop-filter: blur(10px);
}

.explanation-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 12px 0;
}

.explanation-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0 0 12px 0;
}

.explanation-note {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0;
  font-style: italic;
  opacity: 0.7;
}

/* Share button styles */
.share-btn {
  width: 100%;
  padding: 20px;
  border: none;
  border-radius: 18px;
  background: linear-gradient(135deg, #5fb25f 0%, #4a9e4a 100%);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  min-height: 60px;
  position: relative;
  overflow: hidden;
}

.share-btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s;
}

.share-btn:hover::before {
  left: 100%;
}

.share-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 25px rgba(95, 178, 95, 0.3);
}

.share-btn:active {
  transform: translateY(0);
  box-shadow: 0 6px 15px rgba(95, 178, 95, 0.25);
}

/* Dark mode overrides */
html.dark {
  color-scheme: dark;
  --bg: linear-gradient(135deg, #0b1120 0%, #0f172a 100%);
  --bg-radial: radial-gradient(circle at 20% 20%, rgba(96, 165, 250, 0.06) 0%, transparent 40%),
                radial-gradient(circle at 80% 80%, rgba(124, 58, 237, 0.04) 0%, transparent 40%);
  --card: rgba(15, 23, 42, 0.78);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --border: rgba(148, 163, 184, 0.15);
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.25), 0 0 1px rgba(255, 255, 255, 0.05);
  --shadow-hover: 0 20px 40px rgba(0, 0, 0, 0.35), 0 0 1px rgba(255, 255, 255, 0.05);
}

html.dark .app-footer {
  background: rgba(15, 23, 42, 0.5);
  border-top-color: rgba(148, 163, 184, 0.15);
  color: var(--text-secondary);
}

html.dark .footer-text {
  color: var(--text-primary);
}

html.dark .footer-links a {
  color: var(--accent);
}

html.dark .footer-links a:hover {
  background: rgba(96, 165, 250, 0.1);
  color: var(--accent-hover);
}

html.dark .input-field {
  background: rgba(15, 23, 42, 0.6);
  border-color: var(--border);
  color: var(--text-primary);
}

html.dark .input-field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.2);
  background: rgba(15, 23, 42, 0.8);
}

html.dark .calc-card {
  background: var(--card);
  box-shadow: var(--shadow);
}

html.dark .calc-card::before {
  background: radial-gradient(circle, rgba(255,255,255,0.03) 0%, transparent 70%);
}

html.dark .mode-btn {
  background: rgba(15, 23, 42, 0.6);
  color: var(--text-primary);
  border-color: var(--border);
}

html.dark .mode-btn:not(.active):hover {
  background: rgba(30, 41, 59, 0.6);
  border-color: rgba(148, 163, 184, 0.25);
}

html.dark .mode-btn:not(.active):active {
  background: rgba(30, 41, 59, 0.8);
}

html.dark .mode-btn.active {
  box-shadow: 0 4px 12px rgba(96, 165, 250, 0.3);
}

html.dark .best-result-card {
  background: rgba(15, 23, 42, 0.8);
  border-color: rgba(148, 163, 184, 0.15);
}

html.dark .other-result-item {
  background: rgba(15, 23, 42, 0.6);
  border-color: var(--border);
}

html.dark .explanation-card {
  background: rgba(15, 23, 42, 0.6);
  border-color: var(--border);
}

html.dark .policy-panel {
  background: var(--card);
}

html.dark .policy-body {
  color: var(--text-secondary);
}

html.dark .policy-head {
  border-bottom-color: var(--border);
}

html.dark .policy-title {
  color: var(--text-primary);
}

html.dark .policy-close {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-primary);
}

html.dark .policy-close:hover {
  background: rgba(148, 163, 184, 0.2);
}

html.dark .policy-mask {
  background: rgba(0, 0, 0, 0.7);
}

html.dark .result-label::after {
  background: var(--border);
}

/* Dark segmented */
html.dark .ios-seg {
  background: rgba(148, 163, 184, 0.15);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

html.dark .ios-seg label {
  color: var(--text-secondary);
}

html.dark .ios-seg input:checked + label {
  background: rgba(15, 23, 42, 0.92);
  color: var(--text-primary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* Mobile responsive styles */
@media (max-width: 480px) {
  .app-container {
    max-width: 100%;
  }
  
  .app-header {
    padding: 24px 16px 16px;
  }
  
  .app-title {
    font-size: 24px;
  }
  
  .app-subtitle {
    font-size: 14px;
  }
  
  .app-main {
    padding: 0 12px 12px;
  }
  
  .calc-card {
    padding: 26px 20px;
    border-radius: 22px;
  }
  
  .mode-switcher {
    gap: 8px;
    margin-bottom: 20px;
  }
  
  .mode-btn {
    padding: 14px;
    font-size: 14px;
    min-height: 50px;
  }
  
  .input-field {
    padding: 16px;
    font-size: 16px;
    min-height: 54px;
  }
  
  .input-hint {
    font-size: 13px;
  }
  
  .primary-btn {
    padding: 18px;
    font-size: 16px;
    min-height: 56px;
  }
  
  .best-time {
    font-size: 32px;
  }
  
  .best-desc {
    font-size: 13px;
  }
  
  .other-time {
    font-size: 20px;
  }
  
  .other-desc {
    font-size: 12px;
  }
  
  .app-footer {
    padding: 24px 12px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    border-radius: 20px 20px 0 0;
  }
  
  .footer-text {
    font-size: 13px;
  }
  
  .footer-links {
    gap: 10px;
  }
  
  .footer-links a {
    font-size: 12px;
    padding: 5px 8px;
  }
  
  .footer-copyright {
    font-size: 11px;
  }
  
  .explanation-card {
    padding: 18px;
  }
  
  .share-btn {
    padding: 18px;
    min-height: 56px;
  }
}

@media (max-width: 768px) {
  .app-title {
    font-size: 26px;
  }
  
  .app-subtitle {
    font-size: 15px;
  }
  
  .calc-card {
    padding: 30px 22px;
  }
  
  .mode-btn {
    padding: 15px;
    font-size: 15px;
    min-height: 52px;
  }
  
  .input-field {
    padding: 17px;
    min-height: 56px;
  }
  
  .primary-btn {
    padding: 19px;
    min-height: 58px;
  }
  
  .best-time {
    font-size: 34px;
  }
  
  .app-footer {
    padding: 26px 14px;
    padding-bottom: calc(26px + env(safe-area-inset-bottom, 0px));
  }
}