:root {
  --bg: #f4efe4;
  --paper: #fffaf0;
  --ink: #21252d;
  --muted: #686e79;
  --accent: #c65b2d;
  --accent-dark: #a6481f;
  --line: #ddd4c0;
  --shadow: 0 18px 42px rgba(88, 60, 24, 0.08);
  --gold: #f0bf62;
  --green: #1d8f3b;
  --rose: #fff0eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(255, 221, 170, 0.32), transparent 30%),
    radial-gradient(circle at bottom right, rgba(214, 123, 78, 0.16), transparent 28%),
    linear-gradient(135deg, #f7f0e2 0%, #f2ecdf 48%, #ebe4d6 100%);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
}

button,
input,
textarea {
  font: inherit;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(193, 175, 142, 0.5);
  background: rgba(255, 251, 243, 0.75);
  backdrop-filter: blur(10px);
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3.6vw, 2.2rem);
}

.brand-accent {
  color: var(--accent);
}

.brand-block p {
  margin: 0;
  max-width: 34rem;
  color: var(--muted);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-size: 0.98rem;
  line-height: 1.35;
}

.account-shell {
  position: relative;
}

.account-btn {
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #fff8ea, #f6ead7);
  color: var(--ink);
}

.account-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.account-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(280px, 78vw);
  padding: 14px;
  border: 1px solid rgba(205, 190, 160, 0.9);
  border-radius: 18px;
  background: rgba(255, 250, 240, 0.98);
  box-shadow: var(--shadow);
  z-index: 40;
}

.account-menu #authStatus {
  margin-bottom: 12px;
  word-break: break-word;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.auth-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.92rem;
}

.account-menu-actions {
  display: flex;
  gap: 10px;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.card {
  background: rgba(255, 250, 240, 0.88);
  border: 1px solid rgba(205, 190, 160, 0.9);
  border-radius: 24px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none;
}

.centered,
.centered-block {
  text-align: center;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.75rem;
  color: var(--accent-dark);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.muted {
  color: var(--muted);
}

.status-message {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.6);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.sign-in-card {
  max-width: 560px;
  margin: 60px auto 0;
  text-align: center;
}

.sign-in-card h2,
.deck-home-header h2,
.deck-header h2,
.modal-panel h3 {
  margin: 0;
}

.deck-home-header {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin-bottom: 22px;
}

.deck-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.deck-card,
.empty-state {
  min-height: 172px;
}

.deck-card {
  position: relative;
}

.deck-card-button,
.empty-state {
  width: 100%;
  height: 100%;
  border: 1px solid rgba(201, 181, 144, 0.75);
  border-radius: 20px;
  padding: 24px 22px 20px;
  background:
    radial-gradient(circle at top left, var(--deck-card-highlight, rgba(255, 255, 255, 0.98)), var(--deck-card-mid, rgba(255, 247, 233, 0.88)) 42%, var(--deck-card-base, rgba(245, 232, 205, 0.9)) 100%);
  box-shadow:
    0 20px 34px rgba(87, 62, 27, 0.1),
    0 2px 0 rgba(255, 255, 255, 0.8) inset;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.deck-card-button:hover,
.deck-card-button:focus-visible {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow:
    0 24px 38px rgba(87, 62, 27, 0.14),
    0 2px 0 rgba(255, 255, 255, 0.88) inset;
}

.deck-card-button strong {
  max-width: 88%;
  font-size: clamp(1.85rem, 3.1vw, 2.35rem);
  line-height: 1.12;
  text-wrap: balance;
}

.deck-language-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 14px;
  padding: 7px 12px;
  border: 1px solid rgba(201, 181, 144, 0.8);
  border-radius: 999px;
  background: rgba(255, 252, 246, 0.88);
  color: var(--muted);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
}

.deck-manage-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 42px;
  height: 42px;
  margin: 0;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 251, 243, 0.98);
  box-shadow: 0 10px 18px rgba(87, 62, 27, 0.12);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.deck-manage-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.empty-state {
  justify-content: center;
  text-align: center;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wrap {
  flex-wrap: wrap;
}

.deck-header {
  margin-bottom: 14px;
}

.deck-title-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  width: 100%;
  padding: 0 160px;
}

.deck-header h2 {
  margin: 0;
  text-align: center;
  font-size: clamp(1.7rem, 3vw, 2.3rem);
}

.deck-title-row #backToDecksBtn {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}

.deck-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.bottom-actions {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid rgba(205, 190, 160, 0.7);
}

.study-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.mode-trigger {
  width: auto;
  min-width: 200px;
  padding: 12px 16px;
  border-radius: 18px;
  background: linear-gradient(135deg, #fff7e7, #ffffff);
  text-align: left;
}

.mode-trigger-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.86rem;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.seg-toggle {
  display: inline-flex;
  gap: 8px;
}

.stress-index-control {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 64px;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.stepper-btn {
  width: 64px;
  min-width: 64px;
  margin-top: 8px;
  padding: 12px 0;
  border-radius: 14px;
  font-size: 1rem;
}

.stress-index-control input {
  margin-top: 8px;
  text-align: center;
  padding-left: 8px;
  padding-right: 8px;
}

label {
  display: block;
  margin-bottom: 14px;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.word-modal-panel label {
  margin-bottom: 6px;
}

.field-block {
  margin-bottom: 16px;
}

.word-modal-panel .field-block {
  margin-bottom: 4px;
}

.word-modal-panel label input,
.word-modal-panel label textarea,
.word-modal-panel label select {
  margin-top: 4px;
}

.word-modal-panel .stepper-btn,
.word-modal-panel .stress-index-control input {
  margin-top: 4px;
}

.word-modal-panel .field-label-row {
  margin-bottom: 2px;
}

.word-modal-panel .field-assist-status {
  margin-top: 4px;
  min-height: 1em;
}

.word-modal-panel textarea {
  min-height: 88px;
}

.deck-color-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.deck-color-swatch {
  width: 42px;
  min-width: 42px;
  height: 42px;
  margin-top: 0;
  padding: 0;
  border-radius: 999px;
  border: 2px solid rgba(201, 181, 144, 0.7);
  box-shadow:
    0 6px 12px rgba(87, 62, 27, 0.08),
    0 2px 0 rgba(255, 255, 255, 0.82) inset;
  background:
    radial-gradient(circle at top left, var(--deck-swatch-highlight, rgba(255, 255, 255, 0.98)), var(--deck-swatch-mid, rgba(255, 247, 233, 0.88)) 42%, var(--deck-swatch-base, rgba(245, 232, 205, 0.9)) 100%);
}

.deck-color-swatch:hover,
.deck-color-swatch:focus-visible {
  transform: translateY(-2px);
}

.deck-color-swatch.is-selected {
  border-color: var(--accent);
  box-shadow:
    0 0 0 3px rgba(198, 91, 45, 0.18),
    0 8px 14px rgba(87, 62, 27, 0.12),
    0 2px 0 rgba(255, 255, 255, 0.82) inset;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field-ai-btn {
  width: 42px;
  min-width: 42px;
  height: 42px;
  margin-top: 0;
  padding: 0;
  border-radius: 999px;
  font-size: 1.35rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff4ea;
}

.field-ai-btn.is-loading {
  color: transparent;
  position: relative;
}

.field-ai-btn.is-loading::after {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid rgba(198, 91, 45, 0.28);
  border-top-color: var(--accent);
  border-radius: 999px;
  position: absolute;
  inset: 0;
  margin: auto;
  animation: spin 0.8s linear infinite;
}

.field-assist-status {
  display: block;
  margin-top: 8px;
  min-height: 1.2em;
  font-size: 0.92rem;
}

input,
select,
textarea,
button {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
}

textarea {
  min-height: 108px;
  resize: vertical;
}

button {
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
}

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

.primary-btn {
  background: linear-gradient(135deg, #cf6334, #b84d21);
  color: #fffaf3;
  border-color: #b84d21;
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.78);
}

.danger-btn {
  background: #fff0ed;
  color: #992f16;
  border-color: #e6ab9a;
}

.soft-btn {
  background: #fff4ec;
}

.small-btn,
.toggle-btn {
  width: auto;
  margin-top: 0;
}

.toggle-btn.active {
  background: #fff0e8;
  border-color: var(--accent);
}

.flashcard {
  border: 1px solid rgba(206, 191, 165, 0.9);
  border-radius: 24px;
  background: #fffdf7;
  width: min(100%, 520px);
  min-height: 390px;
  margin: 0 auto 12px;
  perspective: 1000px;
  box-shadow: 0 18px 36px rgba(95, 71, 31, 0.08);
}

.flashcard.interactive {
  cursor: pointer;
}

.flashcard-inner {
  position: relative;
  min-height: 390px;
  transform-style: preserve-3d;
  transition: transform 240ms ease;
}

.flashcard.no-flip-transition .flashcard-inner {
  transition: none;
}

.flashcard.is-flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashface {
  position: absolute;
  inset: 0;
  padding: 28px;
  border-radius: 22px;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.flashface-front {
  background: linear-gradient(145deg, #ffffff 0%, #fbf5e7 100%);
}

.flashface-back {
  background: linear-gradient(145deg, #fffaf3 0%, #f3ead7 100%);
  transform: rotateY(180deg);
}

.flashface-back > * + * {
  margin-top: 14px;
}

#wordText {
  font-size: clamp(2.4rem, 5vw, 3.2rem);
}

#definitionText {
  font-size: clamp(1.5rem, 3.2vw, 1.95rem);
}

#exampleText {
  margin-top: 0;
  font-size: 1.08rem;
  color: var(--ink);
  text-align: left;
  line-height: 1.45;
}

.card-details-toggle {
  align-self: center;
  margin-top: 14px;
}

.card-details-modal-panel {
  width: min(640px, 100%);
}

.card-details-modal-panel .centered-block {
  margin-bottom: 18px;
}

.card-details-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.pairings-block {
  width: 100%;
  margin-top: 14px;
}

.pairings-label {
  margin: 0 0 10px;
  font-size: 0.88rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pairings-list {
  display: block;
  margin: 0;
  padding-left: 22px;
  list-style: disc;
}

.pairings-list li {
  margin: 0 0 8px;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-size: 0.92rem;
  line-height: 1.45;
}

.flashcard-audio {
  width: min(100%, 280px);
  margin-top: 14px;
}

.stressed-char {
  color: var(--green);
  font-weight: 700;
}

.flash-hint {
  margin: 4px 0 16px;
  text-align: center;
}

.rating-row {
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}

.ratingBtn {
  width: auto;
  min-width: 128px;
  margin-top: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.ratingBtn.no-idea {
  background: #ffe6e1;
  border-color: #edb2a5;
}

.ratingBtn.forgot {
  background: #fff3dc;
  border-color: #e9cb92;
}

.ratingBtn.remembered {
  background: #e7f2ff;
  border-color: #aac9eb;
}

.ratingBtn.mastered {
  background: #e5f7ea;
  border-color: #9bccaa;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(35, 29, 21, 0.42);
  backdrop-filter: blur(8px);
  z-index: 30;
}

.modal.hidden {
  display: none;
}

.modal-panel {
  position: relative;
  width: min(720px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  overflow-x: hidden;
}

.deck-modal-panel {
  width: min(520px, 100%);
}

.picker-panel {
  width: min(720px, 100%);
}

.modal-close-icon {
  position: absolute;
  top: 16px;
  right: 16px;
  width: auto;
  margin: 0;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 1.35rem;
  line-height: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.stacked-actions {
  flex-direction: column;
  align-items: stretch;
}

.definition-picker-options {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.definition-picker-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: flex-start;
  width: 100%;
  box-sizing: border-box;
  padding: 14px 16px;
  border: 1px solid rgba(205, 190, 160, 0.75);
  border-radius: 16px;
  background: rgba(255, 251, 245, 0.92);
}

.definition-picker-option input {
  justify-self: end;
  margin-top: 3px;
  margin-left: 16px;
  transform: scale(1.2);
  transform-origin: top right;
}

.definition-picker-option span {
  display: block;
  min-width: 0;
  line-height: 1.45;
  text-align: left;
}

.delete-word-row {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(205, 190, 160, 0.6);
}

.picker-header {
  margin-bottom: 16px;
}

.picker-options {
  display: grid;
  gap: 12px;
}

.picker-option {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  text-align: left;
}

.picker-option p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.96rem;
}

.picker-option.active {
  border-color: var(--accent);
  background: #fff4ea;
}

.picker-option-check {
  color: var(--accent-dark);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.word-input-wrap {
  position: relative;
}

#newWord {
  position: relative;
  z-index: 2;
  background: transparent;
  color: transparent;
  caret-color: var(--ink);
}

#newWord::placeholder {
  color: var(--muted);
}

.word-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 14px;
  color: var(--ink);
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.voice-note-box {
  padding: 18px;
  border: 1px dashed rgba(198, 91, 45, 0.35);
  border-radius: 18px;
  background: rgba(255, 248, 238, 0.8);
}

.voice-note-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.voice-note-head h4 {
  margin: 0;
}

.voice-note-head p {
  margin: 4px 0 0;
}

.voice-note-timer {
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-size: 0.9rem;
}

.voice-note-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0 10px;
}

.voice-note-status {
  margin: 0;
}

#voiceNotePreview {
  width: 100%;
  margin-top: 12px;
}

.profile-plan-note {
  margin: 8px 0 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 760px) {
  #flashcardSection.hidden {
    display: none;
  }

  #flashcardSection:not(.hidden) {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 118px);
    padding-bottom: 0;
  }

  .voice-note-head,
  .modal-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .account-menu-actions {
    flex-direction: column;
  }

  .field-label-row {
    align-items: flex-start;
  }

  .container {
    padding: 10px 8px 20px;
  }

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

  .card {
    padding: 14px;
    border-radius: 18px;
  }

  .topbar {
    padding: 8px 10px;
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 1.9rem;
  }

  .brand-block p {
    font-size: 0.9rem;
    max-width: 18rem;
  }

  .account-btn {
    width: 40px;
    height: 40px;
  }

  .deck-header {
    margin-bottom: 8px;
  }

  .deck-title-row #backToDecksBtn {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    padding: 9px 14px;
  }

  .deck-title-row {
    min-height: 44px;
    padding: 0 68px;
  }

  .deck-title-row h2 {
    font-size: 1.8rem;
    line-height: 1;
    text-align: center;
  }

  .deck-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .deck-manage-btn {
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
  }

  .bottom-actions {
    margin-top: auto;
    padding-top: 14px;
    padding-bottom: 10px;
  }

  .study-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 10px;
  }

  .mode-trigger {
    width: 100%;
    min-width: 0;
    padding: 8px 12px;
    border-radius: 16px;
  }

  .seg-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    gap: 8px;
  }

  .seg-toggle .toggle-btn,
  .deck-actions .small-btn,
  .voice-note-actions .small-btn {
    width: 100%;
  }

  .voice-note-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
  }

  .flashcard,
  .flashcard-inner {
    min-height: 250px;
  }

  .flashface {
    padding: 16px;
  }

  #wordText {
    font-size: clamp(1.8rem, 9vw, 2.3rem);
  }

  #definitionText {
    font-size: clamp(1.18rem, 5.5vw, 1.5rem);
  }

  #exampleText,
  .flashcard-audio,
  .flash-hint {
    font-size: 0.96rem;
  }

  .rating-row {
    gap: 8px;
  }

  .ratingBtn {
    min-width: 0;
    flex: 1 1 calc(50% - 8px);
    padding: 9px 10px;
  }

  .flash-hint {
    margin: 2px 0 10px;
  }
}
