:root {
  --bg: #111111;
  --panel: #1d1d1d;
  --panel-light: #272727;
  --text: #f5f5f5;
  --muted: #aaa;
  --accent: #ffcc66;
  --danger: #ff5a5a;
  --success: #58d68d;
  --border: #393939;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #26211a 0, var(--bg) 44%);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

body.dragging { overflow: hidden; }

header {
  padding: 24px 28px 12px;
  display: grid;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: -0.04em;
  text-align: center;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.controls {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  width: 100%;
}

#flashcardModeBtn {
  grid-column: 1;
  justify-self: start;
}

#matchModeBtn {
  grid-column: 2;
  justify-self: start;
}

#categorySelect {
  grid-column: 4;
  justify-self: end;
}

#switchLanguageBtn {
  grid-column: 5;
  justify-self: end;
}

#flashcardModeBtn {
  grid-column: 1;
  justify-self: start;
}

#matchModeBtn {
  grid-column: 2;
  justify-self: start;
}

#categorySelect {
  grid-column: 4;
  justify-self: end;
}

#switchLanguageBtn {
  grid-column: 5;
  justify-self: end;
}

button,
select,
label.file-label {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

button:hover,
select:hover,
label.file-label:hover {
  background: var(--panel-light);
  border-color: #555;
}

button:active,
label.file-label:active { transform: scale(0.97); }

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

input[type="file"] { display: none; }

main {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 12px 28px 36px;
}

.app-shell {
  width: min(860px, 100%);
  display: grid;
  gap: 18px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  background: rgba(29, 29, 29, 0.86);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px;
  text-align: center;
  min-width: 0;
}

.stat strong {
  display: block;
  font-size: 22px;
  margin-bottom: 2px;
  overflow-wrap: anywhere;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  overflow-wrap: anywhere;
}

.study-zone {
  min-height: 450px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 30px;
  background: rgba(255,255,255,0.025);
  padding: 28px;
  position: relative;
}

.empty-state {
  text-align: center;
  max-width: 580px;
  color: var(--muted);
  line-height: 1.5;
}

.empty-state strong { color: var(--text); }

.empty-state code {
  background: #292929;
  border: 1px solid #3d3d3d;
  border-radius: 7px;
  padding: 2px 6px;
  color: var(--accent);
}

.flashcard {
  width: min(520px, 92vw);
  min-height: 300px;
  border-radius: 32px;
  background: linear-gradient(145deg, #f8f4ea, #d7cdbd);
  color: #111;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 36px;
  cursor: pointer;
  box-shadow: 0 28px 80px rgba(0,0,0,0.45);
  user-select: none;
  transform-style: preserve-3d;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.flashcard:hover {
  transform: translateY(-3px);
  box-shadow: 0 34px 90px rgba(0,0,0,0.55);
}

.card-content {
  display: grid;
  gap: 14px;
}

.card-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #665f55;
  font-weight: 700;
}

.card-main.hindi {
  font-size: clamp(54px, 9vw, 92px);
  line-height: 1.05;
  font-weight: 750;
}

.card-main.english {
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1.1;
  font-weight: 750;
}

.card-sub {
  color: #665f55;
  font-size: 15px;
}

.action-row {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
}

.grade-btn {
  width: 76px;
  height: 60px;
  border-radius: 20px;
  font-size: 28px;
  font-weight: 800;
  border: none;
}

.wrong {
  background: rgba(255,90,90,0.14);
  color: var(--danger);
  border: 1px solid rgba(255,90,90,0.35);
}

.right {
  background: rgba(88,214,141,0.14);
  color: var(--success);
  border: 1px solid rgba(88,214,141,0.35);
}

.status-line {
  min-height: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.danger-text { color: var(--danger); }

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  place-items: center;
  background: rgba(0, 0, 0, 0.76);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

body.dragging .drop-overlay { display: grid; }

.drop-overlay div {
  width: min(520px, calc(100vw - 48px));
  min-height: 220px;
  border: 2px dashed var(--accent);
  border-radius: 32px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
  background: rgba(29, 29, 29, 0.92);
}

.drop-overlay strong { font-size: 28px; }
.drop-overlay span { color: var(--muted); }

@media (max-width: 680px) {
  header { padding: 20px 10px 8px; }
  main { padding: 8px 10px 28px; }

  .controls {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }

  #flashcardModeBtn {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
  }

  #matchModeBtn {
    grid-column: 1;
    grid-row: 2;
    justify-self: start;
  }

#categorySelect {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  max-width: min(44vw, 220px);
}

#switchLanguageBtn {
  grid-column: 2;
  grid-row: 2;
  justify-self: end;
}

#appRequestLanguageBtn {
  grid-column: 2;
  grid-row: 3;
  justify-self: end;
}

#resetBtn {
  grid-column: 2;
  grid-row: 4;
  justify-self: end;
}

  .study-zone { min-height: 390px; padding: 18px; }
}

.mode-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.stat-button {
  font-family: inherit;
  border-radius: 18px;
  padding: 12px;
}

.stat-button:hover {
  transform: translateY(-1px);
}

.flashcard.hindi-side {
  background: linear-gradient(145deg, #d9ecff, #abcff2);
}

.flashcard.english-side {
  background: linear-gradient(145deg, #ffd3c7, #ec8f7d);
}

.card-main.hindi {
  line-height: 1.32;
}

.match-board {
  width: min(780px, 100%);
  display: grid;
  gap: 20px;
}

.match-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.match-column {
  display: grid;
  gap: 10px;
}

.match-card {
  min-height: 76px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  padding: 12px 10px;
  font-size: clamp(16px, 4vw, 24px);
  line-height: 1.25;
  cursor: pointer;
  white-space: normal;
  overflow-wrap: anywhere;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.match-card:hover {
  background: var(--panel-light);
  transform: translateY(-1px);
}

.match-card.selected {
  border-color: var(--accent);
  color: var(--accent);
}

.match-card.correct {
  background: rgba(88, 214, 141, 0.18);
  border-color: rgba(88, 214, 141, 0.75);
  color: var(--success);
  cursor: default;
}

.match-card.wrong-flash {
  background: rgba(255, 90, 90, 0.22);
  border-color: rgba(255, 90, 90, 0.8);
  color: var(--danger);
}

.match-next-row {
  min-height: 52px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.match-next-btn {
  display: grid;
  gap: 4px;
  text-align: center;
  line-height: 1.1;
  border-color: rgba(88, 214, 141, 0.75);
  color: var(--success);
  background: rgba(88, 214, 141, 0.14);
  font-size: 18px;
  font-weight: 800;
  padding: 14px 28px;
  border-radius: 22px;
}

.match-next-btn:hover {
  background: rgba(88, 214, 141, 0.22);
  border-color: rgba(88, 214, 141, 1);
}

.match-next-btn:hover {
  background: rgba(88, 214, 141, 0.22);
  border-color: rgba(88, 214, 141, 1);
}

.hidden {
  display: none !important;
}

.study-zone.clickable-upload {
  cursor: pointer;
  border-color: rgba(255, 204, 102, 0.45);
}

.study-zone.clickable-upload:hover {
  background: rgba(255, 204, 102, 0.055);
  border-color: rgba(255, 204, 102, 0.85);
}

.study-zone.clickable-upload .empty-state strong {
  color: var(--accent);
}

.hidden-file-input,
input[type="file"],
#csvFile {
  display: none !important;
}

.stats.hidden-stats {
  display: none;
}

.return-mode strong {
  display: none;
}

.return-mode span {
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.copy-card-btn {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.45);
  color: #111;
  display: grid;
  place-items: center;
  font-size: 18px;
  padding: 0;
  cursor: pointer;
}

.copy-card-btn:hover {
  background: rgba(255, 255, 255, 0.75);
}

.match-item {
  display: grid;
  gap: 8px;
  align-items: stretch;
}

.match-item.hindi-match-item {
  grid-template-columns: clamp(28px, 7vw, 42px) minmax(0, 1fr);
}

.match-item.english-match-item {
  grid-template-columns: minmax(0, 1fr) clamp(28px, 7vw, 42px);
}

.match-copy-btn {
  min-height: 76px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--muted);
  font-size: clamp(13px, 3vw, 19px);
  padding: 0;
  cursor: pointer;
}

.match-copy-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(255, 204, 102, 0.08);
}

.match-copy-btn:active {
  transform: scale(0.96);
}

.match-next-good {
  display: block;
  font-size: 28px;
  font-weight: 900;
}

.match-next-small {
  display: block;
  font-size: 16px;
  font-weight: 700;
}

#statusLine {
  display: none;
}

.play-box-status {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  min-height: 22px;
  margin-bottom: 14px;
}

.flashcard-layout,
.match-layout {
  width: 100%;
  display: grid;
  gap: 18px;
  justify-items: center;
}

/* Extra narrow viewport protection */
html,
body {
  overflow-x: hidden;
}

header,
main {
  max-width: 100vw;
}

header {
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}

main {
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}

.app-shell,
.study-zone,
.match-board,
.match-layout,
.flashcard-layout {
  min-width: 0;
  max-width: 100%;
}

button,
select {
  min-width: 0;
}

.controls {
  gap: 6px;
}

.controls button,
.controls select {
  padding-left: 9px;
  padding-right: 9px;
  font-size: 13px;
}

.stats {
  gap: 6px;
}

.stat,
.stat-button {
  padding-left: 6px;
  padding-right: 6px;
}

.stat strong {
  font-size: clamp(15px, 5vw, 22px);
}

.stat span {
  font-size: clamp(9px, 2.8vw, 12px);
  letter-spacing: 0.04em;
}

.study-zone {
  padding-left: 10px;
  padding-right: 10px;
}

.match-columns {
  gap: 8px;
}

.match-column {
  min-width: 0;
}

.match-item {
  gap: 5px;
  min-width: 0;
}

.match-item.hindi-match-item {
  grid-template-columns: clamp(24px, 6vw, 42px) minmax(0, 1fr);
}

.match-item.english-match-item {
  grid-template-columns: minmax(0, 1fr) clamp(24px, 6vw, 42px);
}

.match-card {
  min-width: 0;
  padding-left: 7px;
  padding-right: 7px;
  font-size: clamp(11px, 2.7vw, 18px);
}

.match-copy-btn {
  min-width: 0;
  font-size: clamp(10px, 2.6vw, 17px);
}

.home-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background: radial-gradient(circle at top, #26211a 0, var(--bg) 44%);
}

.home-card {
  width: min(860px, 100%);
  display: grid;
  gap: 24px;
  justify-items: center;
  text-align: center;
}

.home-card h1 {
  font-size: clamp(34px, 7vw, 72px);
  line-height: 0.95;
  max-width: 900px;
}

.language-title {
  margin: 0;
  color: var(--muted);
  font-size: clamp(18px, 3vw, 28px);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.language-grid {
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}

.language-btn {
  min-height: 72px;
  border-radius: 24px;
  font-size: 22px;
  font-weight: 800;
  border-color: rgba(255, 204, 102, 0.35);
}

.language-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.loading-languages {
  color: var(--muted);
  grid-column: 1 / -1;
}

.request-language-btn {
  margin-top: 8px;
  border-color: rgba(88, 214, 141, 0.4);
  color: var(--success);
}

body.deck-loaded #homeScreen {
  display: none;
}

body:not(.deck-loaded) header:not(.site-header),
body:not(.deck-loaded) main {
  display: none;
}

@media (max-width: 680px) {
  .home-screen {
    padding: 18px;
  }

  .language-grid {
    grid-template-columns: 1fr;
  }
}

.home-logo,
.home-title,
.language-title,
.language-btn,
.home-request-fade {
  opacity: 0;
  transform: translateY(14px);
  animation: home-fade-in 0.55s ease-out forwards;
}

.home-logo {
  width: min(420px, 84vw);
  height: auto;
  animation-delay: 0.1s;
}

.home-title {
  animation-delay: 0.35s;
}

.language-title {
  animation-delay: 0.6s;
}

.home-request-fade {
  animation-delay: 1.2s;
}

@keyframes home-fade-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.home-card h1.home-title {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: clamp(34px, 7vw, 76px);
  line-height: 0.95;
  letter-spacing: 0.02em;
  text-align: center;
  max-width: 920px;
}

.language-title {
  margin: 0;
  color: var(--muted);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: clamp(16px, 3vw, 28px);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 74px;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  pointer-events: none;
}

.back-home-btn {
  justify-self: start;
  pointer-events: auto;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(29, 29, 29, 0.82);
  color: var(--text);
  padding: 9px 13px;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  backdrop-filter: blur(8px);
}

.back-home-btn:hover {
  background: var(--panel-light);
  border-color: var(--accent);
  color: var(--accent);
}

.site-header-logo {
  pointer-events: auto;
  height: 54px;
  width: auto;
  object-fit: contain;
  opacity: 0;
  visibility: hidden;
}

body.deck-loaded .site-header-logo {
  opacity: 1;
  visibility: visible;
}

.home-screen {
  padding-top: 96px;
}

header:not(.site-header) {
  padding-top: 92px;
}

.bottom-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.bottom-controls button {
  flex: 0 1 auto;
}