:root{
  --accent:   #D9A441;
  --secondary:#7E9B8E;
  --danger:   #C96A4A;

  --display: 'Mulish', sans-serif;
  --body:    'Mulish', sans-serif;   /*'IBM Plex Sans'*/
  --mono:    'Mulish', monospace;    /*'IBM Plex Mono'*/
}

/* ---------- theme tokens ---------- */
:root,
[data-theme="dark"]{
  --bg:         #16181C;
  --surface:    #202329;
  --surface-2:  #2A2E3480;
  --border:     rgba(242,239,230,0.14);
  --text:       #F2EFE6;
  --text-dim:   rgba(242,239,230,0.55);
  --text-faint: rgba(242,239,230,0.4);
  --switch-off: rgba(242,239,230,0.2);

  --card-bg:    #dedad0; /*#F6F1E4;*/
  --card-bg-2:  #EAE2CE;
  --card-text:  #1B2430;
  --card-line:  rgba(27,36,48,0.14);
  --card-hint:  rgba(27,36,48,0.4);
}

[data-theme="light"]{
  --bg:         #F4F1EA;
  --surface:    #FFFFFF;
  --surface-2:  #EFE9DA;
  --border:     rgba(27,36,48,0.12);
  --text:       #1B2430;
  --text-dim:   rgba(27,36,48,0.6);
  --text-faint: rgba(27,36,48,0.42);
  --switch-off: rgba(27,36,48,0.18);

  --card-bg:    #FFFFFF;
  --card-bg-2:  #EFE9DA;
  --card-text:  #1B2430;
  --card-line:  rgba(27,36,48,0.12);
  --card-hint:  rgba(27,36,48,0.4);
}

*{ box-sizing: border-box; }

/* Elements with the `hidden` attribute must always be hidden, even when a
   component's own class sets its own `display` (e.g. .modal-overlay,
   .deck-stack). Without this, `hidden` and an author `display` rule have
   equal CSS specificity and the display rule can win, leaving an invisible
   full-screen element still intercepting clicks. */
[hidden]{ display: none !important; }

html,body{
  margin:0;
  height:100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  -webkit-tap-highlight-color: transparent;
  transition: background .2s ease, color .2s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.app{
  min-height:100dvh;
  display:flex;
  flex-direction:column;
}

/* ---------- top bar ---------- */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 20px 20px 8px;
}
.brand{ display:flex; align-items:center; gap:8px; }
.brand-mark{ color: var(--accent); font-size: 14px; }
.brand-name{
  font-family: var(--display);
  font-weight:600;
  font-size: 20px;
  letter-spacing: 0.01em;
}

/* ---------- deck menu ---------- */
.menu-wrap{
  position: relative;
}

.menu-trigger{
  display:flex;
  align-items:center;
  gap: 8px;
  font-family: var(--body);
  font-size: 13px;
  font-weight:600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px 9px 14px;
  cursor:pointer;
  max-width: 55vw;
  transition: border-color .15s ease, transform .1s ease;
}
.menu-trigger span:first-child{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.menu-trigger:hover{ border-color: var(--text-faint); }
.menu-trigger:active{ transform: scale(0.98); }
.menu-chevron{ color: var(--accent); font-size: 11px; flex:0 0 auto; }

.menu-panel{
  position:absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(320px, 84vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 20px 45px -12px rgba(0,0,0,0.45);
  z-index: 30;
}

.menu-panel-title{
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 4px 8px 8px;
}

.menu-divider{
  height: 1px;
  background: var(--border);
  margin: 6px 4px;
}

.menu-list{
  list-style:none;
  margin:0;
  padding:0;
  max-height: 34vh;
  overflow-y:auto;
}

.menu-list .menu-item{
  display:flex;
  align-items:center;
  gap: 4px;
  border-radius: 9px;
}
.menu-list .menu-item:hover{ background: var(--surface-2); }
.menu-list .menu-item.is-active .menu-item-select{ color: var(--accent); }

.menu-item-select{
  flex:1;
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap: 10px;
  background:none;
  border:none;
  color: var(--text);
  font-family: var(--body);
  font-size: 14px;
  font-weight:500;
  text-align:left;
  padding: 10px 8px;
  cursor:pointer;
}
.menu-item-name{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.menu-item-count{
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
}

.menu-item-delete{
  flex: 0 0 auto;
  background:none;
  border:none;
  color: var(--text-faint);
  font-size: 16px;
  cursor:pointer;
  padding: 6px 8px;
}
.menu-item-delete:hover{ color: var(--danger); }

.menu-empty{
  font-size: 13px;
  color: var(--text-faint);
  padding: 10px 8px;
}

.menu-item--upload{
  width:100%;
  display:flex;
  align-items:center;
  gap: 6px;
  margin-top: 6px;
  background: transparent;
  border: 1px dashed var(--text-faint);
  border-radius: 9px;
  color: var(--text-dim);
  font-family: var(--body);
  font-size: 13px;
  font-weight:500;
  padding: 10px 8px;
  cursor:pointer;
}
.menu-item--upload:hover{ border-color: var(--text-dim); }
.menu-item--upload .plus{ color: var(--accent); font-weight:700; }

.menu-setting-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 8px 8px;
  font-size: 13px;
  font-weight:500;
  color: var(--text);
}

.toggle-switch{
  position:relative;
  width: 40px;
  height: 24px;
  border-radius: 999px;
  border: none;
  background: var(--switch-off);
  cursor:pointer;
  padding: 0;
  flex: 0 0 auto;
  transition: background .15s ease;
}
.toggle-switch[aria-checked="true"]{
  background: var(--accent);
}
.toggle-knob{
  position:absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
  transition: transform .15s ease;
}
.toggle-switch[aria-checked="true"] .toggle-knob{
  transform: translateX(16px);
}

/* ---------- deck header (name + row, above the card) ---------- */
.deck-header{
  width: 100%;
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap: 12px;
  padding: 0 4px 10px;
}
.deck-header-name{
  font-family: var(--display);
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.deck-header-row{
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
}

/* ---------- name-this-deck modal ---------- */
.modal-overlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 20px;
  z-index: 40;
}
.modal{
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 24px 60px -16px rgba(0,0,0,0.6);
}
.modal-title{
  font-family: var(--display);
  font-weight: 600;
  font-size: 18px;
  margin: 0 0 6px;
  color: var(--text);
}
.modal-sub{
  font-size: 12px;
  line-height:1.5;
  color: var(--text-dim);
  margin: 0 0 14px;
}
.text-input{
  width: 100%;
  font-family: var(--body);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  margin-bottom: 16px;
}
.text-input:focus{
  outline: none;
  border-color: var(--accent);
}
.modal-actions{
  display:flex;
  justify-content:flex-end;
  gap: 8px;
}

/* ---------- stage ---------- */
.stage{
  flex:1;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 12px 20px 40px;
}

.empty-state{
  text-align:center;
  max-width: 320px;
}
.empty-title{
  font-family: var(--display);
  font-size: 22px;
  margin: 0 0 8px;
}
.empty-sub{
  font-size: 14px;
  color: var(--text-dim);
  line-height:1.5;
  margin: 0 0 20px;
}

.btn{
  font-family: var(--body);
  font-weight:600;
  font-size: 14px;
  border-radius: 10px;
  padding: 11px 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor:pointer;
  transition: transform .1s ease, background .15s ease;
}
.btn:active{ transform: scale(0.97); }
.btn--primary{
  background: var(--accent);
  color: #1B2430;
  border-color: var(--accent);
}
.btn--ghost{
  border-color: var(--border);
  color: var(--text-dim);
  font-size: 13px;
  padding: 8px 14px;
}

/* ---------- deck stack / card ---------- */
.deck-stack{
  width: 100%;
  max-width: 420px;
  display:flex;
  flex-direction:column;
  align-items:center;
}

.ghost-card{
  position:relative;
  width: 88%;
  height: 14px;
  background: var(--card-bg-2);
  border-radius: 14px 14px 0 0;
  opacity: 0.5;
}
.ghost-card--2{ margin-bottom:-8px; width: 80%; opacity:0.35; }
.ghost-card--1{ margin-bottom:-10px; width: 84%; opacity:0.55; }

.card{
  position:relative;
  width: 100%;
  min-height: 340px;
  max-height: 62dvh;
  background: var(--card-bg);
  color: var(--card-text);
  border: none;
  border-radius: 18px;
  padding: 28px 26px 24px;
  display:flex;
  flex-direction:column;
  cursor:pointer;
  text-align:left;
  box-shadow: 0 18px 40px -14px rgba(0,0,0,0.4);
  transition: transform .12s ease, background .2s ease;
  overflow: hidden;
}
.card:active{ transform: scale(0.985); }

.card-rule{
  position:absolute;
  top: 46px;
  left: 26px;
  right: 26px;
  height: 1px;
  background: repeating-linear-gradient(
    to right, var(--card-line) 0 6px, transparent 6px 12px
  );
}

.card-face{
  display:flex;
  flex-direction:column;
  flex:1;
  min-height: 0;
  padding-top: 30px;
  transition: opacity 120ms ease, transform 120ms ease;
  opacity: 1;
  transform: translateY(0);
}
.card.is-fading .card-face{
  opacity: 0;
  transform: translateY(4px);
}

.card-label{
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--secondary);
  flex: 0 0 auto;
}
.card.is-answer .card-label{ color: var(--accent); }

.card-text{
  font-family: var(--display);
  font-weight: 500;
  /* Fluid base size: scales with viewport width, JS trims further if a
     long question would otherwise overflow the card. */
  font-size: clamp(19px, 4.6vw + 8px, 32px);
  line-height: 1.35;
  margin: 18px 0 auto;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.card-hint{
  align-self:flex-end;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--card-hint);
  flex: 0 0 auto;
}

/* ---------- controls ---------- */
.controls{
  width:100%;
  display:flex;
  flex-direction:column;
  gap: 12px;
  margin-top: 18px;
}

.nav-row{
  display:flex;
  align-items:center;
  justify-content:center;
  gap: 22px;
}

.nav-btn{
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 19px;
  line-height: 1;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  transition: border-color .15s ease, transform .1s ease;
}
.nav-btn:hover{ border-color: var(--text-faint); }
.nav-btn:active{ transform: scale(0.93); }

.progress{
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  min-width: 44px;
  text-align:center;
}

.actions-row{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap: 8px;
}

/* Only show "Back to question" while the answer side is showing. .controls
   is a sibling of #card (both direct children of .deck-stack), so this
   reacts to the same .is-answer class JS already toggles on the card. */
#backBtn{ display:none; }
#card.is-answer ~ .controls #backBtn{ display:inline-flex; }

/* ---------- toast ---------- */
.toast{
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-family: var(--body);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  z-index: 20;
}

@media (min-width: 640px){
  .card{ min-height: 380px; }
}

@media (prefers-reduced-motion: reduce){
  .card, .btn, .nav-btn, .toggle-switch, .toggle-knob, html, body, .card-face{ transition: none; }
}
