* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1c2a45;
  font-family: "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

canvas { display: block; touch-action: none; position: fixed; inset: 0; width: 100%; height: 100%; }

.hidden { display: none !important; }
.grow { flex: 1; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  touch-action: manipulation;
}

.pill {
  padding: 8px 13px;
  border-radius: 999px;
  background: rgba(10, 18, 38, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.22);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}
.pill:hover { background: rgba(30, 45, 80, 0.9); }
.pill:disabled { opacity: 0.35; cursor: default; }

/* ================= workshop ================= */

#build { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#build > * { pointer-events: auto; }

#top {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
#top > * { pointer-events: auto; }

.name {
  padding: 8px 16px;
  border-radius: 14px;
  background: rgba(10, 18, 38, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.22);
  font-weight: 800;
  font-size: 19px;
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fly {
  padding: 10px 22px;
  border-radius: 999px;
  background: linear-gradient(#ffd84a, #ff9f1c);
  color: #3a1d00;
  font-weight: 900;
  font-size: 19px;
  letter-spacing: 1px;
  box-shadow: 0 4px 0 #b86a00, 0 6px 16px rgba(0, 0, 0, 0.35);
}
.fly:active { transform: translateY(2px); box-shadow: 0 2px 0 #b86a00; }

#parts {
  position: absolute;
  top: calc(max(10px, env(safe-area-inset-top)) + 54px);
  left: max(10px, env(safe-area-inset-left));
  bottom: 54px;
  width: 92px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  border-radius: 16px;
  background: rgba(10, 18, 38, 0.6);
  scrollbar-width: none;
}
#parts::-webkit-scrollbar { display: none; }
#parts .head { font-size: 11px; letter-spacing: 2px; font-weight: 800; text-align: center; opacity: 0.7; padding: 2px 0; }

.partBtn {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 4px 2px 5px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 12px;
  font-weight: 700;
  touch-action: none;
}
.partBtn:hover { background: rgba(255, 255, 255, 0.18); }
.partBtn img { width: 60px; height: 46px; object-fit: contain; pointer-events: none; }

#panel {
  position: absolute;
  top: calc(max(10px, env(safe-area-inset-top)) + 54px);
  right: max(10px, env(safe-area-inset-right));
  bottom: 120px;
  width: 290px;
  overflow-y: auto;
  padding: 12px 14px 16px;
  border-radius: 16px;
  background: rgba(10, 18, 38, 0.8);
  backdrop-filter: blur(6px);
  font-size: 14px;
}
#panel h3 { margin: 0 0 6px; font-size: 20px; display: flex; align-items: center; gap: 8px; }
#panel h4 { margin: 14px 0 6px; font-size: 11px; letter-spacing: 2px; opacity: 0.65; }
#panel .row { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
#panel .row label { flex: 0 0 92px; font-size: 13px; line-height: 1.1; }
#panel .row .val { flex: 0 0 64px; text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; opacity: 0.9; }
#panel input[type="range"] { flex: 1; min-width: 0; accent-color: #ffc93a; height: 26px; }
#panel .btns { display: flex; flex-wrap: wrap; gap: 6px; }
#panel .btn {
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  font-weight: 700;
  font-size: 13px;
}
#panel .btn:hover { background: rgba(255, 255, 255, 0.22); }
#panel .btn.on { background: #ffc93a; color: #3a1d00; }
#panel .btn.red { background: rgba(230, 60, 60, 0.35); }
#panel .grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
#panel .grid3 .btn { padding: 8px 4px; }
#panel .grid3 .lab { font-size: 12px; text-align: center; align-self: center; opacity: 0.8; }
#panel .note { font-size: 13px; line-height: 1.45; opacity: 0.85; margin: 6px 0; }
#panel input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  font: inherit;
  font-size: 16px;
}

.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.swatch {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  padding: 0;
}
.swatch.on { border-color: #fff; box-shadow: 0 0 0 2px #ffc93a; }
.swatch.pick {
  position: relative;
  overflow: hidden;
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
}
.swatch.pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

#check {
  position: absolute;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  width: 290px;
  height: 100px;
  padding: 8px 12px;
  border-radius: 16px;
  background: rgba(10, 18, 38, 0.8);
  font-size: 12.5px;
}
#check .verdict { font-weight: 800; font-size: 14px; line-height: 1.25; margin-bottom: 5px; }
#check .nums { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; opacity: 0.85; }
#check .nums b { font-variant-numeric: tabular-nums; }

#tip {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(460px, calc(100vw - 440px));
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(10, 18, 38, 0.6);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.4s;
}

/* ================= flying ================= */

#fly { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

#flyTop {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 8px;
}
#flyTop button { pointer-events: auto; }
#flyTop .box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 82px;
  padding: 4px 12px 5px;
  border-radius: 12px;
  background: rgba(10, 18, 38, 0.72);
  line-height: 1.1;
}
#flyTop .box .lab { font-size: 10px; letter-spacing: 2px; opacity: 0.7; font-weight: 800; }
#flyTop .box b { font-size: 24px; font-variant-numeric: tabular-nums; }
#flyTop .box small { font-size: 10px; opacity: 0.7; }
#flyTop .box.gold b { color: #ffd84a; }

#msg {
  position: absolute;
  top: 26%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 40px;
  font-weight: 900;
  text-align: center;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 0 22px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.3s;
  white-space: nowrap;
}
#msg.show { opacity: 1; }
#msg small { display: block; font-size: 19px; font-weight: 700; margin-top: 4px; }

#flyHint {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 340px));
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(10, 18, 38, 0.6);
  font-size: 14px;
  text-align: center;
  transition: opacity 0.5s;
}
#flyHint:empty { display: none; }

#arrow {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #ffd84a;
  font-weight: 800;
  font-size: 13px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  transform: translate(-50%, -50%);
}
#arrow i { font-style: normal; font-size: 30px; display: block; line-height: 1; }

.zone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 44vw;
  height: 62vh;
  pointer-events: auto;
  touch-action: none;
}
.zone .base {
  position: absolute;
  left: 110px;
  bottom: 110px;
  width: 150px;
  height: 150px;
  margin: -75px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.35);
}
.zone .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 62px;
  height: 62px;
  margin: -31px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
}
.zone .cap, #thr .cap {
  position: absolute;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 2px;
  opacity: 0.6;
}
.zone .cap { left: 80px; bottom: 16px; }

#thr {
  position: absolute;
  right: max(24px, env(safe-area-inset-right));
  bottom: 60px;
  width: 74px;
  height: 46vh;
  pointer-events: auto;
  touch-action: none;
}
#thr .track {
  position: absolute;
  inset: 0 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.35);
  overflow: hidden;
}
#thr .fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: linear-gradient(#ffd84a, #ff7a1c); opacity: 0.8; }
#thr .handle { position: absolute; left: -2px; right: -2px; height: 8px; margin-top: -4px; background: #fff; border-radius: 4px; }
#thr .cap { left: 0; right: 0; text-align: center; bottom: -22px; }

/* ================= cards ================= */

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 10, 25, 0.6);
  backdrop-filter: blur(5px);
}
.modal .box {
  width: min(860px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 20px 24px 24px;
  border-radius: 22px;
  background: #18264a;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal h2 { margin: 0 0 4px; font-size: 30px; }
.modal h4 { margin: 20px 0 8px; font-size: 12px; letter-spacing: 2px; opacity: 0.7; }
.modal p { margin: 4px 0; opacity: 0.85; line-height: 1.5; }
.modal .head { display: flex; align-items: center; gap: 10px; }
.modal .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.modal .pcard {
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.07);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}
.modal .pcard.cur { outline: 3px solid #ffc93a; }
.modal .pcard .thumb {
  aspect-ratio: 16 / 10;
  border-radius: 10px;
  background: #2a3a5e center / cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
}
.modal .pcard .nm { font-weight: 800; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal .pcard .row { display: flex; gap: 6px; }
.modal .pcard .row button { flex: 1; padding: 7px 4px; border-radius: 10px; background: rgba(255, 255, 255, 0.12); font-weight: 700; font-size: 13px; }
.modal .pcard .row button.go { background: #ffc93a; color: #3a1d00; }
.modal .tpl { cursor: pointer; }
.modal .tpl:hover { background: rgba(255, 255, 255, 0.15); }
.modal .tpl .desc { font-size: 12.5px; opacity: 0.75; line-height: 1.35; }
.modal .big { padding: 12px 24px; border-radius: 999px; font-weight: 900; font-size: 18px; background: #ffc93a; color: #3a1d00; }
.modal .big.alt { background: rgba(255, 255, 255, 0.14); color: #fff; }
.modal .actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.modal.center .box { width: min(520px, 100%); text-align: center; }

@media (max-width: 760px) {
  #panel, #check { width: 230px; }
  #tip { display: none; }
  .name { font-size: 15px; }
  .pill { padding: 7px 9px; font-size: 12px; }
}
