/* Wordnest – shared UI pieces: buttons, flags, language picker (popup + bottom sheet), toasts. */

.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-1); min-height: var(--tap);
  padding: 0 var(--space-2); border: 2px solid var(--c-text-muted); border-radius: var(--radius-pill); background: var(--c-surface);
  color: var(--c-text); font-weight: var(--fw-heavy); }
.btn.primary { background: var(--c-selected); border-color: transparent; color: var(--c-on-selected); }
.btn.secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-text-muted); }
.btn.danger { background: var(--c-error); border-color: transparent; color: var(--c-on-error); }
.btn.danger-outline { background: var(--c-surface); color: var(--c-text); border-color: var(--c-error); }

/* ---------- Confirm dialog (ui/dialog.js) ---------- */
.dialog { position: absolute; left: var(--space-2); right: var(--space-2); top: 50%; z-index: 6; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3); border-radius: var(--radius-lg);
  background: var(--c-surface); box-shadow: 0 12px 32px rgb(0 0 0 / 0.3); }
.dialog h2 { font-size: var(--fs-xl); }
.dialog .actions { display: flex; gap: var(--space-1); justify-content: flex-end; }
.dialog .btn:focus-visible { outline: var(--focus-ring) solid var(--c-focus); outline-offset: 2px; }

/* ---------- Find me first-use rules (ui/find-rules.js) ---------- */
.find-rules { max-height: calc(100% - var(--space-2)); overflow-y: auto; padding: var(--space-2); gap: var(--space-0-5); }
.find-rules > p { line-height: var(--lh); }
.find-rules .rules-examples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-0-5); }
.find-rules .rules-example { display: flex; flex-direction: column; align-items: center; gap: var(--space-0-5); min-width: 0;
  padding: var(--space-1); border-radius: var(--radius); background: var(--c-bg); text-align: center; }
.find-rules .rules-example h3 { font-size: var(--fs-sm); }
.find-rules .rules-example p { font-size: var(--fs-xs); line-height: var(--lh-tight); color: var(--c-text-muted); }
.find-rules .rules-board { display: grid; gap: 2px; }
.find-rules .rules-board.horizontal { grid-template-columns: repeat(4, 24px); }
.find-rules .rules-board.vertical { grid-template-columns: 24px; grid-template-rows: repeat(4, 24px); }
.find-rules .rules-board.shared { grid-template-columns: repeat(3, 24px); }
.find-rules .rules-board.partial { grid-template-columns: repeat(5, 18px); }
.find-rules .rules-board.partial .rules-cell { width: 18px; height: 18px; font-size: var(--fs-xs); }
.find-rules .rules-cell { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 5px;
  background: var(--c-surface); font-size: var(--fs-sm); font-weight: var(--fw-heavy); }
.find-rules .rules-cell.found { background: var(--c-found); color: var(--c-on-found); }
.find-rules .rules-cell.shared { opacity: 0.5; }
.find-rules .rules-example.shared-example p { max-width: 30em; }
.find-rules .rules-cell.partial { background: var(--c-accent); color: var(--c-on-accent); outline: 2px solid var(--c-text); outline-offset: -2px; }
.find-rules .actions.find-rules-actions { flex-direction: column; }
.find-rules .actions .btn { width: 100%; }
@media (max-width: 340px) {
  .find-rules .rules-board.partial { grid-template-columns: repeat(5, 16px); }
  .find-rules .rules-board.partial .rules-cell { width: 16px; height: 16px; }
}

/* ---------- Wrap-up overlay (ui/wrapup.js) ---------- */
.wrapup { position: absolute; left: var(--space-2); right: var(--space-2); top: 50%; z-index: 6; transform: translateY(-50%);
  max-height: calc(100% - var(--space-2)); overflow-x: hidden; overflow-y: auto; background: var(--c-surface); border-radius: var(--radius-lg);
  padding: var(--space-2) var(--space-3); box-shadow: 0 12px 32px rgb(0 0 0 / 0.3); display: flex; flex-direction: column; gap: 12px;
  text-align: center; }
.wrapup .egg { width: 56px; height: 56px; margin: 0 auto -4px; }
.wrapup h2 { font-size: var(--fs-2xl); font-weight: var(--fw-black); line-height: var(--lh-tight); }
.wrapup .results { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-1); }
.wrapup .results div { padding: var(--space-1); border-radius: var(--radius); background: var(--c-bg); }
.wrapup .results b { display: block; font-size: var(--fs-2xl); font-weight: var(--fw-black); line-height: 1.1; }
.wrapup .results span { display: block; font-size: var(--fs-sm); color: var(--c-text-muted); font-weight: var(--fw-bold); line-height: var(--lh-tight); }
.wrapup .lvl { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.wrapup .lvl .head { display: flex; align-items: center; gap: var(--space-1); font-size: var(--fs-sm); font-weight: var(--fw-heavy); }
.wrapup .lvl .head .count { margin-left: auto; }
.wrapup .lvl .bar { height: 10px; }
.wrapup .lvl .bar > .gain { background: var(--c-selected); }
.wrapup .lvl .legend { font-size: var(--fs-xs); color: var(--c-text-muted); }
.wrapup .milestone { display: flex; align-items: center; justify-content: center; gap: 6px; font-weight: var(--fw-bold); line-height: var(--lh-tight); }
.wrapup .milestone .i { flex: none; width: 20px; height: 20px; color: var(--c-text-muted); }
.wrapup .actions { display: flex; flex-direction: column; gap: var(--space-1); }
.wrapup .actions .row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-1); }
.wrapup .actions .row .btn { gap: 6px; padding: 0 10px; font-size: var(--fs-sm); white-space: nowrap; }
.wrapup .btn .i { width: 18px; height: 18px; }
.wrapup .btn:focus-visible { outline: var(--focus-ring) solid var(--c-focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .wrapup .bar > span { transition: none !important; } }

.flag { width: 30px; height: 20px; flex: none; object-fit: cover; border-radius: 2px; }
.flag.sm { width: 24px; height: 16px; }

/* ---------- Language picker ---------- */
.picker { position: relative; }
.picker-btn { display: flex; align-items: center; gap: var(--space-1); width: 100%; min-height: 52px; padding: 0 var(--space-1) 0 var(--space-2);
  border: 2px solid var(--c-text-muted); border-radius: var(--radius); background: var(--c-surface); color: var(--c-text);
  font-weight: var(--fw-bold); text-align: left; }
.picker-btn .name { flex: 1; }
.picker-btn .native, .option .native { color: var(--c-text-muted); font-weight: var(--fw-regular); }
.picker-btn[aria-expanded="true"] { border-color: var(--c-selected); }

.backdrop { position: absolute; inset: 0; z-index: 5; background: rgb(20 23 28 / 0.55); }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; max-height: 80%; overflow-y: auto; background: var(--c-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: 0 -8px 24px rgb(0 0 0 / 0.2);
  padding: var(--space-1) var(--space-2) calc(var(--space-2) + env(safe-area-inset-bottom)); }
.sheet .handle { width: 40px; height: 4px; margin: 0 auto var(--space-2); border-radius: var(--radius-pill); background: var(--c-text-muted); }
.sheet h2 { margin-bottom: var(--space-1); font-size: var(--fs-lg); }
.popup { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 6; max-height: 320px; overflow-y: auto; padding: 4px;
  border-radius: var(--radius); background: var(--c-surface); box-shadow: var(--shadow), 0 0 0 1px var(--c-border); }

.popup.up { top: auto; bottom: calc(100% + 4px); }
.listbox { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.listbox:focus-visible { outline: none; }
.option { display: flex; align-items: center; gap: var(--space-2); min-height: 56px; padding: 0 var(--space-2); border-radius: var(--radius);
  font-weight: var(--fw-bold); cursor: pointer; }
.option .name { flex: 1; }
.option[aria-selected="true"] { background: color-mix(in srgb, var(--c-selected) 12%, var(--c-surface)); box-shadow: inset 0 0 0 2px var(--c-selected); }
.option .check { flex: none; color: var(--c-selected); }
.option.focus { outline: var(--focus-ring) solid var(--c-focus); outline-offset: -3px; }
@media (min-width: 600px) { .option { min-height: 48px; } }

/* ---------- Toasts: inverted card over the bottom of the play area ---------- */
.toast-layer { position: absolute; left: var(--space-2); right: var(--space-2); bottom: var(--space-2); z-index: 4; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 12px; padding: 12px var(--space-2); border-radius: var(--radius);
  background: var(--c-text); color: var(--c-bg); box-shadow: 0 8px 24px rgb(0 0 0 / 0.25); pointer-events: none;
  animation: fx-toast-in var(--dur) var(--ease) both; }
.toast .badge { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--c-accent); color: var(--c-on-accent); }
.toast .txt { flex: 1; }
.toast strong { display: block; font-size: var(--fs-md); font-weight: var(--fw-heavy); }
.toast .txt span { font-size: var(--fs-sm); }
.toast.actionable { pointer-events: auto; }
.toast .toast-btn { min-height: 36px; padding: 0 12px; border-color: transparent; background: var(--c-bg); color: var(--c-text); font-size: var(--fs-sm); }
