/* ==========================================================================
   Royal Chess — menus.css
   Loading, title, mode-select screens and every modal panel.
   ========================================================================== */

/* ------------------------------------------------------------ loading */
#screen-loading {
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 45%, #2b170b 0%, #120905 70%);
  z-index: 50;
}
.loading-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.loading-crest { height: clamp(90px, 18vmin, 170px); filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.8)); animation: crestFloat 3s ease-in-out infinite; }
.logo-small .logo-royal { font-size: clamp(22px, 4.5vmin, 42px); }
.logo-small .logo-gambit { font-size: clamp(30px, 6.5vmin, 60px); }
.loading-bar {
  width: min(360px, 70vw);
  height: 14px;
  border-radius: 10px;
  padding: 3px;
  background: linear-gradient(#3a2508, #1a0f04);
  box-shadow: 0 0 0 2px #b38a3e, 0 0 0 3px #3a2508, 0 4px 10px rgba(0, 0, 0, 0.6);
}
.loading-fill {
  height: 100%;
  width: 0%;
  border-radius: 7px;
  background: linear-gradient(180deg, #43a07a, #135841 60%, #0b3a2a);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: width 0.25s ease;
}
.loading-text { margin: 0; font-size: clamp(15px, 2.4vmin, 20px); font-style: italic; color: var(--gold-light); opacity: 0.85; }

@keyframes crestFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* ------------------------------------------------------------ title: see royal-ui.css */
@keyframes dropIn { from { opacity: 0; transform: translateY(-40px) scale(0.9); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------ mode select */
#screen-mode {
  display: flex; flex-direction: column; align-items: center; justify-content: safe center; gap: 3.2vmin;
  overflow-y: auto; overflow-x: hidden;
  padding: calc(70px + var(--safe-top)) 0 calc(16px + var(--safe-bottom));
}
#screen-mode .corner { position: fixed; }
.screen-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(24px, 5.4vmin, 56px);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gold-light);
  text-shadow: 0 3px 0 #3b2508, 0 6px 16px rgba(0, 0, 0, 0.9);
  text-align: center;
}
.mode-cards { display: flex; gap: clamp(16px, 4vmin, 56px); align-items: flex-start; justify-content: center; flex-wrap: wrap; padding: 0 12px; }
.mode-col { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.mode-card {
  position: relative;
  width: clamp(230px, 36vmin, 360px);
  padding: clamp(14px, 2.4vmin, 26px) 16px clamp(16px, 2.6vmin, 26px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: url('../assets/images/ui/leather.jpg') center / 256px;
  border: 26px solid transparent;
  border-image: url('../assets/images/ui/frame.png') 64 / 26px round;
  background-clip: padding-box;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.6), inset 0 0 40px rgba(0, 0, 0, 0.6);
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
  animation: cardIn 0.6s cubic-bezier(.2, 1.3, .4, 1) both;
}
.mode-col:nth-child(2) .mode-card { animation-delay: 0.1s; }
.mode-card:hover { transform: translateY(-6px) scale(1.02); filter: brightness(1.1); box-shadow: 0 22px 40px rgba(0, 0, 0, 0.7), 0 0 30px rgba(246, 227, 163, 0.25), inset 0 0 40px rgba(0, 0, 0, 0.5); }
.mode-card:active { transform: scale(0.98); }
.mode-art { display: flex; align-items: flex-end; justify-content: center; gap: 4px; height: clamp(90px, 15vmin, 150px); margin: -10px 0 0; }
.mode-art img { height: 100%; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.7)); transition: transform 0.3s ease; }
.mode-card:hover .art-l { transform: translateX(-6px) rotate(-4deg); }
.mode-card:hover .art-r { transform: translateX(6px) rotate(4deg); }
.vs {
  align-self: center;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(20px, 3.6vmin, 34px);
  color: var(--gold);
  text-shadow: 0 2px 0 #2c1a05, 0 0 12px rgba(0, 0, 0, 0.8);
  text-transform: uppercase;
}
.mode-name {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-head);
  font-weight: 800;
  font-size: clamp(16px, 2.6vmin, 24px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-light);
  text-shadow: 0 2px 0 #031810;
}
.mode-name img { width: 1.4em; height: 1.4em; }
.mode-desc { font-size: clamp(14px, 2.1vmin, 19px); font-style: italic; color: rgba(247, 238, 215, 0.85); }
.mode-key { position: absolute; top: -8px; right: -6px; font-size: 13px; }

.difficulty {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(6, 26, 19, 0.75);
  box-shadow: 0 0 0 2px var(--gold-dark), 0 6px 14px rgba(0, 0, 0, 0.6);
  animation: cardIn 0.6s 0.2s cubic-bezier(.2, 1.3, .4, 1) both;
}
.diff {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: clamp(70px, 11vmin, 104px);
  padding: 6px 8px 7px;
  border-radius: 10px;
  background: linear-gradient(#1a3f31, #0b261d);
  box-shadow: inset 0 0 0 1px rgba(217, 178, 95, 0.4);
  color: rgba(247, 238, 215, 0.6);
  transition: all 0.15s ease;
}
.diff .stars { font-size: clamp(14px, 2.2vmin, 20px); letter-spacing: 0.05em; color: #7d6a3e; }
.diff .diff-name { font-family: var(--font-head); font-weight: 700; font-size: clamp(11px, 1.6vmin, 14px); letter-spacing: 0.1em; text-transform: uppercase; }
.diff:hover { color: var(--ivory); box-shadow: inset 0 0 0 1px var(--gold); }
.diff.selected {
  background: linear-gradient(#f6e3a3, #d9b25f 55%, #a47a2c);
  color: #2a1a05;
  box-shadow: inset 0 1px 0 #fff6d8, 0 0 14px rgba(246, 227, 163, 0.55);
}
.diff.selected .stars { color: #7a1320; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4); }
.mode-stats { margin: 0; min-height: 1.2em; font-size: clamp(14px, 2vmin, 18px); font-style: italic; color: rgba(247, 238, 215, 0.8); text-shadow: 0 1px 3px #000; text-align: center; }

@keyframes cardIn { from { opacity: 0; transform: translateY(30px) scale(0.95); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------ modals */
.modal {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: clamp(16px, 3vh, 28px) clamp(10px, 2vw, 18px) clamp(12px, 2vh, 22px);
  background: radial-gradient(ellipse at center, rgba(6, 18, 13, 0.55), rgba(0, 0, 0, 0.78));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
}
.modal.open { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity 0.3s ease, visibility 0s; }
.modal.open .panel { animation: panelIn 0.45s cubic-bezier(.2, 1.35, .4, 1) both; }
.modal > .panel { margin: auto; flex-shrink: 0; }
@keyframes panelIn { from { opacity: 0; transform: translateY(-30px) scale(0.85); } to { opacity: 1; transform: none; } }

.panel {
  position: relative;
  width: min(440px, 92vw);
  max-height: min(94vh, calc(100vh - 24px));
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
  padding: clamp(16px, 2.8vmin, 26px) clamp(16px, 3vmin, 30px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: url('../assets/images/ui/leather.jpg') center / 256px;
  border: 32px solid transparent;
  border-image: url('../assets/images/ui/frame.png') 64 / 32px round;
  background-clip: padding-box;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8), inset 0 0 60px rgba(0, 0, 0, 0.55);
  scrollbar-width: none;
}
.panel::-webkit-scrollbar { display: none; }
.panel-small { width: min(400px, 92vw); }
.panel-wide { width: min(680px, 94vw); }
.panel-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(24px, 4.6vmin, 42px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
  background: linear-gradient(180deg, #fffbe6 10%, #f3d98f 45%, #c9953d 80%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 0 #2a1904) drop-shadow(0 4px 8px rgba(0, 0, 0, 0.8));
}
.panel-sub { margin: -4px 0 6px; font-size: clamp(15px, 2.2vmin, 19px); font-style: italic; color: rgba(247, 238, 215, 0.85); text-align: center; }
.stack { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 6px; }
.panel-actions { display: flex; gap: clamp(14px, 3vmin, 28px); justify-content: center; margin-top: 10px; }
.modal-close { position: absolute; top: 4px; right: 4px; }

/* promotion */
.promo-row { display: flex; gap: clamp(6px, 1.4vmin, 14px); justify-content: center; flex-wrap: wrap; }
.promo-btn {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: clamp(72px, 12vmin, 96px);
  padding: 8px 4px 10px;
  border-radius: 14px;
  background: radial-gradient(circle at 50% 30%, rgba(246, 227, 163, 0.18), rgba(0, 0, 0, 0.25));
  box-shadow: inset 0 0 0 2px rgba(217, 178, 95, 0.55), 0 6px 12px rgba(0, 0, 0, 0.5);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.promo-btn img { height: clamp(70px, 12vmin, 100px); filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.7)); }
.promo-btn span { font-family: var(--font-head); font-weight: 700; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold-light); }
.promo-btn kbd { position: absolute; top: 4px; right: 4px; font-size: 11px; }
.promo-btn:hover { transform: translateY(-4px); box-shadow: inset 0 0 0 2px var(--gold-light), 0 0 18px rgba(246, 227, 163, 0.45), 0 10px 16px rgba(0, 0, 0, 0.55); }

/* result */
.panel-result { width: min(460px, 92vw); }
.result-emblem { margin-top: -6px; }
.result-emblem img { width: clamp(52px, 9vmin, 80px); height: auto; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.7)); animation: crestFloat 3s ease-in-out infinite; }
.result-sub { margin-top: -8px; }
.result-times { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.rt-row {
  display: flex; align-items: center; gap: 12px;
  padding: 4px 14px;
  border-radius: 12px;
  background: rgba(3, 20, 14, 0.55);
  box-shadow: inset 0 0 0 1px rgba(217, 178, 95, 0.35);
}
.rt-row img { height: clamp(40px, 6.4vmin, 56px); margin: -6px 0; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.7)); }
.rt-name { flex: 1; font-family: var(--font-head); font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold-light); font-size: clamp(14px, 2.2vmin, 18px); }
.rt-time { font-family: var(--font-head); font-weight: 800; font-size: clamp(20px, 3.4vmin, 28px); color: var(--ivory); font-variant-numeric: tabular-nums; }
.rt-row.winner { box-shadow: inset 0 0 0 2px var(--gold), 0 0 16px rgba(246, 227, 163, 0.35); }
.result-score { font-family: var(--font-head); font-weight: 800; font-size: clamp(18px, 3vmin, 24px); color: var(--gold-light); text-align: center; min-height: 1em; }
.result-score small { display: block; font-family: var(--font-body); font-weight: 600; font-style: italic; font-size: 0.72em; color: rgba(247, 238, 215, 0.8); }
.result-score .new-best { color: #7ff0b8; font-style: normal; font-family: var(--font-head); letter-spacing: 0.1em; }

/* settings */
.settings-list { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.setting {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(3, 20, 14, 0.55);
  box-shadow: inset 0 0 0 1px rgba(217, 178, 95, 0.35);
  cursor: pointer;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: clamp(14px, 2.2vmin, 18px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-light);
}
.setting > img { width: 28px; height: 28px; }
.setting > span:first-of-type { flex: 1; }
.setting { position: relative; }
.setting input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.switch {
  position: relative;
  width: 58px; height: 30px;
  border-radius: 16px;
  background: linear-gradient(#3b0d14, #5c1621);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.7), 0 0 0 2px var(--gold-dark);
  transition: background 0.2s ease;
  flex: none;
}
.switch::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6d8, #d9b25f 55%, #8a6420);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
  transition: transform 0.2s cubic-bezier(.3, 1.4, .5, 1);
}
.setting input:checked + .switch { background: linear-gradient(#1c7a55, #0f5a3e); }
.setting input:checked + .switch::after { transform: translateX(28px); }
.setting:hover { box-shadow: inset 0 0 0 1px var(--gold); }

/* help */
.help-body { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 22px; font-size: clamp(15px, 2.1vmin, 18px); line-height: 1.35; }
.help-body section { min-width: 0; }
.help-body h3 { margin: 6px 0 2px; font-family: var(--font-head); font-weight: 800; font-size: 1em; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); }
.help-body p { margin: 0 0 6px; color: rgba(247, 238, 215, 0.92); }
.help-body b { color: var(--gold-light); }
.keys { border-collapse: collapse; width: 100%; font-size: 0.92em; }
.keys td { padding: 2px 4px; vertical-align: middle; }
.keys td:first-child { white-space: nowrap; }

/* credits */
.credits-crest { height: 110px; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.8)); }
.credits-text { margin: 0; text-align: center; font-size: 17px; line-height: 1.35; color: rgba(247, 238, 215, 0.9); }
.credits-version { margin: 4px 0 0; font-family: var(--font-head); font-size: 12px; letter-spacing: 0.2em; color: var(--gold); text-transform: uppercase; }

@media (max-width: 640px) {
  .help-body { grid-template-columns: 1fr; }
}
@media (max-height: 520px) {
  .mode-art { height: 70px; }
  .mode-desc { display: none; }
}

/* promotion panel fits all four pieces on one row */
#modal-promo .panel { width: min(580px, 96vw); }

/* help: the text scrolls inside the frame, title + button stay put */
#modal-help .panel { overflow: hidden; }
#modal-help .help-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dark) transparent;
}
#modal-help .stack { flex: none; }

/* narrow portrait */
@media (max-width: 640px) and (orientation: portrait) {
  .mode-cards { flex-direction: column; align-items: center; gap: 12px; }
  .mode-card { width: min(86vw, 340px); padding-top: 8px; padding-bottom: 10px; }
  .mode-art { height: 84px; }
  .screen-title { font-size: 24px; }
  .screen-title .orn { display: none; }
  #screen-mode { gap: 12px; }
}
@media (pointer: coarse) {
  .title-hint, .mode-key, .promo-btn kbd { display: none; }
}

/* live 3D crest (king.glb rendered with WebGL) */
.logo-crest-3d { aspect-ratio: 0.52; width: auto; display: block; }
