/* ===== CSS Variables (ported from Python COLORS dict) ===== */
:root {
  --bg: #121212;
  --card-bg: #1E1E1E;
  --card-border: #333333;
  --header-bg: #0D1117;
  --text-main: #E0E0E0;
  --text-dim: #B0B0B0;
  --accent-green: #00C853;
  --accent-red: #D32F2F;
  --accent-blue: #2979FF;
  --input-bg: #252525;
  --graph-line: #BB86FC;
  --list-bg: #252525;
  --list-select: #2979FF;
  --one-bee: #FFD700;
  --two-bee: #FF8A65;
  --three-bee: #D32F2F;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  background-color: var(--bg);
  background-image: url('/images/bg.webp');
  background-position: center;
  background-size: cover;
  background-attachment: fixed;
  background-repeat: no-repeat;
  color: var(--text-main);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: -webkit-fill-available;
}

/* ===== Floating Card (matches desktop layout) ===== */
#app {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  padding: 24px;
}

.app-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  width: 100%;
  max-width: 950px;
  height: 750px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* ===== Screens ===== */
.screen { display: none; flex: 1; flex-direction: column; overflow-y: auto; }
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ===== Login Screen ===== */
#screen-login,
#screen-pending {
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}

.login-container {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-logo {
  width: 120px;
  height: 120px;
  object-fit: contain;
  margin-bottom: 16px;
}

.login-title {
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-dim);
  margin-bottom: 32px;
  font-size: 14px;
}

.login-buttons { display: flex; flex-direction: column; gap: 12px; }

.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 13px;
  margin: 4px 0;
}
.login-divider::before, .login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--card-border);
}

.email-form { display: flex; flex-direction: column; gap: 10px; }
.email-form input {
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 12px 16px;
  color: var(--text-main);
  font-size: 15px;
  outline: none;
}
.email-form input:focus { border-color: var(--accent-blue); }

.error-text { color: var(--accent-red); font-size: 13px; margin-top: 8px; min-height: 20px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 20px;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-user-select: none;
  user-select: none;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--accent-blue); color: #fff; }
.btn-secondary { background: #444; color: #fff; }
.btn-danger { background: var(--accent-red); color: #fff; }
.btn-text { background: none; color: var(--accent-blue); padding: 8px; }
.btn-google {
  background: #fff;
  color: #333;
  font-size: 15px;
  padding: 12px;
  border-radius: 8px;
}
.btn-nav {
  background: #616161;
  color: #fff;
  padding: 6px 16px;
  font-size: 13px;
}
.btn-nav-accent { background: var(--accent-blue); }
.btn-icon {
  background: none;
  color: var(--text-dim);
  font-size: 20px;
  padding: 4px 8px;
  border: none;
  cursor: pointer;
}
.btn-audio {
  background: #333;
  color: #fff;
  padding: 8px 16px;
  font-size: 13px;
  border-radius: 6px;
}

/* ===== Header ===== */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--header-bg);
  padding: 10px 20px;
  flex-shrink: 0;
  gap: 12px;
  flex-wrap: wrap;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-logo {
  width: 50px;
  height: 50px;
  object-fit: contain;
}

.header-score {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-green);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.select-difficulty {
  background: var(--input-bg);
  color: var(--text-main);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
}

/* ===== Start Screen ===== */
.start-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px 20px;
  text-align: center;
}

.start-title {
  font-size: 36px;
  font-weight: 700;
  color: #fff;
}

.start-subtitle {
  color: var(--text-dim);
  margin-top: 8px;
  font-size: 14px;
}

.start-spacer { flex: 1; min-height: 40px; }

.btn-start {
  background: var(--accent-green);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  padding: 20px 60px;
  border-radius: 12px;
  margin-bottom: 40px;
}

/* ===== Game Screen ===== */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  padding: 24px 20px;
}

.audio-label {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
}

.audio-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 32px;
  flex-wrap: wrap;
  justify-content: center;
}

.input-label {
  color: #aaa;
  font-size: 14px;
  margin-bottom: 8px;
}

.spelling-input {
  background: var(--input-bg);
  border: 2px solid var(--card-border);
  border-radius: 10px;
  color: #fff;
  font-size: 36px;
  text-align: center;
  padding: 12px 20px;
  width: 100%;
  max-width: 500px;
  outline: none;
  caret-color: #fff;
}
.spelling-input:focus { border-color: var(--accent-blue); }

.btn-check {
  margin-top: 24px;
  font-size: 16px;
  padding: 14px 40px;
}

.game-footer {
  margin-top: auto;
  padding-top: 20px;
  width: 100%;
  display: flex;
  justify-content: flex-start;
}

/* ===== Review Screen ===== */
.review-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  padding: 24px 20px;
  overflow-y: auto;
}

.review-status { font-size: 20px; font-weight: 700; }
.review-status.correct { color: var(--accent-green); }
.review-status.incorrect { color: var(--accent-red); }

.review-word {
  font-size: 42px;
  font-weight: 700;
  color: #fff;
  margin: 8px 0;
  word-break: break-word;
  text-align: center;
}

.review-alternates {
  color: var(--accent-blue);
  font-style: italic;
  font-size: 13px;
  min-height: 20px;
}

.review-stats {
  color: var(--text-dim);
  font-style: italic;
  font-size: 12px;
  margin-top: 4px;
  min-height: 18px;
}

.review-details {
  background: var(--input-bg);
  border-radius: 10px;
  padding: 20px;
  margin: 20px 0;
  width: 100%;
  max-width: 600px;
  font-size: 15px;
  line-height: 1.6;
  overflow-y: auto;
  max-height: 300px;
}

.review-detail-section { margin-bottom: 16px; }
.review-detail-section:last-child { margin-bottom: 0; }
.review-detail-label {
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 2px;
}
.review-detail-text {
  color: var(--text-main);
}

.btn-next {
  font-size: 16px;
  padding: 14px 40px;
}

/* ===== Dictionary Screen ===== */
.dictionary-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 16px 20px;
  overflow: hidden;
}

.dict-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.dict-search {
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 8px 14px;
  color: var(--text-main);
  font-size: 14px;
  flex: 1;
  min-width: 150px;
  outline: none;
}
.dict-search:focus { border-color: var(--accent-blue); }

.dict-body {
  display: flex;
  flex: 1;
  gap: 16px;
  overflow: hidden;
}

.dict-list-panel {
  width: 240px;
  flex-shrink: 0;
  overflow-y: auto;
  background: var(--list-bg);
  border-radius: 8px;
}

.dict-word-list {
  list-style: none;
  padding: 4px;
}

.dict-word-list li {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  transition: background 0.1s;
}
.dict-word-list li:hover { background: #333; }
.dict-word-list li.selected { background: var(--list-select); color: #fff; }

.dict-detail-panel {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 20px;
  overflow-y: auto;
}

.dict-word-title {
  font-size: 26px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 10px;
  word-break: break-word;
}

.btn-dict-listen { margin-bottom: 16px; }

.dict-details {
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  color: #eee;
}

.dict-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 12px;
}

/* ===== Analytics Screen ===== */
.analytics-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
}

.kpi-cards {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.kpi-card {
  background: var(--list-bg);
  border-radius: 10px;
  padding: 16px;
  flex: 1;
  min-width: 120px;
  text-align: left;
}
.kpi-card .kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
}
.kpi-card .kpi-value {
  font-size: 28px;
  font-weight: 700;
  margin: 4px 0;
}
.kpi-card .kpi-attempts {
  font-size: 11px;
  color: #777;
}

.graph-section { margin-bottom: 20px; }

.graph-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.graph-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.perf-graph {
  width: 100%;
  height: 180px;
  background: var(--card-bg);
  border-radius: 8px;
}

.missed-section { flex: 1; min-height: 0; }
.missed-title {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 10px;
}

.missed-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.missed-table th {
  background: #444;
  color: #fff;
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.missed-table th:hover { background: #555; }
.missed-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #333;
}
.missed-table tbody tr:hover { background: #2a2a2a; }

.btn-reset-word {
  background: var(--accent-red);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 600;
}

.analytics-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 12px;
}

/* ===== Admin Screen ===== */
.admin-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
}

.admin-section-title {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 10px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.admin-table th {
  background: #444;
  color: #fff;
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
}
.admin-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #333;
}
.admin-table tbody tr:hover { background: #2a2a2a; }

.btn-admin-action {
  background: var(--accent-green);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 4px 12px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 600;
}
.btn-admin-deny {
  background: var(--accent-red);
}

.admin-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 12px;
}

/* ===== Loading spinner ===== */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--text-dim);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #app { padding: 0; align-items: stretch; }
  .app-card {
    max-width: none;
    height: 100vh;
    height: -webkit-fill-available;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }

  .header-right { gap: 6px; }
  .btn-nav { padding: 6px 10px; font-size: 12px; }
  .header-score { font-size: 14px; }
  .start-title { font-size: 26px; }
  .btn-start { font-size: 18px; padding: 16px 40px; }
  .spelling-input { font-size: 28px; }
  .review-word { font-size: 32px; }

  .dict-body { flex-direction: column; }
  .dict-list-panel { width: 100%; max-height: 200px; }

  .kpi-cards { flex-wrap: wrap; }
  .kpi-card { min-width: calc(50% - 8px); }
}

@media (max-width: 480px) {
  #app-header { padding: 8px 12px; }
  .header-logo { width: 36px; height: 36px; }
  .start-title { font-size: 22px; }
  .spelling-input { font-size: 24px; }
  .review-word { font-size: 26px; }
  .audio-buttons { gap: 6px; }
  .btn-audio { padding: 6px 10px; font-size: 12px; }
}

/* ===== PWA safe area ===== */
@supports (padding-top: env(safe-area-inset-top)) {
  #app-header { padding-top: calc(10px + env(safe-area-inset-top)); }
  body { padding-bottom: env(safe-area-inset-bottom); }
}
