/* =========================================================
   JSRay Studio · UI styles (the studio chrome, not the
   highlighted code itself which is themed by --jr-* vars).
   ========================================================= */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font: 14px/1.5 -apple-system, "Segoe UI", "PingFang SC",
        "Helvetica Neue", sans-serif;
  background: var(--jr-bg);
  color: var(--jr-fg);
  transition: background 200ms ease, color 200ms ease;
  min-height: 100vh;
}

/* --- Header --------------------------------------------------------------- */
.studio-header {
  max-width: 1280px;
  margin: 0 auto;
  padding: 48px 32px 24px;
}
.studio-header .brand {
  font-size: 11px;
  letter-spacing: 0.2em;
  opacity: 0.5;
  margin-bottom: 8px;
}
.studio-header h1 {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.studio-header p {
  margin: 0;
  opacity: 0.6;
  font-size: 13.5px;
}
.studio-nav {
  margin-top: 18px;
  font-size: 13px;
}
.studio-nav a {
  color: inherit;
  text-decoration: none;
  opacity: 0.55;
}
.studio-nav a:hover { opacity: 1; }

/* --- Toolbar -------------------------------------------------------------- */
.studio {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 32px 96px;
}
.studio-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 16px;
  margin-bottom: 20px;
  border-radius: 10px;
  background: rgba(127,127,127,0.08);
}
.toolbar-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.6;
}
.toolbar-field input {
  background: rgba(127,127,127,0.12);
  color: inherit;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  min-width: 200px;
  outline: none;
}
.toolbar-field input:focus { border-color: rgba(127,127,127,0.35); }

.toolbar-tabs {
  display: inline-flex;
  background: rgba(127,127,127,0.12);
  padding: 3px;
  border-radius: 8px;
}
.toolbar-tabs .tab {
  background: transparent;
  color: inherit;
  border: 0;
  padding: 7px 16px;
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  opacity: 0.6;
}
.toolbar-tabs .tab.active {
  background: rgba(127,127,127,0.25);
  opacity: 1;
}

.toolbar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  /* Three buttons at tap size overflow a 320px screen unless they can wrap. */
  flex-wrap: wrap;
}
.btn {
  background: rgba(127,127,127,0.15);
  color: inherit;
  border: 0;
  padding: 9px 16px;
  border-radius: 7px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: rgba(127,127,127,0.25); }
.btn.primary {
  background: var(--jr-fn-decl);
  color: var(--jr-bg);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1px rgba(127,127,127,0.25); }

/* --- Body grid ------------------------------------------------------------ */
.studio-body {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
}

/* A grid item defaults to min-width:auto, so it refuses to shrink below the
   intrinsic width of its content — and this one holds code. On a 390px phone
   both columns measured 412px and the whole page scrolled sideways. */
.studio-body > * { min-width: 0; }

@media (max-width: 900px) {
  .studio-body { grid-template-columns: 1fr; }
}

/* --- Picker list ---------------------------------------------------------- */
.pickers {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 78vh;
  overflow-y: auto;
  padding-right: 6px;
}

/* Once the two columns stack, capping the list turns it into a scroll area
   inside a page that also scrolls — on a touch screen the inner one swallows
   the gesture and the page appears stuck. Side by side it earns its keep;
   stacked it only gets in the way. */
@media (max-width: 900px) {
  .pickers {
    max-height: none;
    overflow-y: visible;
    padding-right: 0;
  }
}
.picker-group {
  margin-top: 14px;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.45;
  padding: 0 6px;
}
.picker-group:first-child { margin-top: 0; }
.picker-row {
  display: grid;
  grid-template-columns: 36px 1fr 88px;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 7px;
  font-size: 13px;
}
.picker-row:hover { background: rgba(127,127,127,0.06); }
.picker-row label {
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.picker-row .meta {
  font-size: 10.5px;
  opacity: 0.45;
  letter-spacing: 0.05em;
}
.picker-row input[type="color"] {
  width: 32px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  overflow: hidden;
}
.picker-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.picker-row input[type="color"]::-webkit-color-swatch { border: 1px solid rgba(127,127,127,0.2); border-radius: 4px; }
.picker-row .hex {
  font-family: ui-monospace, "JetBrains Mono", Menlo, monospace;
  font-size: 11.5px;
  background: rgba(127,127,127,0.12);
  border: 0;
  color: inherit;
  padding: 5px 8px;
  border-radius: 4px;
  text-align: center;
  outline: none;
  width: 88px;
}
.picker-row .hex:focus { background: rgba(127,127,127,0.25); }

/* --- Preview pane --------------------------------------------------------- */
.preview { display: flex; flex-direction: column; gap: 12px; }
.preview-tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  background: rgba(127,127,127,0.08);
  border-radius: 8px;
  align-self: flex-start;
}
.preview-tabs .ptab {
  background: transparent;
  color: inherit;
  border: 0;
  padding: 6px 12px;
  border-radius: 5px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  opacity: 0.55;
}
.preview-tabs .ptab.active {
  background: rgba(127,127,127,0.22);
  opacity: 1;
}
.preview-pane pre {
  margin: 0;
  min-height: 60vh;
}

/* --- Touch and small screens ---------------------------------------------- */

/* 32px of padding each side costs a 390px phone 16% of its width, and the
   picker row needs every pixel it can get before the hex field starts
   clipping. */
@media (max-width: 640px) {
  .studio-header { padding: 32px 20px 20px; }
  .studio { padding: 0 20px 72px; }
  .picker-row {
    grid-template-columns: 32px 1fr 76px;
    gap: 8px;
    padding: 7px 6px;
  }
  .picker-row .hex { width: 76px; padding: 6px 4px; }
}

/* Pointer:coarse is the finger, and 44px is the size Apple and the WCAG
   target-size rule both settle on. Bumping it here rather than in the width
   query keeps the desktop proportions exactly as they were, and still fixes a
   large touch screen — an iPad is 768px wide and every control on it was 35px. */
@media (pointer: coarse) {
  .btn { padding: 12px 18px; min-height: 44px; }
  .preview-tabs .ptab { padding: 11px 14px; min-height: 44px; }
  .toolbar-tabs .tab { padding: 11px 18px; min-height: 44px; }
  .toolbar-field input { min-height: 44px; }
  /* Wrapped rows of 44px buttons need 48px between centres or the row below
     takes the tap; the column gaps stay as they are. */
  .preview-tabs, .toolbar-tabs, .toolbar-actions { row-gap: 6px; }
  .picker-row { padding-top: 10px; padding-bottom: 10px; }
  .picker-row .hex,
  .picker-row input[type="color"] { min-height: 44px; }

  /* The underline is applied on hover, so the hit area is grown with an
     overlay instead of padding that would drag it away from the words. */
  .studio-nav a { position: relative; display: inline-block; }
  .studio-nav a::after {
    content: "";
    position: absolute;
    left: 0; right: 0; top: 50%;
    height: 48px;
    transform: translateY(-50%);
  }
}
