/* Production app-shell overrides — neutralize design-canvas + bezel framing */

html, body, #root {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  background: var(--bg) !important;
  font-family: 'Inter', 'Noto Sans Thai', -apple-system, system-ui, sans-serif;
}

:lang(th), [lang="th"] { font-family: 'Noto Sans Thai', 'Inter', sans-serif; }

#root {
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
}

/* App shell — fills the viewport on mobile, capped width on desktop */
.app-shell {
  width: 100%;
  max-width: 100vw;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Cap content width on large screens for a tablet-like layout */
@media (min-width: 720px) {
  #root {
    align-items: center;
    background: var(--bg-2);
  }
  .app-shell {
    max-width: 480px;
    min-height: min(100dvh, 920px);
    height: min(100dvh, 920px);
    border-radius: 24px;
    box-shadow: 0 30px 80px rgba(124, 92, 255, 0.18), 0 0 0 1px var(--border);
    overflow: hidden;
  }
}

/* Reset frame chrome inherited from design canvas */
.app-shell .frame,
.app-shell .frame.mobile,
.app-shell .frame.desktop {
  width: 100%;
  height: 100%;
  border-radius: 0;
  background: var(--bg);
}

/* PWA install prompt — small floating banner */
.pwa-install {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 14px 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  z-index: 9999;
  animation: pwaSlide 240ms ease-out;
}
.pwa-install button {
  background: var(--purple);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}
.pwa-install .pwa-close {
  background: transparent;
  color: var(--text-3);
  font-size: 18px;
  padding: 0 4px;
}
@keyframes pwaSlide {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* Splash — shown until React renders */
.splash {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 99999;
  font-family: 'Inter', sans-serif;
  font-weight: 900;
  letter-spacing: 0.18em;
  font-size: 24px;
  color: var(--text);
}
.splash.hide { opacity: 0; pointer-events: none; transition: opacity 200ms ease; }

/* status bar (used inside frame) — hide on real devices */
.app-shell .status-bar { display: none; }

/* Make sure pause/countdown overlays use the shell box, not viewport */
.wp-root, .wo-root, .wc-root, .ws-root, .wpr-root, .wl-root, .wlp-root, .we-root {
  position: absolute;
  inset: 0;
}

/* Error boundary fallback */
.eb-root {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 24px;
  z-index: 100000;
}
.eb-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 22px;
  text-align: center;
}
.eb-icon { font-size: 48px; margin-bottom: 12px; }
.eb-title {
  font-size: 22px; font-weight: 800;
  margin-bottom: 8px;
}
.eb-sub {
  color: var(--text-2);
  font-size: 14px; line-height: 1.5;
  margin-bottom: 16px;
}
.eb-trace {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--danger);
  padding: 10px;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 140px;
  overflow: auto;
  margin-bottom: 16px;
}
.eb-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.eb-btn {
  flex: 1; min-width: 100px;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.eb-btn.primary { background: var(--purple); color: #fff; border-color: var(--purple); }
.eb-btn.danger  { background: transparent;   color: var(--danger); border-color: var(--danger); }
.eb-btn.ghost   { background: transparent; }

/* ===== Vocab / flash-card screen ===== */
.wvb-root { background: var(--bg); overflow-y: auto; padding-bottom: 24px; }
.wvb-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  padding: 0 16px 12px;
}
.wvb-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
}
.wvb-stat-num {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800; font-size: 20px; color: var(--text);
}
.wvb-stat-lbl {
  font-size: 9px; font-weight: 700; letter-spacing: 0.1em;
  color: var(--text-3); margin-top: 2px;
}

.wvb-tools { padding: 0 16px 8px; }
.wvb-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--text-3);
}
.wvb-search input {
  flex: 1; background: transparent; border: 0; outline: none;
  font: inherit; color: var(--text); font-size: 14px;
}
.wvb-search-clear {
  background: var(--bg-2); border: 0; color: var(--text-3);
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 16px;
}
.wvb-sort {
  display: flex; gap: 6px; overflow-x: auto;
  padding: 10px 0 2px;
  -ms-overflow-style: none; scrollbar-width: none;
}
.wvb-sort::-webkit-scrollbar { display: none; }
.wvb-sort-pill {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: 999px;
  padding: 6px 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  cursor: pointer;
  white-space: nowrap;
}
.wvb-sort-pill.on {
  background: var(--purple); color: #fff; border-color: var(--purple);
}

.wvb-list {
  padding: 6px 16px 24px;
  display: flex; flex-direction: column; gap: 6px;
}
.wvb-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  text-align: left;
  transition: transform 80ms ease, border-color 120ms ease;
}
.wvb-row:active { transform: translateY(1px); }
.wvb-row:hover  { border-color: var(--purple); }
.wvb-row-word {
  font-weight: 800; font-size: 15px; letter-spacing: 0.04em;
}
.wvb-row-meta {
  display: flex; align-items: center; gap: 10px;
  font-family: 'JetBrains Mono', monospace; font-size: 11px;
}
.wvb-row-count { color: var(--gold); font-weight: 700; }
.wvb-row-combo { color: var(--orange); font-weight: 700; }
.wvb-row-time  { color: var(--text-3); }
.wvb-more {
  text-align: center; color: var(--text-3);
  font-size: 11px; font-family: 'JetBrains Mono', monospace;
  padding: 16px 0;
}

.wvb-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: 40px 24px;
  color: var(--text-2);
}
.wvb-empty-icon { font-size: 48px; margin-bottom: 12px; }
.wvb-empty-title { font-weight: 800; font-size: 18px; color: var(--text); margin-bottom: 4px; }
.wvb-empty-sub   { font-size: 13px; }

/* Detail modal */
.wvb-modal-root {
  position: absolute; inset: 0;
  z-index: 9000;
  display: flex; align-items: flex-end; justify-content: center;
}
.wvb-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
}
.wvb-modal-card {
  position: relative;
  width: 100%;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  padding: 28px 22px 32px;
  animation: vcbSlideUp 280ms cubic-bezier(.2,.8,.2,1);
}
@keyframes vcbSlideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.wvb-modal-close {
  position: absolute; top: 12px; right: 12px;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg-2); border: 0; cursor: pointer;
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
}
.wvb-modal-word {
  font-size: 32px; font-weight: 900; letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.wvb-modal-phon {
  color: var(--text-3); font-family: 'JetBrains Mono', monospace; font-size: 12px;
  margin-bottom: 16px;
}
.wvb-modal-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin: 12px 0 14px;
}
.wvb-modal-stat {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.wvb-modal-stat-num {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800; font-size: 18px; color: var(--text);
}
.wvb-modal-stat-lbl {
  font-size: 9px; font-weight: 700; letter-spacing: 0.1em;
  color: var(--text-3); margin-top: 2px;
}
.wvb-modal-times {
  display: flex; justify-content: space-between;
  color: var(--text-3); font-size: 11px;
  margin: 8px 0 14px;
}
.wvb-modal-times strong { color: var(--text-2); }
.wvb-modal-def {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  color: var(--text-2);
  font-size: 14px; line-height: 1.55;
}
.wvb-modal-def-loading,
.wvb-modal-def-empty {
  color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  text-align: center;
  padding: 16px 0;
}
.wvb-modal-pos {
  color: var(--purple); font-weight: 700; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.1em;
  margin-bottom: 6px;
}
.wvb-modal-def-line { margin-bottom: 6px; }
.wvb-modal-example {
  font-style: italic;
  color: var(--text-3);
  border-left: 2px solid var(--purple);
  padding-left: 10px;
  margin-top: 8px;
}

/* Profile screen — Vocab CTA row */
.wpr-vocab-cta {
  display: flex; align-items: center; gap: 12px;
  width: calc(100% - 32px); margin: 4px 16px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  color: var(--text);
  cursor: pointer; font: inherit;
  text-align: left;
  transition: border-color 120ms ease;
}
.wpr-vocab-cta:hover  { border-color: var(--purple); }
.wpr-vocab-cta:active { transform: translateY(1px); }
.wpr-vocab-icon  { font-size: 26px; }
.wpr-vocab-meta  { flex: 1; display: flex; flex-direction: column; }
.wpr-vocab-title { font-weight: 800; font-size: 13px; letter-spacing: 0.08em; }
.wpr-vocab-sub   { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.wpr-vocab-chev  { color: var(--text-3); font-size: 24px; font-weight: 300; }

/* Result screen — NEW WORDS pill */
.wr-new-words {
  display: inline-flex; align-items: center; gap: 8px;
  margin: 12px auto 0;
  background: linear-gradient(135deg, rgba(255, 216, 77, 0.18), rgba(124, 92, 255, 0.18));
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text);
  animation: newWordsPop 480ms cubic-bezier(.2,.8,.2,1);
}
@keyframes newWordsPop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.wr-new-words-icon { font-size: 18px; }
.wr-new-words-num  {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800; font-size: 18px; color: var(--gold);
}
.wr-new-words-lbl  { font-weight: 700; letter-spacing: 0.04em; }

/* Gameplay — NEW WORD floater variant */
.wg-floater.new-word {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-shadow: 0 0 12px var(--gold);
  animation-duration: 1.4s !important;
}
