/* ============================================================
   Emordle — Global Styles
   Dark, moody, clean. Elder emo aesthetic without clichés.
   Mobile-first, BEM-influenced class names prefixed emordle-.
   ============================================================ */

/* ── Custom properties ──────────────────────────────────────────────────── */
:root {
  --em-bg:            #0f0f11;
  --em-surface:       #18181c;
  --em-surface-2:     #1e1e24;
  --em-border:        #2a2a32;
  --em-text:          #e8e8f0;
  --em-text-muted:    #7070888;
  --em-text-dim:      #48485a;

  --em-accent:        #7c6af7;
  --em-accent-hover:  #6a58e8;
  --em-accent-glow:   rgba(124,106,247,0.18);

  --em-correct:       #3d8c5e;   /* green  */
  --em-present:       #b08a28;   /* yellow */
  --em-absent:        #3a3a46;   /* dark grey */

  --em-correct-text:  #fff;
  --em-present-text:  #fff;
  --em-absent-text:   #c0c0d0;

  /* High-contrast overrides applied via .emordle-app--hc */
  --em-hc-correct:    #f5793a;
  --em-hc-present:    #85c0f9;

  --em-tile-size:     clamp(48px, 11vw, 62px);
  --em-gap:           6px;
  --em-radius:        4px;
  --em-radius-lg:     12px;
  --em-radius-xl:     18px;

  --em-font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --em-mono:          'SF Mono', 'Fira Code', 'Cascadia Code', monospace;

  --em-shadow-modal:  0 24px 80px rgba(0,0,0,0.7), 0 4px 24px rgba(0,0,0,0.4);
  --em-transition:    180ms cubic-bezier(0.4,0,0.2,1);
}

/* ── High-contrast mode ─────────────────────────────────────────────────── */
.emordle-app--hc {
  --em-correct: var(--em-hc-correct);
  --em-present: var(--em-hc-present);
}

/* ── Reduce-motion ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
.emordle-app--reduce-motion * {
  animation-duration: 0.01ms !important;
  transition-duration: 0.01ms !important;
}

/* ── App wrapper ────────────────────────────────────────────────────────── */
.emordle-app {
  font-family: var(--em-font);
  background: var(--em-bg);
  color: var(--em-text);
  height: 100dvh;
  height: 100vh; /* fallback */
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.emordle-header {
  width: 100%;
  border-bottom: 1px solid var(--em-border);
  background: var(--em-bg);
  position: sticky;
  top: 0;
  z-index: 100;
}

.emordle-header__inner {
  max-width: 500px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.emordle-header__title-group {
  text-align: center;
  flex: 1;
}

.emordle-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin: 0;
  line-height: 1;
  background: linear-gradient(135deg, #fff 0%, #c0b8ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.emordle-subtitle {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--em-text-dim);
  margin: 3px 0 0;
}

.emordle-header__left {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
  min-width: 72px; /* matches __actions width so title stays centered */
}

.emordle-header__actions {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
  min-width: 72px;
  justify-content: flex-end;
}

/* Icon buttons (header) */
.emordle-icon-btn {
  background: none;
  border: none;
  color: var(--em-text-dim);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--em-transition), background var(--em-transition);
}
.emordle-icon-btn svg { width: 20px; height: 20px; }
.emordle-icon-btn:hover { color: var(--em-text); background: var(--em-surface-2); }
.emordle-icon-btn:focus-visible {
  outline: 2px solid var(--em-accent);
  outline-offset: 2px;
}


/* ── Identity strip ──────────────────────────────────────────────────────── */
.emordle-identity-strip {
  max-width: 500px;
  width: 100%;
  padding: 0 16px;
  margin-top: 6px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.emordle-identity-strip__inner {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--em-text-dim);
}
.emordle-identity-strip__streak {
  background: var(--em-accent-glow);
  border: 1px solid var(--em-accent);
  color: var(--em-accent);
  font-weight: 700;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 9999px;
}
.emordle-identity-strip__email {
  font-family: var(--em-mono);
  font-size: 12px;
  color: var(--em-text-muted);
}
.emordle-identity-strip__save-btn {
  background: none;
  border: 1px solid var(--em-border);
  color: var(--em-accent);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 9999px;
  cursor: pointer;
  transition: background var(--em-transition), border-color var(--em-transition);
}
.emordle-identity-strip__save-btn:hover {
  background: var(--em-accent-glow);
  border-color: var(--em-accent);
}
.emordle-identity-strip__disconnect-btn {
  background: none;
  border: none;
  color: var(--em-text-dim);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 4px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.emordle-identity-strip__disconnect-btn:hover { color: var(--em-text); }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.emordle-toast-container {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: min(360px, calc(100vw - 32px));
}

.emordle-toast {
  background: var(--em-text);
  color: var(--em-bg);
  font-size: 14px;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  animation: emordle-toast-in 200ms ease forwards;
  pointer-events: auto;
}
.emordle-toast--success { background: var(--em-correct); color: #fff; }
.emordle-toast--error   { background: #c0392b; color: #fff; }
.emordle-toast--fade-out { animation: emordle-toast-out 300ms ease forwards; }

@keyframes emordle-toast-in {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes emordle-toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-8px); }
}

/* ── Board ───────────────────────────────────────────────────────────────── */
.emordle-board-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  min-height: 0;
  padding: 8px 16px 4px;
  width: 100%;
  box-sizing: border-box;
}

.emordle-board {
  display: flex;
  flex-direction: column;
  gap: var(--em-gap);
}

.emordle-row {
  display: flex;
  gap: var(--em-gap);
}

/* Row shake animation (invalid word) */
.emordle-row--shake {
  animation: emordle-shake 500ms cubic-bezier(.36,.07,.19,.97);
}
@keyframes emordle-shake {
  10%, 90% { transform: translateX(-3px); }
  20%, 80% { transform: translateX(5px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}

/* ── Tile ────────────────────────────────────────────────────────────────── */
.emordle-tile {
  width: var(--em-tile-size);
  height: var(--em-tile-size);
  border: 2px solid var(--em-border);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(20px, 5vw, 26px);
  font-weight: 800;
  font-family: var(--em-font);
  letter-spacing: 0.02em;
  color: var(--em-text);
  border-radius: var(--em-radius);
  transition: border-color 80ms ease, transform 80ms ease;
  user-select: none;
  position: relative;
}

/* Tile states */
.emordle-tile[data-state="tbd"] {
  border-color: #5a5a70;
}
.emordle-tile[data-state="tbd"].emordle-tile--pop {
  animation: emordle-pop 100ms ease;
}
@keyframes emordle-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Tile reveal flip */
.emordle-tile[data-animation="flip-in"] {
  animation: emordle-flip-in 250ms ease forwards;
}
.emordle-tile[data-animation="flip-out"] {
  animation: emordle-flip-out 250ms ease forwards;
}
@keyframes emordle-flip-in {
  0%   { transform: scaleY(1); }
  100% { transform: scaleY(0); }
}
@keyframes emordle-flip-out {
  0%   { transform: scaleY(0); }
  100% { transform: scaleY(1); }
}

/* Tile result colours */
.emordle-tile[data-state="correct"] {
  background: var(--em-correct);
  border-color: var(--em-correct);
  color: var(--em-correct-text);
}
.emordle-tile[data-state="present"] {
  background: var(--em-present);
  border-color: var(--em-present);
  color: var(--em-present-text);
}
.emordle-tile[data-state="absent"] {
  background: var(--em-absent);
  border-color: var(--em-absent);
  color: var(--em-absent-text);
}

/* Win bounce */
.emordle-tile--win-bounce {
  animation: emordle-bounce 700ms cubic-bezier(0.36, 0.07, 0.19, 0.97) forwards;
}
@keyframes emordle-bounce {
  0%, 20% { transform: translateY(0); }
  40%     { transform: translateY(-16px); }
  50%     { transform: translateY(0); }
  60%     { transform: translateY(-8px); }
  80%     { transform: translateY(0); }
  100%    { transform: translateY(0); }
}

/* ── Keyboard ────────────────────────────────────────────────────────────── */
.emordle-keyboard {
  width: 100%;
  max-width: 500px;
  padding: 0 6px 8px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  flex-shrink: 0;
}

.emordle-keyboard__row {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.emordle-key {
  height: clamp(48px, 12vw, 58px);
  min-width: clamp(28px, 8vw, 40px);
  flex: 1;
  max-width: 44px;
  background: var(--em-surface-2);
  color: var(--em-text);
  border: 1px solid var(--em-border);
  border-radius: 6px;
  font-size: clamp(11px, 3.5vw, 14px);
  font-weight: 700;
  font-family: var(--em-font);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: background var(--em-transition), color var(--em-transition), transform 80ms ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.emordle-key:active { transform: scale(0.93); }
.emordle-key--wide {
  min-width: clamp(50px, 14vw, 64px);
  max-width: 72px;
  font-size: 12px;
}
.emordle-key:focus-visible {
  outline: 2px solid var(--em-accent);
  outline-offset: 2px;
}

/* Key states (match tile colours) */
.emordle-key[data-state="correct"] {
  background: var(--em-correct);
  border-color: var(--em-correct);
  color: #fff;
}
.emordle-key[data-state="present"] {
  background: var(--em-present);
  border-color: var(--em-present);
  color: #fff;
}
.emordle-key[data-state="absent"] {
  background: var(--em-absent);
  border-color: var(--em-absent);
  color: var(--em-text-dim);
}

/* ── Modals ──────────────────────────────────────────────────────────────── */
.emordle-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}
.emordle-modal[hidden] { display: none; }

.emordle-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.emordle-modal__content {
  position: relative;
  background: var(--em-surface);
  border: 1px solid var(--em-border);
  border-radius: var(--em-radius-xl);
  padding: 32px 28px;
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  box-shadow: var(--em-shadow-modal);
  animation: emordle-modal-in 200ms cubic-bezier(0.34,1.56,0.64,1) forwards;
}
@keyframes emordle-modal-in {
  from { opacity: 0; transform: scale(0.94) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.emordle-modal__title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  margin: 0 0 20px;
  color: var(--em-text);
}

.emordle-modal__close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--em-text-dim);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color var(--em-transition), background var(--em-transition);
}
.emordle-modal__close:hover { color: var(--em-text); background: var(--em-surface-2); }
.emordle-modal__close:focus-visible { outline: 2px solid var(--em-accent); }

/* ── Help modal body ─────────────────────────────────────────────────────── */
.emordle-help-body p { font-size: 14px; color: var(--em-text-muted); line-height: 1.6; margin: 0 0 12px; }
.emordle-help-body ul { font-size: 14px; color: var(--em-text-muted); padding-left: 18px; margin: 0 0 16px; }
.emordle-help-body ul li { margin-bottom: 6px; }
.emordle-help-examples { background: var(--em-surface-2); border-radius: var(--em-radius-lg); padding: 16px; margin: 8px 0; }
.emordle-help-row { display: flex; gap: 5px; margin: 10px 0 4px; }
.emordle-help-tile {
  width: 40px; height: 40px;
  border: 2px solid var(--em-border);
  border-radius: var(--em-radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800; color: var(--em-text);
}
.emordle-help-tile--correct { background: var(--em-correct); border-color: var(--em-correct); color: #fff; }
.emordle-help-tile--present { background: var(--em-present); border-color: var(--em-present); color: #fff; }
.emordle-help-tile--absent  { background: var(--em-absent);  border-color: var(--em-absent);  color: var(--em-absent-text); }
.emordle-help-desc { font-size: 13px; color: var(--em-text-muted); margin: 4px 0 14px; }
.emordle-help-note { font-size: 12px; color: var(--em-text-dim); border-top: 1px solid var(--em-border); padding-top: 12px; margin-top: 8px !important; }

/* ── Stats modal body ────────────────────────────────────────────────────── */
.emordle-stats-body { color: var(--em-text); }
.emordle-stats-numbers {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 24px;
}
.emordle-stat-item { text-align: center; }
.emordle-stat-item__value {
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
  color: var(--em-text);
}
.emordle-stat-item__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--em-text-dim);
  margin-top: 4px;
}

.emordle-stats-dist-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--em-text-dim);
  margin: 0 0 10px;
  font-weight: 600;
}
.emordle-dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 13px;
}
.emordle-dist-row__label {
  width: 12px;
  text-align: right;
  color: var(--em-text-muted);
  font-weight: 700;
  flex-shrink: 0;
}
.emordle-dist-row__bar-wrap {
  flex: 1;
  height: 20px;
  background: var(--em-surface-2);
  border-radius: 3px;
  overflow: hidden;
}
.emordle-dist-row__bar {
  height: 100%;
  background: var(--em-accent);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  min-width: 20px;
  transition: width 600ms cubic-bezier(0.4,0,0.2,1);
}
.emordle-dist-row__bar--highlight { background: var(--em-correct); }

/* ── Settings modal ──────────────────────────────────────────────────────── */
.emordle-settings-body { display: flex; flex-direction: column; gap: 4px; }
.emordle-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 4px;
  font-size: 15px;
  font-weight: 500;
  color: var(--em-text);
  border-bottom: 1px solid var(--em-border);
  cursor: pointer;
}
.emordle-toggle-row:last-of-type { border-bottom: none; }
.emordle-toggle-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 44px;
  height: 24px;
  background: var(--em-surface-2);
  border: 2px solid var(--em-border);
  border-radius: 9999px;
  position: relative;
  cursor: pointer;
  transition: background var(--em-transition), border-color var(--em-transition);
  flex-shrink: 0;
}
.emordle-toggle-row input[type="checkbox"]::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--em-text-dim);
  border-radius: 50%;
  transition: transform var(--em-transition), background var(--em-transition);
}
.emordle-toggle-row input[type="checkbox"]:checked {
  background: var(--em-accent);
  border-color: var(--em-accent);
}
.emordle-toggle-row input[type="checkbox"]:checked::before {
  transform: translateX(20px);
  background: #fff;
}
.emordle-toggle-row input[type="checkbox"]:focus-visible { outline: 2px solid var(--em-accent); outline-offset: 2px; }
.emordle-setting-desc { font-size: 12px; color: var(--em-text-dim); margin: 2px 0 10px; padding-bottom: 2px; border-bottom: 1px solid var(--em-border); }
.emordle-setting-desc:last-child { border-bottom: none; }

/* ── Result modal ────────────────────────────────────────────────────────── */
.emordle-result-body { margin-bottom: 20px; }
.emordle-result-band {
  text-align: center;
  margin-bottom: 16px;
}
.emordle-result-band__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--em-text-dim);
  margin-bottom: 4px;
}
.emordle-result-band__name {
  font-size: 22px;
  font-weight: 700;
  color: var(--em-text);
}
.emordle-result-actions {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

/* ── Streak save CTA ─────────────────────────────────────────────────────── */
.emordle-streak-cta {
  background: var(--em-surface-2);
  border: 1px solid var(--em-border);
  border-radius: var(--em-radius-lg);
  padding: 16px;
  text-align: center;
  margin-top: 4px;
}
.emordle-streak-cta p {
  font-size: 13px;
  color: var(--em-text-muted);
  margin: 0 0 12px;
  line-height: 1.5;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.emordle-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: 9999px;
  font-size: 14px;
  font-weight: 700;
  font-family: var(--em-font);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 13px 28px;
  cursor: pointer;
  transition: background var(--em-transition), transform 80ms ease, box-shadow var(--em-transition);
  text-decoration: none;
}
.emordle-btn:active { transform: scale(0.97); }
.emordle-btn:focus-visible { outline: 2px solid var(--em-accent); outline-offset: 3px; }

.emordle-btn--primary {
  background: var(--em-accent);
  color: #fff;
  width: 100%;
  justify-content: center;
  margin-top: 12px;
}
.emordle-btn--primary:hover { background: var(--em-accent-hover); box-shadow: 0 0 24px var(--em-accent-glow); }

.emordle-btn--share {
  background: var(--em-correct);
  color: #fff;
}
.emordle-btn--share:hover { background: #347a52; }

/* ── Form elements ───────────────────────────────────────────────────────── */
.emordle-field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--em-text-dim);
  margin-bottom: 6px;
}
.emordle-input {
  width: 100%;
  background: var(--em-bg);
  border: 1px solid var(--em-border);
  border-radius: 8px;
  color: var(--em-text);
  font-size: 15px;
  font-family: var(--em-font);
  padding: 12px 14px;
  box-sizing: border-box;
  transition: border-color var(--em-transition), box-shadow var(--em-transition);
}
.emordle-input:focus {
  outline: none;
  border-color: var(--em-accent);
  box-shadow: 0 0 0 3px var(--em-accent-glow);
}
.emordle-input::placeholder { color: var(--em-text-dim); }

.emordle-form-msg {
  font-size: 13px;
  margin-top: 10px;
  line-height: 1.5;
  text-align: center;
  min-height: 20px;
  color: var(--em-text-muted);
}
.emordle-form-msg--success { color: #5cb87a; }
.emordle-form-msg--error   { color: #e05c5c; }

/* ── Utilities ───────────────────────────────────────────────────────────── */
.emordle-divider {
  border: none;
  border-top: 1px solid var(--em-border);
  margin: 20px 0;
}
.emordle-text-sm { font-size: 13px; color: var(--em-text-dim); text-align: center; margin: 0; }
.emordle-link-btn {
  background: none;
  border: none;
  color: var(--em-accent);
  font-size: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.emordle-link-btn:hover { color: var(--em-accent-hover); }

/* ── reCAPTCHA badge ─────────────────────────────────────────────────────── */
.grecaptcha-badge { visibility: hidden !important; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 380px) {
  .emordle-modal__content { padding: 24px 16px; }
}
