/*
 * App chrome for the mobile edition: app frame + portrait rotation, boot card, thumb rails for the
 * original-canvas fallback, touch feedback (ripple, hold ring, loupe), description card, toasts and
 * bottom sheets. Uses the tokens from theme.css.
 */

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% -10%, rgba(207, 174, 118, 0.05), transparent 60%),
    var(--bg-0);
}

/* Portrait phones: the whole app is turned 90° clockwise so the game runs landscape even with
 * the orientation lock on. view.js sets --vw/--vh to the viewport size. */
html.rotated #app {
  inset: auto;
  top: 0;
  left: 0;
  width: var(--vh);
  height: var(--vw);
  transform-origin: 0 0;
  transform: translateX(var(--vw)) rotate(90deg);
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
}

#screens {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

#screens > .scr {
  position: absolute;
  inset: 0;
  pointer-events: auto;
}

/* ---------------------------------------------------------------- boot */

.boot-screen {
  container-type: size;
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(45% 60% at 50% 45%, rgba(217, 47, 60, 0.14), transparent 70%),
    radial-gradient(80% 80% at 50% 120%, rgba(207, 174, 118, 0.08), transparent 70%),
    linear-gradient(180deg, #0b0c10, #07080b);
  transition: opacity 0.4s var(--ease);
}

.boot-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Two hairlines framing the card, like a title plate. */
.boot-screen::before,
.boot-screen::after {
  content: '';
  position: absolute;
  left: 8%;
  right: 8%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--acc-line), transparent);
}

.boot-screen::before { top: 12%; }
.boot-screen::after { bottom: 12%; }

.boot-card {
  position: relative;
  width: min(380px, 84%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: bootIn 0.6s var(--ease);
}

@keyframes bootIn {
  from { opacity: 0; transform: translateY(8px); }
}

.boot-logo {
  width: clamp(64px, 22cqh, 104px);
  height: clamp(64px, 22cqh, 104px);
  color: var(--acc);
  margin-bottom: 14px;
}

.boot-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.boot-title .w1 {
  font: 500 13px/1 var(--font-d);
  letter-spacing: 0.56em;
  margin-right: -0.56em;
  color: var(--tx-2);
}

.boot-title .w2 {
  margin-top: 6px;
  font: 700 clamp(34px, 12cqh, 52px)/0.95 var(--font-d);
  letter-spacing: 0.06em;
  color: var(--tx-1);
}

.boot-title em {
  margin-left: 0.16em;
  font-style: normal;
  color: var(--brand);
}

.boot-sub {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 22px;
  font-size: 11px;
  font-weight: 650;
  color: var(--acc);
  text-transform: uppercase;
  letter-spacing: 0.3em;
}

.boot-sub::before,
.boot-sub::after {
  content: '';
  width: 5px;
  height: 5px;
  transform: rotate(45deg);
  background: var(--acc);
  opacity: 0.7;
}

.boot-bar {
  width: 100%;
  height: 2px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-bottom: 10px;
}

#boot-progress {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--acc), var(--acc-2));
  box-shadow: 0 0 8px rgba(234, 209, 162, 0.6);
  transition: width 0.2s;
}

#boot-msg {
  font: 500 12px/1.3 var(--font-d);
  letter-spacing: 0.12em;
  color: var(--tx-3);
}

#boot-msg.error {
  color: var(--bad);
  font-family: var(--font);
  letter-spacing: 0;
}

.boot-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.boot-actions .play {
  position: relative;
  width: min(280px, 100%);
  min-height: 54px;
  border: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 52%),
    linear-gradient(90deg, #c4202f, var(--brand) 45%, #e3434d);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.04em;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  overflow: hidden;
  transition: transform 0.12s var(--ease);
}

.boot-actions .play::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -40%;
  width: 30%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.24), transparent);
  transform: skewX(-18deg);
  animation: sweep 4.5s ease-in-out infinite;
}

.boot-actions .play:active {
  transform: scale(0.97);
}

.boot-actions .play-window {
  min-height: 44px;
  padding: 0 16px;
  border: none;
  background: none;
  color: var(--tx-2);
  font-weight: 600;
}

.boot-tip {
  margin: 0;
  font-size: 12px;
  color: var(--tx-3);
}

@keyframes sweep {
  0%, 62% { left: -40%; }
  100% { left: 120%; }
}

/* ---------------------------------------------------------------- rails (original-canvas fallback) */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.rail {
  position: absolute;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding: 10px 0;
}

.rail.h {
  flex-direction: row;
  padding: 0 10px;
}

.rail.overlay .ibtn,
.rail.overlay .seg {
  opacity: 0.78;
}

.grp {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.rail.h .grp {
  flex-direction: row;
}

.items {
  display: grid;
  grid-template-columns: 50px;
  gap: 8px;
}

.items.two {
  grid-template-columns: 50px 50px;
}

.rail.h .items {
  grid-auto-flow: column;
  grid-template-columns: none;
}

/* Item slot: conic cooldown ring + uses badge. */
.slot {
  position: relative;
  width: 50px;
  height: 50px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--bg-2) 60%, transparent 61%),
    conic-gradient(var(--acc) calc(var(--cd, 1) * 360deg), rgba(255, 255, 255, 0.1) 0);
  color: var(--tx-1);
  display: flex;
  align-items: center;
  justify-content: center;
  font: 600 18px/1 var(--font-d);
  transition: transform 0.12s var(--ease), opacity 0.15s;
}

.slot:active,
.slot.pressed {
  transform: scale(0.9);
}

.slot.off {
  opacity: 0.4;
}

.slot .uses {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  box-sizing: border-box;
  border-radius: 2px;
  background: var(--tx-1);
  color: var(--tx-inv);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
}

.slot.auto::after {
  content: 'A';
  position: absolute;
  bottom: -2px;
  left: -2px;
  width: 16px;
  height: 16px;
  border-radius: 2px;
  background: var(--acc);
  color: var(--acc-ink);
  font-size: 10px;
  line-height: 16px;
}

.seg-cap {
  font: 600 10px/1 var(--font-d);
  color: var(--tx-3);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* ---------------------------------------------------------------- touch feedback */

.ripple {
  position: absolute;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(234, 209, 162, 0.3), rgba(234, 209, 162, 0) 70%);
  border: 1px solid rgba(234, 209, 162, 0.75);
  pointer-events: none;
  animation: ripple 0.42s var(--ease) forwards;
}

@keyframes ripple {
  from { transform: scale(0.3); opacity: 1; }
  to { transform: scale(1.35); opacity: 0; }
}

.hold-ring {
  position: absolute;
  width: 66px;
  height: 66px;
  margin: -33px 0 0 -33px;
  border-radius: 50%;
  pointer-events: none;
  background: conic-gradient(var(--acc-2) calc(var(--p, 0) * 360deg), rgba(255, 255, 255, 0.12) 0);
  -webkit-mask: radial-gradient(circle, transparent 29px, #000 30px);
  mask: radial-gradient(circle, transparent 29px, #000 30px);
}

.loupe {
  position: absolute;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  border: 1px solid var(--acc-2);
  box-shadow: 0 0 0 4px rgba(7, 8, 11, 0.55), var(--shadow-2);
  background: var(--bg-0);
  pointer-events: none;
}

.infocard {
  position: absolute;
  left: 50%;
  max-width: min(520px, 72%);
  transform: translateX(-50%);
  box-sizing: border-box;
  padding: 12px 16px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line-2);
  border-top: 1px solid var(--acc-line);
  color: var(--tx-1);
  font-size: 15px;
  line-height: 1.4;
  box-shadow: var(--shadow-2);
  pointer-events: none;
  z-index: 30;
}

.infocard b {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  color: var(--acc);
  font: 600 10.5px/1.2 var(--font-d);
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(16px + var(--sab));
  transform: translate(-50%, 16px);
  max-width: 80%;
  padding: 11px 18px 11px 16px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line-2);
  border-left: 2px solid var(--acc);
  color: var(--tx-1);
  font-weight: 650;
  box-shadow: var(--shadow-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  z-index: 70;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.bad {
  border-left-color: var(--bad);
  color: #fbd3d4;
}

/* ---------------------------------------------------------------- bottom sheets */

.sheet-back {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(4, 5, 7, 0.66);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.18s ease-out;
}

.sheet {
  position: relative;
  width: min(640px, 100%);
  max-height: calc(100% - 10px - var(--sat));
  overflow-y: auto;
  overscroll-behavior: contain;
  box-sizing: border-box;
  padding: 6px 20px calc(18px + var(--sab));
  margin: 0 var(--sar) 0 var(--sal);
  background:
    linear-gradient(180deg, rgba(207, 174, 118, 0.06), transparent 120px),
    var(--bg-1);
  border: 1px solid var(--line-2);
  border-top-color: var(--acc-line);
  border-bottom: none;
  box-shadow: 0 -18px 60px rgba(0, 0, 0, 0.65);
  clip-path: polygon(14px 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%, 0 14px);
  animation: slideUp 0.26s var(--ease);
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}

.sheet .grab {
  width: 36px;
  height: 2px;
  margin: 8px auto 14px;
  background: var(--acc);
  opacity: 0.7;
}

@keyframes slideUp {
  from { transform: translateY(30%); opacity: 0; }
}

@keyframes fadeIn {
  from { opacity: 0; }
}

.sheet h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.005em;
}

.sheet h2 > span:first-child {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sheet h2 > span:first-child::before {
  content: '';
  flex: none;
  width: 7px;
  height: 7px;
  transform: rotate(45deg);
  background: var(--acc);
}

.sheet h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 22px 0 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--acc);
}

.sheet h3::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line-2), transparent);
}

.sheet p {
  margin: 6px 0;
}

.sheet .small {
  font-size: 13px;
  color: var(--tx-2);
}

.sheet .warn {
  color: var(--warn);
  font-size: 13px;
}

.sheet .btn.block {
  margin-top: 18px;
}

.row.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.gestures {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 8px;
  margin: 8px 0;
}

.gesture {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-left: 2px solid var(--acc-line);
}

.gesture .gi {
  flex: none;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--acc-2);
}

.gesture .gi .ic {
  width: 24px;
  height: 24px;
}

.gesture b {
  display: block;
  font-size: 14px;
  font-weight: 700;
}

.gesture span {
  font-size: 13px;
  color: var(--tx-2);
}

.aboutbox {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 13px;
}

.aboutbox a {
  color: var(--acc-2);
  font-weight: 650;
}

.egg-btn {
  width: 44px;
  height: 44px;
  padding: 9px;
  border: 1px dashed var(--acc-line);
  border-radius: 50%;
  background: transparent;
  color: var(--acc);
  cursor: pointer;
}

.egg {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.egg-icon {
  width: 76px;
  height: 76px;
  color: var(--acc);
  animation: spin 12s linear infinite;
}

.egg-icon .ic {
  width: 100%;
  height: 100%;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.confirm h2 {
  margin-top: 4px;
}

.row.buttons.end {
  justify-content: flex-end;
  margin-top: 16px;
}

.btn.primary.danger-fill {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0) 52%),
    linear-gradient(90deg, #a8121f, #d0202f);
}

.gesture .gi svg {
  width: 30px;
  height: 30px;
}

.row.buttons.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 18px;
}

/* ---------------------------------------------------------------- guide */

.guide .gd-tabs {
  margin: 4px 0 12px;
  border-bottom: 1px solid var(--line);
}

.gd-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gd-item {
  --c: var(--acc);
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-left: 2px solid color-mix(in srgb, var(--c) 70%, transparent);
}

.gd-ic {
  flex: none;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
  border-radius: 2px;
}

.gd-body {
  min-width: 0;
  flex: 1;
}

.gd-body b {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--c);
}

.gd-f {
  display: block;
  margin: 6px 0 4px;
  padding: 7px 10px;
  background: var(--bg-0);
  border: 1px solid var(--line);
  border-left: 2px solid var(--acc-line);
  color: var(--tx-1);
  font: 600 12.5px/1.45 ui-monospace, "SF Mono", Menlo, Consolas, "PingFang SC", "Microsoft YaHei", monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.gd-body p {
  margin: 4px 0 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--tx-2);
  white-space: pre-line;
}

.gd-note {
  margin: 12px 2px 0;
  font-size: 12px;
  color: var(--tx-3);
}
