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

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #16213e;
  --text-primary: #ffffff;
  --text-secondary: #b8b8b8;
  --text-muted: #6b6b6b;
  --accent: #4a9eff;
  --accent-hover: #3a8eef;
  --danger: #ff4757;
  --success: #2ed573;
  --orp-highlight: #ff6b6b;
  --font-size-reader: 48px;
  --transition: 0.2s ease;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

.high-contrast {
  --text-primary: #ffffff;
  --text-secondary: #e0e0e0;
  --bg-primary: #000000;
  --bg-secondary: #0a0a0a;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Screen Management */
.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--safe-top) 0 var(--safe-bottom) 0;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* Home Screen */
#home-screen {
  padding: calc(var(--safe-top) + 1.5rem) 1.5rem calc(var(--safe-bottom) + 1.5rem);
}

.home-header {
  text-align: center;
  margin-bottom: 2rem;
}

.home-header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent) 0%, #a855f7 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

.tagline {
  color: var(--text-secondary);
  font-size: 1rem;
}

.home-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
}

.home-footer {
  display: flex;
  justify-content: center;
  padding-top: 1rem;
}

/* Buttons */
.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  width: 100%;
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.start-btn {
  background: var(--accent);
  color: white;
}

.start-btn:not(:disabled):hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

.resume-btn {
  background: var(--success);
  color: white;
  flex-direction: column;
  gap: 0.25rem;
}

.resume-btn .btn-sub {
  font-size: 0.8rem;
  font-weight: 400;
  opacity: 0.9;
}

.upload-btn {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 2px dashed var(--text-muted);
}

.upload-btn:hover {
  border-color: var(--accent);
  background: var(--bg-tertiary);
}

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

.icon-btn {
  background: var(--bg-secondary);
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.back-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.danger-btn {
  background: transparent;
  border: 2px solid var(--danger);
  color: var(--danger);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  width: 100%;
}

.danger-btn:hover {
  background: var(--danger);
  color: white;
}

/* Input Section */
.input-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.input-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.text-input {
  width: 100%;
  padding: 1rem;
  background: var(--bg-secondary);
  border: 2px solid transparent;
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  min-height: 120px;
  transition: border-color var(--transition);
}

.text-input:focus {
  outline: none;
  border-color: var(--accent);
}

.text-input::placeholder {
  color: var(--text-muted);
}

/* History Section */
.history-section {
  margin-top: 1rem;
}

.history-section h3 {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  background: var(--bg-secondary);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-item:hover {
  background: var(--bg-tertiary);
}

.history-item-title {
  font-size: 0.9rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.history-item-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Samples Section */
.samples-section {
  margin-top: 0.5rem;
}

.samples-section h3 {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
}

.samples-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.sample-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  flex: 1 1 calc(50% - 0.5rem);
  min-width: 140px;
  max-width: 200px;
}

.sample-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent);
}

.sample-btn-lang {
  font-size: 0.7rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.2rem;
}

.sample-btn-title {
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sample-btn-author {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* Settings Screen */
#settings-screen {
  background: var(--bg-primary);
}

.settings-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: calc(var(--safe-top) + 1rem) 1rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--bg-tertiary);
}

.settings-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.settings-content {
  flex: 1;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.setting-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.setting-label span:first-child {
  font-weight: 500;
  color: var(--text-primary);
}

.setting-value {
  font-size: 0.9rem;
  color: var(--accent);
  font-weight: 600;
}

.setting-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  width: 100%;
}

.setting-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  outline: none;
}

.setting-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform var(--transition);
}

.setting-slider::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

.setting-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.setting-range {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Toggle Switch */
.toggle-group {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.toggle-group .setting-label {
  flex: 1;
  flex-direction: column;
  align-items: flex-start;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-tertiary);
  transition: var(--transition);
  border-radius: 28px;
}

.toggle-slider::before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: var(--transition);
  border-radius: 50%;
}

.toggle input:checked + .toggle-slider {
  background-color: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(24px);
}

/* Reader Screen */
#reader-screen {
  background: #000000;
  padding: 0;
  position: relative;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.reader-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  position: relative;
}

.reader-word {
  font-size: var(--font-size-reader);
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  line-height: 1.3;
  max-width: 90vw;
  word-break: break-word;
}

.reader-word .orp {
  color: var(--orp-highlight);
}

.reader-progress {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 2rem);
  left: 2rem;
  right: 2rem;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.1s linear;
}

.reader-paused {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-secondary);
  pointer-events: none;
}

.reader-paused span {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  margin-bottom: 0.5rem;
}

.reader-paused small {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.reader-controls {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 4rem);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1rem;
}

.control-btn {
  background: var(--bg-secondary);
  border: none;
  color: var(--text-primary);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.control-btn:hover {
  background: var(--bg-tertiary);
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 2rem);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 1rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s ease;
  z-index: 1000;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: var(--danger);
}

.toast.success {
  background: var(--success);
}

/* iOS Install Prompt */
.ios-install {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  padding: calc(1rem + var(--safe-bottom)) 1rem 1rem;
  z-index: 1001;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.ios-install-content {
  max-width: 400px;
  margin: 0 auto;
  text-align: center;
  position: relative;
}

.ios-install-content p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.ios-install-content strong {
  color: var(--text-primary);
}

.ios-install-close {
  position: absolute;
  top: -0.5rem;
  right: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
}

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

/* Responsive Adjustments */
@media (max-width: 360px) {
  .home-header h1 {
    font-size: 2rem;
  }

  .action-btn {
    padding: 0.875rem 1.25rem;
    font-size: 0.9rem;
  }
}

@media (min-height: 800px) {
  .home-content {
    gap: 1.5rem;
  }

  .text-input {
    min-height: 150px;
  }
}

/* Prevent zoom on iOS */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  select,
  textarea,
  input[type="text"] {
    font-size: 16px;
  }
}

/* Animation for screen transitions */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.screen.active {
  animation: fadeIn 0.2s ease;
}
