/* Gemstone 3D interface. Dark neutral grays, one blue accent, Inter. */
:root {
  --bg: #1c1c1c;
  --viewport: #232325;
  --line: #2e2e2e;
  --card: #262626;
  --control: #333333;
  --control-on: #3a3a3a;
  --text: #dadada;
  --muted: #9a9a9a;
  --accent: #5b9dff;
  --left: 240px;
  --right: 300px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  font-size: 12px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: default; }

/* ---- overall layout: top bar, then diagram panel | viewport | properties panel ---- */
#app {
  height: 100%;
  display: grid;
  grid-template-columns: var(--left) minmax(0, 1fr) var(--right);
  grid-template-rows: 44px minmax(0, 1fr);
  grid-template-areas: "top top top" "left stage right";
}
#app.hide-left { grid-template-columns: 0 minmax(0, 1fr) var(--right); }
#app.hide-right { grid-template-columns: var(--left) minmax(0, 1fr) 0; }
#app.hide-left.hide-right { grid-template-columns: 0 minmax(0, 1fr) 0; }
#app.hide-left #left, #app.hide-right #right { display: none; }

/* ---- top bar ---- */
#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.brand { font-size: 14px; font-weight: 600; white-space: nowrap; }
#app:not(.hide-left) .brand { width: calc(var(--left) - 28px); }
.spacer { flex: 1 1 auto; }
.tools { display: flex; gap: 2px; }

/* ---- pills: a row of icon buttons on one rounded strip ---- */
.pill { display: flex; align-items: center; gap: 2px; padding: 3px; background: var(--card); border-radius: 8px; }
.pill.floating { background: var(--bg); border: 1px solid var(--line); }
.pill .divider { width: 1px; align-self: stretch; margin: 4px; background: var(--control-on); }
.icon-btn {
  width: 32px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0;
  background: transparent;
  color: #b3b3b3;
  border: 0;
  border-radius: 5px;
}
.icon-btn:hover:not(:disabled) { background: #2f2f2f; color: var(--text); }
.icon-btn[aria-pressed="true"] { background: var(--control-on); color: #ffffff; }
.icon-btn:disabled { color: #5c5c5c; }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#cuts { overflow-x: auto; scrollbar-width: none; }
#cuts .icon-btn { width: 34px; height: 30px; flex: none; }

/* ---- side panels ---- */
.panel { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; overflow-y: auto; min-width: 0; }
#left { grid-area: left; border-right: 1px solid var(--line); padding: 10px 8px; }
#right { grid-area: right; border-left: 1px solid var(--line); }
.heading { display: flex; align-items: center; justify-content: space-between; padding: 4px 2px 0 2px; font-size: 13px; font-weight: 600; }
.heading svg { color: var(--muted); }
.columns { display: flex; align-items: center; height: 26px; padding: 0 8px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.columns span:first-child { flex: 1 1 auto; }
.columns span + span { width: 46px; text-align: right; }
.empty { padding: 6px 8px; color: var(--muted); font-size: 11px; }
.card { background: var(--card); border-radius: 8px; padding: 0 12px; }
.card .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 36px; }
.card .row + .row { border-top: 1px solid #323232; }
.card.compact { padding: 8px 12px; }
.card.compact .row { min-height: 22px; }
.card.compact .row + .row { border-top: 0; }
.value { color: var(--text); font-variant-numeric: tabular-nums; }
.dim { color: var(--muted); }
.off { opacity: 0.45; }
.note { color: var(--muted); font-size: 11px; padding: 0 2px; }
#left .card { margin: 0 4px; }
#left .heading { padding: 4px 8px 0 8px; }
.foot { margin-top: auto; padding: 8px 8px 0 8px; color: var(--muted); font-size: 11px; }

.control { height: 26px; background: var(--control); color: var(--text); border: 0; border-radius: 5px; }
select.control { width: 138px; padding: 0 6px; }
.switch { position: relative; width: 36px; height: 20px; background: #454545; border: 0; border-radius: 10px; padding: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: var(--text); border-radius: 8px; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { left: 18px; background: #ffffff; }
.primary { height: 36px; display: flex; align-items: center; justify-content: center; gap: 8px; background: var(--accent); color: #07111f; border: 0; border-radius: 6px; font-weight: 600; }
.primary:disabled { background: var(--control); color: #7a7a7a; }
.push-down { margin-top: auto; }

/* ---- viewport ---- */
#stage { grid-area: stage; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
#viewport { position: relative; flex: 1 1 auto; min-height: 0; background: var(--viewport); overflow: hidden; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: default; }
#viewtools { position: absolute; left: 12px; top: 12px; }
#gizmo { position: absolute; right: 12px; top: 10px; pointer-events: none; }
.popover { position: absolute; left: 12px; top: 54px; width: 232px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); z-index: 3; }
.popover[hidden] { display: none; }
.popover .row { min-height: 30px; margin-top: 6px; }
.popover .row:first-child { margin-top: 0; }
.popover .row + .row { border-top: 0; }
.popover input[type="range"] { display: block; width: 100%; margin: 2px 0 4px 0; accent-color: var(--accent); }
.popover.flat input[type="range"], .popover.flat .row, .popover.grid-off .dims { opacity: 0.45; }
.popover .switch { flex: none; }
.segmented { display: flex; gap: 2px; padding: 3px; background: var(--card); border-radius: 7px; }
.segmented button { flex: 1 1 0; height: 26px; background: transparent; color: var(--muted); border: 0; border-radius: 5px; }
.segmented button[aria-pressed="true"] { background: var(--control-on); color: #ffffff; }
.segmented button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.overlay { position: absolute; color: var(--muted); font-size: 11px; pointer-events: none; user-select: none; }
#hint { left: 0; right: 0; bottom: 12px; text-align: center; }
#scale { right: 14px; bottom: 12px; }
#stone-name { left: 14px; bottom: 12px; }
#message { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; padding: 24px; text-align: center; }
#message div { max-width: 420px; padding: 14px 18px; background: var(--card); border-radius: 8px; }

/* ---- the four small fixed views under the viewport ---- */
/* The small views keep a 4:3 shape. They share the width, and stop growing once the row is about
   a quarter of the window tall, so the main viewport always keeps most of the room. */
#fourup { --gap: 8px; flex: none; display: flex; justify-content: center; gap: var(--gap); padding: var(--gap); }
#app.hide-views #fourup { display: none; }
.tile { position: relative; flex: none; width: min(calc((100% - 3 * var(--gap)) / 4), calc(26vh * 4 / 3)); aspect-ratio: 4 / 3; background: var(--viewport); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.tile canvas, .callout { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.callout { pointer-events: none; }
.callout line { stroke: #b9b9b9; stroke-width: 1; }
.callout text { fill: #b9b9b9; font-size: 11px; font-variant-numeric: tabular-nums; }
/* The view shown in the main viewport is outlined, and its button turns into the way back. */
.tile.active { border-color: var(--accent); }
.tile-expand { position: absolute; top: 3px; right: 3px; width: 26px; height: 24px; color: #8a8a8a; }
.tile-expand[aria-pressed="true"] { background: transparent; color: var(--accent); }
.tile-name { position: absolute; top: 7px; left: 9px; color: var(--muted); font-size: 11px; pointer-events: none; }

/* ---- narrow screens: panels float over the viewport instead of squeezing it ---- */
@media (max-width: 900px) {
  #app, #app.hide-left, #app.hide-right, #app.hide-left.hide-right { grid-template-columns: 0 minmax(0, 1fr) 0; }
  #left, #right { position: fixed; top: 44px; bottom: 0; z-index: 5; width: min(86vw, 300px); background: var(--bg); box-shadow: 0 0 24px rgba(0, 0, 0, 0.5); }
  #left { left: 0; }
  #right { right: 0; }
  #app:not(.hide-left) .brand { width: auto; }
  #hint { display: none; }
  #fourup { --gap: 4px; }
  .tile { aspect-ratio: 1; } /* four across on a phone is too short at 4:3 to fit a stone and its dimension line */
}
