/* 3D Builder page. Mobile first: the view on top, the palette and details below; three columns on wide screens. */
/* 163px = the two-row top bar (111px: tabs + sub-tabs) + page padding + breathing room, as the old 110px was for one row. */
.page-builder { max-width: 1800px; display: grid; gap: 16px; }
.builder { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start; }
.viewport-wrap { order: -1; min-width: 0; }
@media (min-width: 1200px) {
  .builder { grid-template-columns: 250px minmax(0, 1fr) 300px; }
  .viewport-wrap { order: 0; }
  .palette, .info { max-height: clamp(480px, calc(100dvh - 163px), 920px); overflow-y: auto; overscroll-behavior: contain; }
}

/* ---------- the 3D view ---------- */
.viewport {
  position: relative; overflow: hidden; border: 1px solid var(--line-strong); border-radius: var(--radius);
  height: clamp(420px, calc(100dvh - 163px), 920px); background: #9aa9b3; box-shadow: var(--shadow);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.viewport canvas { display: block; width: 100%; height: 100%; outline: none; cursor: crosshair; }
.viewport canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.viewport.locked canvas { cursor: none; }
.crosshair { position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; pointer-events: none; display: none; }
.crosshair::before, .crosshair::after { content: ""; position: absolute; background: rgba(255, 255, 255, .92); box-shadow: 0 0 2px rgba(0, 0, 0, .8); }
.crosshair::before { left: 8px; top: 0; width: 2px; height: 18px; }
.crosshair::after { top: 8px; left: 0; height: 2px; width: 18px; }
.viewport.locked .crosshair { display: block; }

.hud-top { position: absolute; left: 10px; top: 10px; right: 10px; display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none; }
.hud-chip {
  padding: .3rem .6rem; border-radius: var(--radius); background: var(--tip-bg); color: var(--tip-text);
  border: 1px solid var(--tip-line); font: 700 .8rem/1.2 var(--head-font); font-stretch: 87.5%; letter-spacing: .04em; text-transform: uppercase;
}
.hud-target { color: #f5c78a; }
.hud-msg {
  position: absolute; left: 50%; top: 56px; transform: translateX(-50%); max-width: calc(100% - 24px);
  padding: .4rem .75rem; border-radius: var(--radius); background: rgba(18, 17, 15, .88); color: #eee8dc;
  font-size: .9rem; text-align: center; pointer-events: none; opacity: 0; transition: opacity .2s;
}
.hud-msg.on { opacity: 1; }

.fly-cta {
  position: absolute; right: 10px; top: 48px; display: grid; gap: .45rem; justify-items: start; max-width: 290px;
  padding: .7rem .8rem; border-radius: var(--radius); background: var(--tip-bg); border: 1px solid var(--tip-line); color: var(--tip-text);
  font-size: .82rem; box-shadow: var(--shadow);
}
.fly-cta p { margin: 0; line-height: 1.7; }
.fly-cta .kbd { color: var(--tip-text); background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .25); }
.viewport.locked .fly-cta { display: none; }
.fly-cta.touch .btn { display: none; }
.linklike { appearance: none; border: 0; padding: 0; background: none; color: #f4a07e; text-decoration: underline; cursor: pointer; font: inherit; }

.hotbar {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; gap: 4px; max-width: calc(100% - 20px);
  padding: 4px; border-radius: var(--radius); background: rgba(14, 13, 12, .72); overflow-x: auto; scrollbar-width: none;
}
.hotbar::-webkit-scrollbar { display: none; }
.hot {
  position: relative; flex: none; display: grid; place-items: center; width: 46px; height: 46px; padding: 0;
  border: 1px solid rgba(255, 255, 255, .14); border-radius: 3px; background: rgba(255, 255, 255, .06); color: #e3dccf; cursor: pointer;
}
.hot svg { width: 26px; height: 26px; }
.hot:hover { background: rgba(255, 255, 255, .14); }
.hot.on { border-color: #e8653d; background: rgba(205, 65, 43, .35); box-shadow: inset 0 -3px 0 #cd412b; }
.hot-key { position: absolute; left: 3px; top: 1px; font: 700 .62rem/1 var(--mono); color: rgba(255, 255, 255, .6); }

.touch-pad {
  position: absolute; left: 10px; bottom: 66px; display: grid; grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 40px); gap: 4px;
}
.touch-pad[hidden] { display: none; }
.touch-pad button {
  border: 1px solid rgba(255, 255, 255, .2); border-radius: 4px; background: rgba(14, 13, 12, .6); color: #eee;
  font: 700 .8rem/1 var(--head-font); touch-action: none;
}
.touch-pad [data-key="KeyW"] { grid-column: 2; grid-row: 1; }
.touch-pad [data-key="KeyA"] { grid-column: 1; grid-row: 2; }
.touch-pad [data-key="KeyS"] { grid-column: 2; grid-row: 3; }
.touch-pad [data-key="KeyD"] { grid-column: 3; grid-row: 2; }
.touch-pad [data-key="Space"] { grid-column: 3; grid-row: 1; }
.touch-pad [data-key="ControlLeft"] { grid-column: 3; grid-row: 3; }
.no-webgl { margin: 2rem; }

/* ---------- palette ---------- */
.palette { display: grid; gap: .75rem; align-content: start; }
.palette .label { font-family: var(--head-font); font-stretch: 87.5%; font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.grade-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px; }
.grade-btn {
  display: grid; justify-items: center; gap: 3px; padding: .35rem .1rem; min-height: 50px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--btn); color: var(--muted); cursor: pointer; font: 700 .66rem/1.1 var(--head-font); font-stretch: 87.5%; text-transform: uppercase; letter-spacing: .03em;
}
.grade-btn:hover { background: var(--btn-hover); color: var(--text); }
.grade-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--text); box-shadow: inset 0 -3px 0 var(--accent); }
.swatch { width: 22px; height: 16px; border-radius: 2px; border: 1px solid rgba(0, 0, 0, .35); }
.g-twig .swatch { background: repeating-linear-gradient(45deg, #b8955e 0 3px, #6e5231 3px 5px); }
.g-wood .swatch { background: repeating-linear-gradient(90deg, #8a5a33 0 5px, #3a2412 5px 6px); }
.g-stone .swatch { background: linear-gradient(#9d998f 0 45%, #6d6961 45% 55%, #908b82 55%); }
.g-metal .swatch { background: repeating-linear-gradient(90deg, #5f5a53 0 3px, #9a938a 3px 6px); }
.g-hqm .swatch { background: #3e454c; box-shadow: inset 0 0 0 2px #59616a; }
.hammer-btn { justify-content: flex-start; }
.hammer-btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.palette-groups { display: grid; gap: .6rem; }
.pal-title { margin: 0 0 .3rem; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.pal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 3px; }
.pal-btn {
  display: flex; align-items: center; gap: .4rem; min-height: 34px; padding: .25rem .4rem; border: 1px solid transparent; border-radius: var(--radius);
  background: var(--panel-2); color: var(--text); cursor: pointer; text-align: left; font-size: .76rem; line-height: 1.15;
}
.pal-btn svg { width: 20px; height: 20px; flex: none; color: var(--muted); }
.pal-btn:hover { background: var(--btn-hover); }
.pal-btn.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, transparent); }
.pal-btn.on svg { color: var(--accent-2); }

/* ---------- details panel ---------- */
.info { display: grid; gap: .8rem; align-content: start; }
.tools-row { gap: .35rem; }
.tools-row [aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.info-sec { display: grid; gap: .4rem; padding-top: .6rem; border-top: 1px solid var(--line); }
.sec-title { margin: 0; font-size: .82rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.target-info { display: grid; gap: .45rem; }
.target-info p { margin: 0; }
.tgt-name { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.tgt-facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .15rem .7rem; margin: 0; font-size: .88rem; }
.tgt-facts dt { color: var(--muted); }
.tgt-facts dd { margin: 0; font-weight: 600; }
.tgt-facts .good { color: var(--good); } .tgt-facts .warn { color: var(--warn); } .tgt-facts .bad { color: var(--bad); }
.raid-table { width: 100%; border-collapse: collapse; font-size: .84rem; font-variant-numeric: tabular-nums; }
.raid-table th, .raid-table td { padding: .22rem .35rem; border-bottom: 1px solid var(--line); text-align: right; }
.raid-table th:first-child, .raid-table thead th:first-child { text-align: left; font-weight: 500; }
.raid-table thead th { color: var(--muted); font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; }
.raid-table tr.best th, .raid-table tr.best td { color: var(--good); font-weight: 700; }
.res-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .2rem; font-size: .9rem; }
.res-list li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .45rem; }
.res-list b { font-variant-numeric: tabular-nums; }
.res-dot { width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .3); }
.r-wood { background: #8a5a33; } .r-stones { background: #9d998f; } .r-metal-fragments { background: #8a8177; }
.r-metal-refined { background: #5d7d96; } .r-gears { background: #b59a5a; } .r-rope { background: #c9b37d; } .r-ladder-wooden-wall { background: #6e5231; }
.players { display: flex; align-items: center; justify-content: space-between; gap: .6rem; font-size: .85rem; color: var(--muted); }
.players .input { width: 5.5rem; min-height: 32px; padding: .25rem .5rem; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.file-btn:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.info .note { margin: 0; }
.g-tag.g-twig { color: #d2b27a; } .g-tag.g-wood { color: #c8915d; } .g-tag.g-stone { color: #c9c4b9; } .g-tag.g-metal { color: #c2b9ad; } .g-tag.g-hqm { color: #9fb3c6; }
:root[data-theme="light"] .g-tag.g-twig { color: #6e5231; }
:root[data-theme="light"] .g-tag.g-wood { color: #6a3f1d; }
:root[data-theme="light"] .g-tag.g-stone { color: #4d4a43; }
:root[data-theme="light"] .g-tag.g-metal { color: #4f4a44; }
:root[data-theme="light"] .g-tag.g-hqm { color: #2f4658; }

.keys-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.keys-table th { text-align: left; white-space: nowrap; padding: .3rem .8rem .3rem 0; color: var(--accent-2); font-family: var(--mono); font-size: .82rem; vertical-align: top; }
.keys-table td { padding: .3rem 0; border-bottom: 1px solid var(--line); }

/* ---------- guide under the builder ---------- */
.guide-cols { display: grid; gap: 1rem; }
.guide-cols h3 { font-size: .95rem; margin-bottom: .3rem; }
.guide-cols p { margin: 0; color: var(--muted); }
@media (min-width: 900px) { .guide-cols { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

@media (max-width: 560px) {
  .viewport { height: min(72dvh, 560px); }
  .hot { width: 40px; height: 40px; }
  .hot svg { width: 22px; height: 22px; }
  .fly-cta { left: 10px; right: auto; top: auto; bottom: 62px; max-width: calc(100% - 20px); }
  .fly-cta.touch { display: none; }
}

/* ---------- palette sprites and search ---------- */
.pal-search { min-height: 34px; }
.pal-ico { width: 24px; height: 24px; flex: none; display: grid; place-items: center; color: var(--muted); }
.pal-ico svg { width: 20px; height: 20px; }
img.pal-ico { object-fit: contain; }
.pal-btn.on .pal-ico { color: var(--accent-2); }
.hot img.pal-ico, .hot .pal-ico { width: 30px; height: 30px; color: #e3dccf; }
.hot .pal-ico svg { width: 26px; height: 26px; }
.palette-groups .pal-group[hidden], .pal-btn[hidden] { display: none; }
