:root {
  --bg: #0b1320;
  --panel: #121c2f;
  --card: #182946;
  --text: #e6edf3;
  --muted: #96a3b3;
  --primary: #3b82f6;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --border: #243652;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  background: linear-gradient(180deg, #0b1320 0%, #0e1a2e 100%);
  color: var(--text);
}

.app-header {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 16px;
  align-items: center;
  padding: 16px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
/* Safe-area support for iOS notch */
.app-header {
  padding-top: calc(16px + env(safe-area-inset-top));
}
body {
  padding-bottom: env(safe-area-inset-bottom);
}
/* Hide and disable study UI when signed out */
body.signed-out .review,
body.signed-out #manageView {
  display: none !important;
}
body.signed-out .app-header {
  pointer-events: auto;
}
body.signed-out .review {
  pointer-events: none;
}
/* Hide header stats and controls when signed out */
body.signed-out .app-header .stats,
body.signed-out .app-header .controls {
  display: none !important;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.3px;
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.controls label {
  color: var(--muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

select, textarea, input[type="text"] {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
/* Prevent iOS zoom-on-focus by keeping input text >=16px */
select, textarea,
input[type="text"], input[type="password"], input[type="email"], input[type="number"] {
  font-size: 16px;
}

.controls select#deckSelect {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats {
  display: flex;
  gap: 12px;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
}

.review {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 72px);
  padding: 24px;
}

.empty {
  text-align: center;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 640px;
  box-shadow: var(--shadow);
}

.card {
  width: min(820px, 96vw);
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)) , var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 72px 24px 22px 24px;
  position: relative;
}

.card-face {
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 18px;
  max-height: 52vh;
  overflow: auto;
}

.card-face + .card-face {
  margin-top: 16px;
  border-top: 1px dashed var(--border);
  padding-top: 16px;
}

.answer {
  color: #dbeafe;
}

.deck-name {
  display: none;
}

.side-actions {
  position: absolute;
  top: 12px;
  right: 12px;
}

.actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

.ratings {
  display: flex;
  gap: 8px;
}

/* Mobile tweaks */
@media (max-width: 600px) {
  .app-header {
    grid-template-columns: 1fr auto;
    grid-auto-rows: auto;
    gap: 10px;
  }
  .brand { display: none; }
  .controls { display: none; }
  .auth { display: none; }
  /* When signed out, reveal the auth container so the centered button can show */
  .signed-out .auth { display: block; }
  .deck-name {
    display: block;
    font-weight: 600;
  }
  .stats {
    grid-column: 2 / span 1;
    justify-content: flex-end;
  }
  .deck-name {
    grid-column: 1 / span 1;
  }
  /* Make deck name shorter on small screens to fit beside stats */
  .deck-name.truncate {
    max-width: 44vw;
  }
  .actions {
    flex-wrap: wrap;
    gap: 10px;
  }
  button {
    min-height: 44px;
  }
  .controls {
    gap: 6px;
  }
  .card-face {
    font-size: 16px;
    max-height: 50vh;
  }
  .card {
    padding-top: 72px;
  }
}

/* Mobile bottom bar */
.mobile-bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: none;
  gap: 10px;
  z-index: 15;
}
.mobile-bottom-bar > button {
  flex: 1 1 0;
}
@media (max-width: 600px) {
  .mobile-bottom-bar { display: flex; }
}
/* Hide mobile bottom bar when signed out */
body.signed-out .mobile-bottom-bar {
  display: none !important;
}
button {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.06s ease, background 0.15s ease, border 0.15s ease, box-shadow 0.15s ease;
}

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

button:active {
  transform: translateY(0px) scale(0.98);
}

button.primary {
  background: linear-gradient(180deg, rgba(59,130,246,0.2), rgba(59,130,246,0)) , var(--panel);
  border-color: #2563eb;
}

button.success {
  background: linear-gradient(180deg, rgba(34,197,94,0.2), rgba(34,197,94,0)) , var(--panel);
  border-color: #16a34a;
}

button.warn {
  background: linear-gradient(180deg, rgba(245,158,11,0.2), rgba(245,158,11,0)) , var(--panel);
  border-color: #d97706;
}

button.danger {
  background: linear-gradient(180deg, rgba(239,68,68,0.2), rgba(239,68,68,0)) , var(--panel);
  border-color: #dc2626;
}

.hidden {
  display: none !important;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  max-width: 560px;
  width: min(560px, 96vw);
  padding: 0;
}

.form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.form h3 {
  margin: 0 0 8px;
}

.form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.form label.inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.log {
  margin-top: 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  color: var(--muted);
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
}

/* Simple vertical menu inside dialogs */
.menu-list {
  display: grid;
  gap: 8px;
}

/* Manage dialog */
dialog#manageDialog {
  max-width: 1200px;
  width: min(96vw, 1200px);
}
.table-wrap {
  max-height: 70vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
/* Full-screen Manage view */
.manage-view {
  position: fixed;
  inset: 0;
  background: #0e1a2e;
  z-index: 20;
  padding: 16px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 12px;
}
.manage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.manage-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
#manageCloseBtn {
  position: absolute;
  top: 8px;
  right: 8px;
}
.icon-btn.close {
  width: 36px;
  height: 36px;
  line-height: 1;
  font-size: 18px;
}

/* Card side actions panel */
.card-actions-panel {
  position: absolute;
  top: 48px;
  right: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  gap: 6px;
  box-shadow: var(--shadow);
  z-index: 1000;
}
table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  table-layout: fixed;
}
table.table th, table.table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}
table.table thead th {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
  text-align: left;
}
.table thead th:nth-child(1),
.table tbody td:nth-child(1) { width: 30%; }
.table thead th:nth-child(2),
.table tbody td:nth-child(2) { width: 30%; }
.table thead th:nth-child(3),
.table tbody td:nth-child(3) { width: 10%; }
.table thead th:nth-child(4),
.table tbody td:nth-child(4) { width: 10%; }
.table thead th:nth-child(5),
.table tbody td:nth-child(5) { width: 8%; }
.table thead th:nth-child(6),
.table tbody td:nth-child(6) { width: 6%; }
.table thead th:nth-child(7),
.table tbody td:nth-child(7) { width: 6%; }
.muted {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}
.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.row-actions-cell {
  position: relative;
  vertical-align: top;
  text-align: left;
  overflow: visible;
}
.row-actions-cell .row-actions-btn {
  display: inline-block;
  margin: 0;
  vertical-align: top;
}
.row-actions-panel {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  gap: 6px;
  box-shadow: var(--shadow);
  z-index: 10;
}
.truncate {
  max-width: 360px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Center the sign-in button when signed out */
#authBtn.centered-auth {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 100;
  padding: 14px 18px;
}

.auth-menu {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  box-shadow: var(--shadow);
  z-index: 1000;
  display: none;
  min-width: 160px;
}
.auth-menu.open {
  display: grid;
  gap: 6px;
}
.auth-menu-item {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.auth-menu-item:hover {
  border-color: var(--border);
}


