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

:root {
  --color-primary: #1a73e8;
  --color-text: #202124;
  --color-text-secondary: #5f6368;
  --color-bg: #ffffff;
  --color-surface: #f8f9fa;
  --color-border: #e8eaed;
  --color-nav-bg: #ffffff;
  --nav-height: 56px;
  --header-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  position: relative;
}

/* Screens */
.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

.screen.active {
  display: flex;
}

.screen-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.screen-header h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--color-text);
}

.screen-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}

.placeholder-text {
  text-align: center;
  color: var(--color-text-secondary);
  margin-top: 40%;
  font-size: 16px;
}

/* Bottom Navigation */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--color-nav-bg);
  border-top: 1px solid var(--color-border);
  z-index: 100;
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--color-text-secondary);
  font-size: 11px;
  font-family: inherit;
  padding: 6px 0;
  min-height: 48px;
  transition: color 200ms ease;
  -webkit-tap-highlight-color: transparent;
}

.nav-tab.active {
  color: var(--color-primary);
}

.nav-tab svg {
  width: 24px;
  height: 24px;
}

.nav-tab span {
  font-weight: 500;
}

/* Back button */
.back-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text);
  padding: 4px;
  margin-right: 8px;
  display: flex;
  align-items: center;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}

.back-btn.hidden {
  display: none;
}

/* Section label */
.section-label {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
}

/* Pill buttons */
.pill-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  padding: 0 20px;
  border: 1px solid var(--color-border);
  border-radius: 24px;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 200ms ease, border-color 200ms ease;
  -webkit-tap-highlight-color: transparent;
}

.pill:active {
  background: var(--color-surface);
}

/* Class grid */
.class-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.class-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 56px;
  border: none;
  border-radius: 12px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 15px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 200ms ease;
  -webkit-tap-highlight-color: transparent;
}

.class-btn:active {
  background: var(--color-border);
}

/* Subject / Medium list rows */
.subject-list {
  display: flex;
  flex-direction: column;
}

.subject-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--color-bg);
  cursor: pointer;
  min-height: 48px;
  border-bottom: 1px solid var(--color-border);
  transition: background 200ms ease;
  -webkit-tap-highlight-color: transparent;
}

.subject-item:active {
  background: var(--color-surface);
}

.subject-item-name {
  font-size: 16px;
  color: var(--color-text);
}

.saved-item-meta {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.subject-item-text {
  flex: 1;
  min-width: 0;
}

.saved-delete-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-secondary);
  flex-shrink: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transition: color 200ms ease;
}

.saved-delete-btn:hover,
.saved-delete-btn:active {
  color: #d93025;
}

.subject-item-arrow {
  color: var(--color-text-secondary);
  flex-shrink: 0;
  margin-left: 12px;
}

/* Book detail */
.book-detail {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.book-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  background: var(--color-surface);
  border-radius: 12px;
}

.book-subject {
  font-size: 20px;
  font-weight: 600;
}

.book-meta {
  font-size: 14px;
  color: var(--color-text-secondary);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  padding: 0 24px;
  border: none;
  border-radius: 24px;
  background: var(--color-primary);
  color: #ffffff;
  font-size: 16px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 200ms ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:active {
  opacity: 0.8;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  padding: 0 24px;
  border: 1.5px solid var(--color-primary);
  border-radius: 24px;
  background: transparent;
  color: var(--color-primary);
  font-size: 16px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 200ms ease, color 200ms ease, border-color 200ms ease;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

.btn-secondary:active {
  background: rgba(26, 115, 232, 0.08);
}

.btn-secondary.downloading {
  color: var(--color-text-secondary);
  border-color: var(--color-border);
  pointer-events: none;
}

.download-progress {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: rgba(26, 115, 232, 0.1);
  transition: width 150ms ease;
  pointer-events: none;
}

.btn-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 16px;
  border: none;
  border-radius: 20px;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: color 200ms ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-remove:active {
  color: var(--color-text);
}

/* Settings */
.settings-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--color-border);
}

.settings-section:last-child {
  border-bottom: none;
}

.settings-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  min-height: 48px;
}

.settings-item-value {
  color: var(--color-text-secondary);
}

.settings-disclaimer {
  color: var(--color-text-secondary);
  font-size: 14px;
  line-height: 1.5;
}

/* Tablet layout */
@media (min-width: 768px) {
  .screen-content {
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    padding: 24px 16px;
  }

  #bottom-nav {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 16px 16px 0 0;
  }
}
