:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --dark-bg: #0f172a;
  --dark-card: #1e293b;
  --dark-border: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
}

/* Use border-box universally for predictable sizing */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
  background: var(--dark-bg);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

body {
  justify-content: flex-start;
  align-items: center;
  min-height: 100vh;
  overflow-x: hidden;
  padding-bottom: 70px;
}

header {
  text-align: center;
  padding: 2rem 1rem 1.5rem;
  width: 100%;
  background: linear-gradient(180deg, rgba(30,30,30,0.8) 0%, transparent 100%);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

h1 { 
  margin-bottom: 0.5rem; 
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

header p {
  font-size: 0.95rem;
  color: #aaa;
  margin: 0.5rem 0 1.5rem 0;
}

input[type="file"] {
  margin-top: 0.8rem;
  background: linear-gradient(135deg, #252525 0%, #1e1e1e 100%);
  border: 1px solid rgba(255,255,255,0.06);
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  cursor: pointer;
  color: #ddd;
  font-size: 0.95rem;
  width: 100%;
  max-width: 280px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

input[type="file"]:hover {
  border-color: rgba(255,255,255,0.12);
}

/* Base button style: consistent spacing, borders and accessible sizes */
button {
  margin: 0.35rem 0;
  background: linear-gradient(135deg, #222 0%, #151515 100%);
  border: 1px solid rgba(255,255,255,0.06);
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.98rem;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  font-weight: 600;
  line-height: 1.15;
  -webkit-tap-highlight-color: transparent;
}

button:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(99,102,241,0.12);
  border-color: var(--primary-dark);
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(255,255,255,0.12);
}

/* Specific control button positions */
#showMessageBtn {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 1000;
  padding: 10px 14px;
  font-size: 0.95rem;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--warning) 0%, #d97706 100%);
  color: #fff;
  display: none;
}

#showMessageBtn[aria-hidden="false"], #showMessageBtn.show {
  display: inline-block;
}

#startCustomBtn {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  border-color: var(--primary-dark);
  color: #fff;
  width: 100%;
}

@media (min-width: 700px) {
  #startCustomBtn { width: auto; padding: 0.8rem 1.2rem; }
}

a.download-btn {
  display: inline-block;
  margin-top: 0.8rem;
  padding: 0.7rem 1.4rem;
  background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
  color: #fff;
  text-decoration: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

a.download-btn:hover { 
  background: linear-gradient(135deg, #45a049 0%, #3d8b40 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(76, 175, 80, 0.4);
}

#messageBanner {
  color: #fff;
  padding: 1rem 1.2rem;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 95vw;
  width: auto;
  margin: 1.2rem auto 0.8rem auto;
  background: linear-gradient(135deg, rgba(255,152,0,0.15) 0%, rgba(255,87,34,0.1) 100%);
  border: 1px solid rgba(255,152,0,0.3);
  box-shadow: 0 2px 8px rgba(255,152,0,0.1);
}

#messageBanner p {
  margin: 0.3rem 0;
  font-size: 0.95rem;
}

#hideMessageBtn {
  margin-top: 0.5rem;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  border: none;
  background-color: #555;
  color: #fff;
  cursor: pointer;
}

#hideMessageBtn:hover { background-color: #777; }

#flashcardContainer {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  width: 100%;
  max-width: 1100px;
  padding: 1rem;
  box-sizing: border-box;
}

#createSection.hidden { display: none; }

#createSection {
  background: linear-gradient(135deg, #252525 0%, #1f1f1f 100%);
  padding: 2rem 1.5rem;
  border-radius: 16px;
  margin: 2rem auto 2rem auto;
  width: 100%;
  max-width: 480px;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  box-sizing: border-box;
  border: 1px solid rgba(255,255,255,0.05);
}

#createSection h2 {
  margin: 0 0 1.5rem 0;
  font-size: 1.5rem;
  text-align: center;
}

#createSection input,
#createSection button {
  width: 100%;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  padding: 0.7rem 1rem;
  margin: 0.6rem 0;
  border-radius: 8px;
  border: 1px solid #444;
  background: linear-gradient(135deg, #1a1a1a 0%, #151515 100%);
  color: #fff;
  font-size: 1rem;
  transition: all 0.3s ease;
}

#createSection input:focus {
  outline: none;
  border-color: #666;
  background: linear-gradient(135deg, #222 0%, #1a1a1a 100%);
  box-shadow: 0 0 0 3px rgba(76,175,80,0.1);
}

#newFlashcardsContainer {
  width: 100%;
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 1rem;
  padding: 0.5rem 0;
}

.flashcard-front, .flashcard-back {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #252525 0%, #1f1f1f 100%);
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  backface-visibility: hidden;
  text-align: center;
  font-size: clamp(0.9rem, 2vw, 1.2rem);
  line-height: 1.6;
  flex-direction: column;
  word-wrap: break-word;
  overflow-wrap: break-word;
  border: 1px solid rgba(255,255,255,0.05);
}

.flashcard-front p, .flashcard-back p {
  margin: 0;
  padding: 0;
}

.flashcard-back { 
  background: linear-gradient(135deg, #2a2a3e 0%, #1f2937 100%);
  transform: rotateY(180deg);
  border: 1px solid rgba(100,150,255,0.1);
}

.big-flashcard {
  perspective: 1000px;
  cursor: pointer;
  width: min(520px, 85vw);
  max-width: 90vw;
  height: 400px;
  position: relative;
  margin: 2rem auto 2rem auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.2s ease;
}

.big-flashcard:active {
  transform: scale(0.98);
}

#media-small-screen
@media (max-width: 600px) {
  .big-flashcard {
    width: 94vw;
    max-width: 94vw;
    min-width: 0;
    height: 260px;
    margin: 1rem auto;
  }
  .flashcard-front, .flashcard-back {
    font-size: 1.1rem;
    padding: 1rem;
  }
}

.flashcard-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 0.6s; }
.big-flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.answer-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
  box-sizing: border-box;
  padding: 0.75rem 0.5rem 0.5rem 0.5rem;
  margin-top: 1rem;
}

.correct-btn, .wrong-btn, .skip-btn {
  flex: 1 1 0;
  min-width: 0;
  font-size: 0.95rem;
  padding: 0.55rem 0.5rem;
  box-sizing: border-box;
  margin: 0;
  border: none;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  text-transform: none;
  letter-spacing: 0.2px;
}
.correct-btn { 
  background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
  box-shadow: 0 4px 12px rgba(76,175,80,0.3);
}
.correct-btn:hover, .correct-btn:active {
  background: linear-gradient(135deg, #45a049 0%, #3d8b40 100%);
  transform: translateY(-2px);
}
.wrong-btn { 
  background: linear-gradient(135deg, #F44336 0%, #da190b 100%);
  box-shadow: 0 4px 12px rgba(244,67,54,0.3);
}
.wrong-btn:hover, .wrong-btn:active {
  background: linear-gradient(135deg, #da190b 0%, #ba0000 100%);
  transform: translateY(-2px);
}
.skip-btn { 
  background: linear-gradient(135deg, #FF9800 0%, #F57C00 100%);
  box-shadow: 0 4px 12px rgba(255,152,0,0.3);
  color: #fff;
}
.skip-btn:hover, .skip-btn:active {
  background: linear-gradient(135deg, #F57C00 0%, #E65100 100%);
  transform: translateY(-2px);
}

#repeatIncorrectBtn {
  display: inline-block;
  margin-top: 0.9rem;
  width: auto;
  padding: 0.6rem 1rem;
  align-self: center;
}

/* Stack side-by-side on wider screens for easier selection */
@media (min-width: 600px) {
  .answer-buttons { flex-direction: row; gap: 0.8rem; }
  .answer-buttons .correct-btn, .answer-buttons .wrong-btn, .answer-buttons .skip-btn { padding: 0.9rem 0.6rem; }
}

footer {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100vw;
  min-height: 60px;
  background: linear-gradient(180deg, transparent 0%, rgba(15,15,15,0.95) 50%, #0f0f0f 100%);
  color: #888;
  text-align: center;
  font-size: 0.85rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-shadow: 0 -1px 8px rgba(0,0,0,0.3);
  padding: 0.8rem 0;
  margin: 0;
  border-top: 1px solid rgba(255,255,255,0.05);
}

footer div {
  margin: 0.3rem 0;
}

footer a.contact-btn { 
  color: #fff; 
  text-decoration: none; 
  border: 1px solid #555;
  padding: 0.4rem 1rem; 
  border-radius: 8px; 
  transition: all 0.3s ease;
  font-weight: 500;
}
footer a.contact-btn:hover { 
  background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
  color: #fff;
  border-color: #4CAF50;
  transform: translateY(-2px);
}

footer span.version { 
  display: inline-block; 
  margin-left: 0.8rem; 
  color: #666; 
  font-size: 0.75rem; 
}

/* Admin / Hacker panel trigger button */
.admin-btn {
  margin-left: 0.6rem;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.06);
  color: var(--text-primary);
  font-weight: 700;
  cursor: pointer;
}
.admin-btn:hover { background: rgba(255,255,255,0.02); transform: translateY(-1px); }

/* Keep the visible footer trigger hidden — require Numpad sequence to open the panel */
.admin-btn { display: none !important; }

/* Hacker Panel modal */
#hackerPanelOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 1rem;
}
#hackerPanel {
  width: 100%;
  max-width: 980px;
  max-height: 90vh;
  overflow: auto;
  background: linear-gradient(135deg, #0f172a 0%, #111827 100%);
  border: 1px solid rgba(255,255,255,0.07);
  color: var(--text-primary);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
#hackerPanel .panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
#hackerPanel .panel-title { font-weight: 800; font-size: 1.05rem; }
#hackerPanel .panel-close { background: transparent; border: none; color: var(--text-secondary); cursor: pointer; font-weight: 700; padding: 0.25rem 0.6rem; border-radius: 6px; }
#hackerPanel .panel-close:hover { color: var(--text-primary); background: rgba(255,255,255,0.02); }
#hackerPanel .panel-content { padding: 1rem 1.25rem 1.5rem 1.25rem; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, 'Roboto Mono', 'Courier New', monospace; font-size: 0.86rem; color: #dbeafe; }
#hackerPanel pre { white-space: pre-wrap; word-wrap: break-word; margin: 0 0 1rem 0; }
#hackerPanel .panel-actions { display:flex; gap:0.5rem; align-items:center; }
#hackerPanel .panel-actions button { padding: 0.45rem 0.7rem; font-weight:700; }


/* Enhanced responsive design for mobile and desktop */
@media (max-width: 600px) {
  html, body {
    font-size: 16px;
    overflow-x: hidden;
    overscroll-behavior: none;
    touch-action: manipulation;
    width: 100vw;
    max-width: 100vw;
    box-sizing: border-box;
  }

  header {
    padding: 1.5rem 1rem 1rem;
  }

  h1 {
    font-size: 1.8rem;
  }

  /* Make key containers fluid on small screens */
  #flashcardContainer,
  .big-flashcard,
  #createSection,
  #messageBanner {
    width: 94vw !important;
    max-width: 94vw !important;
    min-width: 0 !important;
    box-sizing: border-box;
    margin-left: auto;
    margin-right: auto;
  }

  .big-flashcard {
    height: 300px;
    margin: 1.5rem auto;
  }

  footer {
    width: 100vw !important;
    left: 0;
    bottom: 0;
    position: fixed;
    font-size: 0.75rem;
    min-height: 56px;
    padding: 0.4rem 0;
    box-shadow: 0 -1px 4px rgba(0,0,0,0.2);
  }
}

@media (min-width: 600px) and (max-width: 800px) {
  #createSection {
    max-width: 420px;
    padding: 1.5rem;
  }

  .big-flashcard {
    height: 350px;
  }
}

@media (min-width: 800px) {
  #createSection {
    max-width: 500px;
    padding: 2rem;
  }

  .big-flashcard {
    height: 400px;
  }
}

/* Improve touch targets for all buttons */
button, .download-btn, .contact-btn {
  /* don't force an overly large min-height; let padding control sizing */
  min-height: auto;
  touch-action: manipulation;
  font-weight: 500;
}
