/* ==========================================================================
   Pokémon Rivals - shared layout & components.
   Themes (theme-3ds.css, theme-gameboy.css, theme-wii.css) set the variables and the look.
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: var(--fs);
  color: var(--text);
  background: var(--page-bg);
  min-height: 100dvh;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
img { -webkit-user-drag: none; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------- device ---- */
/* The console stretches to fill the window in every theme, leaving only a thin margin. */
#stage {
  --stage-pad: 6px;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--stage-pad);
}
.device {
  position: relative;
  width: 100%;
  height: calc(100dvh - 2 * var(--stage-pad));
  min-height: 560px;
  display: flex;
  flex-direction: column;
}
.lid { position: relative; flex: 0 0 46%; display: flex; flex-direction: column; min-height: 250px; }
.bezel { position: relative; display: flex; align-items: stretch; }
.bezel-top { flex: 1 1 auto; min-height: 0; }
.screen-wrap { position: relative; flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; }
.screen { position: relative; flex: 1 1 auto; min-width: 0; overflow: hidden; }
.overlay { position: absolute; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.overlay > * { pointer-events: auto; }
.hinge { flex: 0 0 auto; }
.base {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr minmax(0, 4.4fr) 1fr;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "left screen right" "strip strip strip";
}
.bezel-bottom { grid-area: screen; min-height: 0; }
.deco-left { grid-area: left; }
.deco-right { grid-area: right; }
.base-strip { grid-area: strip; }
.gb-grille, .ab, .wii-sensor, .wii-bar { display: none; }

.screen-top, .screen-bottom { display: flex; flex-direction: column; }

/* Scrollable regions inside screens */
.scroll { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 8px; }

/* ----------------------------------------------------------- generic ----- */
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1 1 auto; min-width: 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.tiny { font-size: var(--fs-xs); }
.nowrap { white-space: nowrap; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hint { font-size: var(--fs-sm); color: var(--muted); margin: 6px 2px 0; }
.spacer { flex: 1 1 auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ----------------------------------------------------------- buttons ----- */
.btn {
  appearance: none;
  border: var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-text);
  border-radius: var(--btn-radius);
  padding: 8px 14px;
  font-weight: 800;
  font-size: var(--fs);
  line-height: 1.15;
  cursor: pointer;
  box-shadow: var(--btn-shadow);
  transition: transform .08s ease, filter .12s ease, box-shadow .12s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  min-height: 36px;
  user-select: none;
}
.btn:hover:not([disabled]) { filter: var(--btn-hover); }
.btn:active:not([disabled]) { transform: translateY(1px) scale(.985); box-shadow: var(--btn-shadow-active); }
.btn:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; filter: grayscale(.4); }
.btn.primary { background: var(--btn-primary-bg); color: var(--btn-primary-text); border: var(--btn-primary-border); }
.btn.danger { background: var(--btn-danger-bg); color: var(--btn-danger-text); border: var(--btn-danger-border); }
.btn.ghost { background: var(--btn-ghost-bg); color: var(--btn-ghost-text); box-shadow: none; }
.btn.small { padding: 4px 10px; min-height: 28px; font-size: var(--fs-sm); }
.btn.block { width: 100%; }
.btn small { display: block; font-weight: 600; opacity: .75; font-size: var(--fs-xs); }
.btn-col { flex-direction: column; gap: 2px; }

.icon-btn {
  appearance: none; border: var(--btn-border); background: var(--btn-bg); color: var(--btn-text);
  border-radius: var(--btn-radius); width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center;
  cursor: pointer; box-shadow: var(--btn-shadow); font-weight: 900;
}
.icon-btn .pxi { width: 16px; height: 16px; }

/* ----------------------------------------------------------- inputs ------ */
.input, select.input, textarea.input {
  width: 100%;
  border: var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: var(--input-radius);
  padding: 9px 11px;
  font-weight: 700;
  outline: none;
}
.input:focus { box-shadow: var(--input-focus); }
textarea.input { resize: vertical; min-height: 90px; line-height: 1.35; }

.toggle { position: relative; display: inline-flex; align-items: center; cursor: pointer; flex: 0 0 auto; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .track { width: 46px; height: 26px; border-radius: 26px; background: var(--toggle-off); border: var(--toggle-border); position: relative; transition: background .15s; }
.toggle .track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--toggle-knob); box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.toggle input:checked + .track { background: var(--toggle-on); }
.toggle input:checked + .track::after { transform: translateX(20px); }
.toggle input:focus-visible + .track { outline: var(--focus-ring); outline-offset: 2px; }
.toggle input:disabled + .track { opacity: .5; }

input[type=range].range { width: 100%; accent-color: var(--accent); }

.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.check-chip { position: relative; cursor: pointer; }
.check-chip input { position: absolute; opacity: 0; pointer-events: none; }
.check-chip span {
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 6px 6px; min-height: 32px; border-radius: var(--chip-radius); border: var(--chip-border);
  background: var(--chip-bg); font-weight: 800; font-size: var(--fs-sm); line-height: 1.1;
}
.check-chip input:checked + span { background: var(--chip-on-bg); color: var(--chip-on-text); border-color: transparent; }
.check-chip input:focus-visible + span { outline: var(--focus-ring); }
.check-chip input:disabled + span { opacity: .5; cursor: not-allowed; }

/* ---------------------------------------------------------- badges ------- */
.type-badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px 8px; border-radius: var(--badge-radius); font-size: var(--fs-xs);
  font-weight: 900; text-transform: uppercase; letter-spacing: .04em;
  background: var(--badge-bg, #888); color: var(--badge-text, #fff);
  border: var(--badge-border); white-space: nowrap;
}
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px;
  border-radius: 999px; background: var(--chip-bg); border: var(--chip-border);
  font-weight: 800; font-size: var(--fs-xs); white-space: nowrap;
}
.bar { position: relative; height: 7px; border-radius: 7px; background: var(--bar-bg); overflow: hidden; border: var(--bar-border); }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--bar-fill); border-radius: inherit; }
.bar.rage > i { background: var(--rage-fill); }
.bar.rage.warn > i { background: var(--rage-warn); }
.bar.rage.hot > i { background: var(--rage-hot); }

.mon-sprite { image-rendering: auto; object-fit: contain; pointer-events: none; }
.sprite-pixel, .sprite-animated, [data-theme="gameboy"] .mon-sprite { image-rendering: pixelated; }
.mon-sprite.sprite-missing { opacity: 0; }
.mon-sprite.gb-filter { filter: grayscale(1) sepia(1) hue-rotate(40deg) saturate(1.5) contrast(1.2); }
.item-icon { width: 28px; height: 28px; object-fit: contain; image-rendering: pixelated; flex: 0 0 auto; display: inline-block; }
/* Hand-drawn pixel icons (js/ui/pixelart.js). Sizes are kept at multiples of 16 where it matters. */
.pxi { display: inline-block; flex: 0 0 auto; line-height: 0; }
.pxi svg { width: 100%; height: 100%; display: block; overflow: visible; }

/* ---------------------------------------------------------- overlays ----- */
.textbox {
  position: absolute; left: 12px; right: 12px; bottom: 12px;
  min-height: 74px; padding: 14px 18px 18px;
  background: var(--textbox-bg); border: var(--textbox-border); border-radius: var(--textbox-radius);
  box-shadow: var(--textbox-shadow); color: var(--textbox-text);
  font-weight: 700; font-size: var(--fs-lg); line-height: 1.38;
  white-space: pre-wrap; cursor: pointer; z-index: 30;
  opacity: 0; transform: translateY(10px); transition: opacity .16s ease, transform .16s ease;
}
.textbox-text { max-height: min(42cqh, 220px); overflow-y: auto; }
#top-overlay { container-type: size; }
.textbox.show { opacity: 1; transform: none; }
.textbox.hide { opacity: 0; transform: translateY(6px); }
.textbox-speaker {
  position: absolute; top: -14px; left: 16px; padding: 2px 12px; border-radius: 10px;
  background: var(--speaker-bg); color: var(--speaker-text); font-size: var(--fs-sm); font-weight: 900;
}
.textbox-arrow { position: absolute; right: 14px; bottom: 6px; font-size: 12px; color: var(--accent-2); opacity: 0; }
.textbox.done .textbox-arrow { opacity: 1; animation: bob 0.8s ease-in-out infinite; }
.textbox.danger { --textbox-border: var(--textbox-border-danger); }
.textbox.good { --textbox-border: var(--textbox-border-good); }

.choices {
  position: absolute; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: stretch; justify-content: center;
  gap: 10px; padding: 18px clamp(18px, 10%, 90px);
  background: var(--choices-scrim);
  opacity: 0; transition: opacity .14s ease;
  overflow-y: auto;
}
.choices.many { justify-content: flex-start; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); align-content: center; }
.choices.show { opacity: 1; }
.choices.hide { opacity: 0; }
.choices .choice { min-height: 48px; font-size: var(--fs-lg); }

.sheet {
  position: absolute; inset: 0; z-index: 35;
  display: flex; flex-direction: column;
  background: var(--sheet-bg);
  border: var(--sheet-border); border-radius: var(--sheet-radius);
  transform: translateY(16px); opacity: 0; transition: opacity .16s ease, transform .16s ease;
}
.sheet.show { transform: none; opacity: 1; }
.sheet.hide { transform: translateY(12px); opacity: 0; }
.sheet-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px 8px 16px;
  background: var(--sheet-head-bg); color: var(--sheet-head-text);
  border-bottom: var(--sheet-head-border); border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
}
.sheet-titles { flex: 1 1 auto; min-width: 0; }
.sheet-title { font-weight: 900; font-size: var(--fs-lg); line-height: 1.15; }
.sheet-sub { font-size: var(--fs-sm); opacity: .85; font-weight: 700; }
.sheet-close { appearance: none; border: 0; background: var(--sheet-close-bg); color: inherit; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-weight: 900; }
.sheet-body { flex: 1 1 auto; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.sheet-actions { display: flex; gap: 8px; padding: 10px 12px; border-top: var(--sheet-head-border); flex-wrap: wrap; }
.sheet-actions .btn { flex: 1 1 0; min-width: 90px; }
.prompt-sheet { inset: auto 0 0 0; height: auto; max-height: 100%; }

.info-card {
  position: absolute; left: 14px; right: 14px; top: 14px; z-index: 25;
  background: var(--card-bg); border: var(--card-border); border-radius: var(--card-radius);
  box-shadow: var(--card-shadow); padding: 12px 14px; max-height: calc(100% - 28px); overflow-y: auto;
}

.top-scene { position: absolute; inset: 0; z-index: 27; opacity: 0; transition: opacity .25s ease; }
.top-scene.show { opacity: 1; }
.top-scene.hide { opacity: 0; }

#toast-layer { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--toast-bg); color: var(--toast-text); border: var(--toast-border); padding: 9px 16px; border-radius: var(--btn-radius); font-weight: 800; box-shadow: var(--card-shadow); opacity: 0; transform: translateY(-8px); transition: all .2s ease; }
.toast.show { opacity: 1; transform: none; }
.toast.hide { opacity: 0; }

/* -------------------------------------------------------- panels/cards --- */
.panel { background: var(--panel-bg); border: var(--panel-border); border-radius: var(--panel-radius); padding: 10px 12px; box-shadow: var(--panel-shadow); }
.panel-title { font-weight: 900; font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .06em; color: var(--panel-title); margin: 0 0 6px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.list-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  background: var(--item-bg); border: var(--item-border); border-radius: var(--item-radius);
  cursor: pointer; text-align: left; width: 100%;
}
.list-item:hover { background: var(--item-hover); }
.list-item.selected { outline: 2px solid var(--accent); }
.list-item[disabled], .list-item.disabled { opacity: .5; cursor: not-allowed; }
.list-item .mon-sprite { width: 44px; height: 44px; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { appearance: none; border: var(--tab-border); background: var(--tab-bg); color: var(--tab-text); padding: 5px 11px; border-radius: 999px; font-weight: 800; font-size: var(--fs-sm); cursor: pointer; white-space: nowrap; }
.tab.active { background: var(--tab-active-bg); color: var(--tab-active-text); }

/* ------------------------------------------------------ loading screen --- */
.boot { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; }
.boot-bar { width: min(380px, 80%); height: 14px; border-radius: 10px; background: var(--bar-bg); border: var(--bar-border); overflow: hidden; }
.boot-bar > i { display: block; height: 100%; width: 0; background: var(--bar-fill); transition: width .25s ease; }

/* ------------------------------------------------------- animations ------ */
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(3px); } }
@keyframes idle { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-3px) scale(1.015, .985); } }
@keyframes pop-in { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
@keyframes slide-in-right { from { transform: translateX(60%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shake { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-22deg); } 75% { transform: rotate(22deg); } }
@keyframes flash { 0% { opacity: 0; } 30% { opacity: 1; } 100% { opacity: 0; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 0 var(--glow); } 50% { box-shadow: 0 0 0 5px var(--glow); } }

[data-motion="reduced"] *, [data-motion="reduced"] *::before, [data-motion="reduced"] *::after {
  animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition-duration: 0.001s !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; }
}

/* ---------------------------------------------------------- responsive --- */
@media (max-width: 860px) {
  .base { grid-template-columns: 0 minmax(0, 1fr) 0; }
  .deco { display: none !important; }
}
@media (max-width: 640px), (max-height: 560px) {
  #stage { padding: 0; align-items: stretch; }
  .device { height: auto; min-height: 100dvh; width: 100%; }
  .lid { flex: 0 0 auto; min-height: 0; }
  .bezel-top .screen-wrap { min-height: 280px; }
  .base { grid-template-rows: auto auto; }
  .bezel-bottom .screen-wrap { min-height: 460px; }
}
