* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #e7ebf0;
  color: #1c2430;
  font-family: Manrope, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button { font: inherit; }

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
}

.app {
  position: relative;
  width: min(1080px, 100%);
  height: min(760px, calc(100dvh - 56px));
  display: flex;
  flex-direction: column;
  padding: 16px 16px 12px;
  gap: 10px;
  background: #f7f8fa;
  border: 1px solid #d9e0e8;
  border-radius: 22px;
  box-shadow: 0 18px 50px rgba(28, 39, 58, 0.12);
}

.top {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-height: 36px;
}
.brand {
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: 13px;
  text-transform: uppercase;
  color: #2f6fed;
  background: #fff;
  border: 1px solid #e3e8ef;
  border-radius: 999px;
  padding: 6px 12px;
  box-shadow: 0 1px 2px rgba(20, 30, 50, 0.04);
}
.top h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.sub {
  margin: 0;
  color: #66758a;
  font-size: 13px;
  font-weight: 600;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 12px;
}

.rail, .stage-wrap {
  background: #f7f8fa;
  border: 1px solid #e4e8ee;
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(28, 39, 58, 0.05);
  min-height: 0;
}

.rail {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #5d6b80;
}
.rail-head strong {
  color: #1c2430;
  font-variant-numeric: tabular-nums;
}
.rail-view {
  position: relative;
  flex: 1;
  min-height: 0;
}
#railCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.list {
  position: absolute;
  inset: 0;
  overflow-y: scroll;
  overflow-x: hidden;
  padding: 4px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #b7c3d3 transparent;
}
.list::-webkit-scrollbar { width: 10px; }
.list::-webkit-scrollbar-thumb {
  background: #b7c3d3;
  border-radius: 99px;
  border: 2px solid #f7f8fa;
}
.list::-webkit-scrollbar-track { background: transparent; }

.card {
  position: relative;
  flex: 0 0 196px;
  height: 196px;
  border: 1px solid #e1e6ee;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  cursor: grab;
  text-align: left;
  padding: 8px 10px;
  color: #314056;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}
.card:active { cursor: grabbing; }
.card.active {
  border-color: #ff6fae;
  box-shadow: 0 0 0 3px rgba(255, 111, 174, 0.18);
  background: rgba(255, 245, 250, 0.72);
}
.card.placed {
  cursor: default;
  opacity: 0.55;
}
.card.shake { animation: shake 0.35s linear; }
.card .tag {
  position: relative;
  z-index: 1;
  display: inline-flex;
  min-width: 28px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: #fff;
  border: 1px solid #e5eaf1;
  font-size: 11px;
  font-weight: 800;
}
.card .check {
  position: absolute;
  right: 10px;
  top: 8px;
  z-index: 1;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #22a06b;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  display: none;
  align-items: center;
  justify-content: center;
}
.card.placed .check { display: flex; }

@keyframes shake {
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

.stage-wrap {
  position: relative;
  background: #f3f6fa;
  overflow: hidden;
}
#stage { position: absolute; inset: 0; }
#stage canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hud {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #e5eaf1;
  box-shadow: 0 6px 16px rgba(28, 39, 58, 0.06);
  z-index: 2;
  pointer-events: none;
}
#status { font-size: 13px; font-weight: 800; min-width: 52px; }
.bar {
  width: 120px;
  height: 8px;
  border-radius: 99px;
  background: #e7edf4;
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #2f6fed, #7aa6ff);
  transition: width 0.35s ease;
}

#toast {
  position: absolute;
  left: 50%;
  top: 58px;
  transform: translate(-50%, -8px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #fff;
  color: #146c43;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 10px 24px rgba(28, 39, 58, 0.1);
  transition: 0.35s ease;
  z-index: 3;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.tools {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.tool {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid #e6ebf2;
  background: #fff;
  color: #5c6b80;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(28, 39, 58, 0.06);
}
.tool svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { color: #2f6fed; border-color: #d5e3ff; }
.tool[data-act="fit"] { color: #2f6fed; }

.vcube {
  width: 92px;
  height: 92px;
  margin-bottom: 4px;
  perspective: 420px;
  cursor: grab;
}
.vcube:active { cursor: grabbing; }
.cube {
  width: 54px;
  height: 54px;
  margin: 19px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.08s linear;
}
.face {
  position: absolute;
  inset: 0;
  border: 0;
  background: #fff;
  color: #8b97a8;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: inset 0 0 0 1px #dfe5ee;
  cursor: pointer;
}
.face:hover { color: #2f6fed; background: #f5f8ff; }
.front  { transform: translateZ(27px); }
.back   { transform: rotateY(180deg) translateZ(27px); }
.right  { transform: rotateY(90deg) translateZ(27px); }
.left   { transform: rotateY(-90deg) translateZ(27px); }
.top    { transform: rotateX(90deg) translateZ(27px); }
.bottom { transform: rotateX(-90deg) translateZ(27px); }

.tool[data-act="spin"].on {
  color: #fff;
  background: #2f6fed;
  border-color: #2f6fed;
}
.tool[data-act="spin"].attention {
  animation: spinNotice 1.1s ease-in-out infinite;
}
@keyframes spinNotice {
  0%, 100% { transform: scale(1); box-shadow: 0 4px 12px rgba(28, 39, 58, 0.06); }
  50% { transform: scale(1.12); box-shadow: 0 0 0 6px rgba(47, 111, 237, 0.2); }
}

.card.rise {
  animation: riseIn 0.38s ease;
}
@keyframes riseIn {
  from { transform: translateY(18px); }
  to { transform: translateY(0); }
}

.assistant {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.assistant-panel[hidden] { display: none; }
.assistant-fab {
  border: 0;
  border-radius: 999px;
  background: #2f6fed;
  color: #fff;
  font-weight: 800;
  padding: 12px 16px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(47, 111, 237, 0.28);
}
.assistant-panel {
  width: min(320px, calc(100vw - 36px));
  height: 360px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid #e4e8ee;
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(28, 39, 58, 0.16);
  overflow: hidden;
}
.assistant-panel header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 12px 12px 10px;
  border-bottom: 1px solid #eef2f6;
}
.assistant-panel header span { color: #7b8798; font-size: 12px; font-weight: 700; }
.assistant-panel header button {
  margin-left: auto;
  border: 0;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: #66758a;
}
.assistant-log {
  flex: 1;
  overflow: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bubble {
  max-width: 92%;
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.4;
}
.bubble.bot { background: #f3f6fa; color: #1c2430; }
.bubble.user { align-self: flex-end; background: #2f6fed; color: #fff; }
.assistant-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 12px;
}
.assistant-choices button {
  border: 1px solid #d7e3f8;
  background: #f5f8ff;
  color: #2457c5;
  border-radius: 999px;
  padding: 7px 10px;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
}
