/* ═══════════════════════════════════════════════════════════════════
   SỔ TAY FSRS — Custom Word Form v1.0
   Modal thêm từ vựng thủ công: overlay + form đa nghĩa + play button
   ═══════════════════════════════════════════════════════════════════ */

/* --- Overlay --- */
.cw-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.22s ease;
}
.cw-overlay.is-open { opacity: 1; }

/* --- Modal box --- */
.cw-modal {
  width: 96vw;
  max-width: 780px;
  max-height: 92vh;
  height: 100vh;
  height: 100dvh;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--sotay-panel, #1a1030);
  border: 1px solid var(--sotay-border-hi, rgba(212,180,90,0.3));
  border-radius: var(--sotay-radius-lg, 16px);
  box-shadow: 0 24px 80px rgba(0,0,0,0.55), 0 0 60px rgba(200,169,110,0.07);
  transform: translateY(24px) scale(0.97);
  transition: transform 0.26s cubic-bezier(0.2, 0, 0, 1);
}
.cw-overlay.is-open .cw-modal { transform: translateY(0) scale(1); }

/* --- Header --- */
.cw-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--sotay-border, rgba(255,255,255,0.08));
  flex-shrink: 0;
}
.cw-modal__title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--sotay-gold, #c8a96e);
  display: flex;
  align-items: center;
  gap: 8px;
}
.cw-close-btn {
  background: none;
  border: none;
  color: var(--sotay-text-muted, rgba(255,255,255,0.45));
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.cw-close-btn:hover { color: #fff; background: rgba(255,255,255,0.08); }

/* --- Body (scrollable) --- */
.cw-modal__body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* --- Row layouts --- */
.cw-row { display: grid; gap: 12px; }
.cw-row--2 { grid-template-columns: 1fr 1fr; }
.cw-row--3 { grid-template-columns: 1fr 1fr 1fr; }
.cw-mt { margin-top: 4px; }

/* --- Field --- */
.cw-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cw-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--sotay-text-muted, rgba(255,255,255,0.5));
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cw-req { color: #e74c3c; font-size: 0.85em; }
.cw-req-note { font-size: 0.78rem; color: var(--sotay-text-muted, rgba(255,255,255,0.4)); }

/* --- Input --- */
.cw-input {
  width: 100%;
  padding: 9px 12px;
  background: var(--sotay-input-bg, rgba(255,255,255,0.05));
  border: 1px solid var(--sotay-border, rgba(255,255,255,0.1));
  border-radius: 8px;
  color: var(--sotay-text, #e8e0d0);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
}
.cw-input:focus {
  outline: none;
  border-color: var(--sotay-gold, #c8a96e);
  box-shadow: 0 0 0 2px rgba(200,169,110,0.18);
}
.cw-input::placeholder { color: rgba(255,255,255,0.25); }

/* --- Input + play button wrapper --- */
.cw-input-play {
  display: flex;
  align-items: center;
  gap: 6px;
}
.cw-input-play .cw-input { flex: 1; }
.cw-input-play--wide { flex: 1; }
.cw-input-play--wide .cw-input { flex: 1; }

.cw-play-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  background: rgba(200,169,110,0.12);
  border: 1px solid rgba(200,169,110,0.25);
  border-radius: 8px;
  color: var(--sotay-gold, #c8a96e);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: background 0.15s, transform 0.1s;
}
.cw-play-btn:hover { background: rgba(200,169,110,0.22); transform: scale(1.05); }
.cw-play-btn:active { transform: scale(0.95); }

/* --- Usage block --- */
.cw-usages { display: flex; flex-direction: column; gap: 12px; }
.cw-usage-block {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--sotay-border, rgba(255,255,255,0.08));
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cw-usage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cw-usage-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--sotay-gold, #c8a96e);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.cw-remove-usage {
  background: none;
  border: none;
  color: rgba(255,255,255,0.35);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.cw-remove-usage:hover { color: #e74c3c; background: rgba(231,76,60,0.1); }

/* Add usage button */
.cw-add-usage-btn {
  background: none;
  border: 1px dashed rgba(200,169,110,0.3);
  border-radius: 8px;
  color: var(--sotay-gold, #c8a96e);
  font-size: 0.85rem;
  font-family: inherit;
  padding: 8px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s, border-color 0.15s;
  align-self: flex-start;
}
.cw-add-usage-btn:hover { background: rgba(200,169,110,0.08); border-color: rgba(200,169,110,0.5); }

/* --- Examples --- */
.cw-examples { display: flex; flex-direction: column; gap: 6px; }
.cw-examples-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cw-examples-label {
  font-size: 0.74rem;
  font-weight: 600;
  color: rgba(255,255,255,0.4);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cw-add-example {
  background: none;
  border: none;
  color: rgba(200,169,110,0.6);
  font-size: 0.78rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 5px;
  transition: background 0.15s, color 0.15s;
}
.cw-add-example:hover { background: rgba(200,169,110,0.1); color: var(--sotay-gold, #c8a96e); }
.cw-example-list { display: flex; flex-direction: column; gap: 6px; }
.cw-example-row .cw-input { font-size: 0.85rem; }
.cw-remove-example {
  flex-shrink: 0;
  background: none;
  border: none;
  color: rgba(255,255,255,0.3);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.cw-remove-example:hover { color: #e74c3c; background: rgba(231,76,60,0.1); }

/* --- Footer --- */
.cw-modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--sotay-border, rgba(255,255,255,0.08));
  flex-shrink: 0;
}
.cw-footer-btns { display: flex; gap: 10px; }
.cw-btn {
  padding: 9px 20px;
  border-radius: 8px;
  border: none;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.cw-btn:active { transform: scale(0.97); }
.cw-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.cw-btn--ghost {
  background: rgba(255,255,255,0.06);
  color: var(--sotay-text-muted, rgba(255,255,255,0.5));
  border: 1px solid rgba(255,255,255,0.1);
}
.cw-btn--ghost:hover { background: rgba(255,255,255,0.1); }
.cw-btn--primary {
  background: var(--sotay-gold, #c8a96e);
  color: #1a1030;
}
.cw-btn--primary:hover:not(:disabled) { background: #d4b87a; }

/* ─── Light mode overrides ──────────────────────────────────────── */
html[data-theme="light"] .cw-modal,
body.light-mode .cw-modal {
  background: #faf8f4;
  border-color: rgba(180,120,60,0.2);
  box-shadow: 0 24px 80px rgba(0,0,0,0.18);
}
html[data-theme="light"] .cw-input,
body.light-mode .cw-input {
  background: #fff;
  border-color: rgba(180,120,60,0.2);
  color: #3d2b1a;
}
html[data-theme="light"] .cw-input::placeholder,
body.light-mode .cw-input::placeholder { color: rgba(60,40,20,0.3); }
html[data-theme="light"] .cw-usage-block,
body.light-mode .cw-usage-block {
  background: rgba(180,120,60,0.05);
  border-color: rgba(180,120,60,0.15);
}
html[data-theme="light"] .cw-modal__title,
body.light-mode .cw-modal__title { color: #8a5c2e; }
html[data-theme="light"] .cw-usage-label,
body.light-mode .cw-usage-label { color: #8a5c2e; }
html[data-theme="light"] .cw-play-btn,
body.light-mode .cw-play-btn { border-color: rgba(180,120,60,0.3); color: #8a5c2e; }
html[data-theme="light"] .cw-add-usage-btn,
body.light-mode .cw-add-usage-btn { border-color: rgba(180,120,60,0.3); color: #8a5c2e; }
html[data-theme="light"] .cw-btn--primary,
body.light-mode .cw-btn--primary { background: #8a5c2e; color: #fff; }
html[data-theme="light"] .cw-btn--ghost,
body.light-mode .cw-btn--ghost { background: rgba(180,120,60,0.07); border-color: rgba(180,120,60,0.2); color: #5a3a1a; }
html[data-theme="light"] .cw-field label,
body.light-mode .cw-field label { color: rgba(60,40,20,0.55); }
html[data-theme="light"] .cw-req-note,
body.light-mode .cw-req-note { color: rgba(60,40,20,0.4); }
html[data-theme="light"] .cw-close-btn,
body.light-mode .cw-close-btn { color: rgba(60,40,20,0.4); }
html[data-theme="light"] .cw-close-btn:hover,
body.light-mode .cw-close-btn:hover { color: #3d2b1a; background: rgba(180,120,60,0.08); }

/* ─── Mobile (< 580px) ──────────────────────────────────────────── */
@media (max-width: 580px) {
  .cw-modal {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 16px 16px 0 0;
    align-self: flex-end;
  }
  .cw-overlay { align-items: flex-end; }
  .cw-row--3 { grid-template-columns: 1fr 1fr; }
  .cw-row--3 .cw-field:last-child { grid-column: 1 / -1; }
  .cw-modal__body { padding: 14px 14px; }
  .cw-modal__footer { padding: 12px 14px; }
}
