:root {
  color-scheme: dark;
  --ink: #f6f2e8;
  --muted: #a9ad9f;
  --panel: rgba(25, 27, 24, 0.86);
  --panel-solid: #1b1d1a;
  --line: rgba(232, 222, 196, 0.16);
  --line-strong: rgba(232, 222, 196, 0.26);
  --accent: #d7c27a;
  --accent-ink: #15130c;
  --danger: #d98b7b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #11120f;
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
p {
  margin: 0;
}

.studio-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(215, 194, 122, 0.08), transparent 38%),
    linear-gradient(315deg, rgba(99, 141, 124, 0.12), transparent 46%),
    #11120f;
}

.topbar {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: auto minmax(230px, 1fr) auto auto auto auto;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 18, 15, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand-lockup {
  display: flex;
  min-width: 190px;
  gap: 11px;
  align-items: center;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(215, 194, 122, 0.42);
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 42%, rgba(246, 242, 232, 0.78) 43% 50%, transparent 51%),
    linear-gradient(160deg, #174c3d, #0d2822);
  box-shadow:
    inset 0 0 18px rgba(255, 255, 255, 0.05),
    0 10px 24px rgba(0, 0, 0, 0.28);
}

.brand-lockup h1 {
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: 0;
}

.brand-lockup p,
.control-field span,
.scene-status span {
  color: var(--muted);
  font-size: 0.78rem;
}

.tool-group,
.control-group,
.guide-group,
.board-group,
.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tool-group {
  justify-content: center;
}

.action-group {
  justify-content: end;
}

.board-group {
  justify-content: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(246, 242, 232, 0.045);
}

.guide-group {
  justify-content: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(246, 242, 232, 0.045);
}

.tool-button,
.icon-button,
.secondary-action,
.primary-action {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(246, 242, 232, 0.06);
  color: var(--ink);
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

.tool-button:hover,
.icon-button:hover,
.secondary-action:hover,
.primary-action:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: rgba(246, 242, 232, 0.1);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  transform: none;
}

.tool-button.is-active {
  border-color: rgba(215, 194, 122, 0.72);
  background: rgba(215, 194, 122, 0.18);
  color: #fff7d3;
}

.icon-button.is-active {
  border-color: rgba(215, 194, 122, 0.58);
  background: rgba(215, 194, 122, 0.14);
  color: #fff7d3;
}

.tool-button,
.icon-button {
  display: grid;
  width: 38px;
  padding: 0;
  place-items: center;
}

.tool-button svg,
.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.primary-action {
  padding: 0 14px;
  border-color: rgba(215, 194, 122, 0.72);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.secondary-action {
  min-width: 82px;
  padding: 0 12px;
  font-weight: 700;
}

.guide-selected-name {
  display: grid;
  min-width: 78px;
  height: 38px;
  place-items: center;
  color: #fff7d3;
  font-size: 0.84rem;
  font-weight: 700;
}

.board-counter {
  display: grid;
  min-width: 52px;
  height: 38px;
  place-items: center;
  color: #fff7d3;
  font-size: 0.84rem;
  font-weight: 700;
}

.add-board-button {
  border-color: rgba(215, 194, 122, 0.48);
  color: #fff7d3;
}

.danger-action {
  border-color: rgba(232, 111, 97, 0.46);
  color: #ffc9bf;
}

.danger-action:hover {
  border-color: rgba(232, 111, 97, 0.78);
  background: rgba(232, 111, 97, 0.13);
}

.control-group {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(246, 242, 232, 0.045);
}

.control-field {
  display: grid;
  gap: 4px;
}

.control-field input[type="color"] {
  width: 44px;
  height: 26px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: transparent;
}

.control-field select {
  height: 28px;
  min-width: 110px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(246, 242, 232, 0.08);
  color: var(--ink);
  padding: 0 28px 0 8px;
}

.control-field select option {
  background: var(--panel-solid);
  color: var(--ink);
}

.range-field {
  width: 120px;
}

.range-field span {
  display: flex;
  justify-content: space-between;
}

.range-field input {
  width: 100%;
  accent-color: var(--accent);
}

.stage-wrap {
  position: relative;
  min-height: 0;
}

.guide-library {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 4;
  display: grid;
  width: min(520px, calc(100% - 36px));
  max-height: min(620px, calc(100% - 36px));
  gap: 12px;
  padding: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 21, 18, 0.92);
  box-shadow: 0 20px 54px rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(16px);
}

.board-overview {
  position: absolute;
  inset: 18px;
  z-index: 5;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 21, 18, 0.94);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(18px);
}

.chalk-palette {
  position: absolute;
  right: auto;
  bottom: 18px;
  left: 50%;
  z-index: 6;
  display: grid;
  width: min(460px, calc(100% - 36px));
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 21, 18, 0.94);
  box-shadow: 0 22px 58px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(16px);
  transform: translateX(-50%);
}

.chalk-palette.hidden {
  display: none;
}

.chalk-palette-header {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.chalk-palette-header div {
  display: grid;
  gap: 2px;
}

.chalk-palette-header strong {
  color: #fff7d3;
}

.chalk-palette-header span {
  color: var(--muted);
  font-size: 0.78rem;
}

.chalk-palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(94px, 1fr));
  gap: 10px;
}

.chalk-swatch {
  position: relative;
  display: grid;
  min-height: 72px;
  gap: 7px;
  align-content: center;
  justify-items: center;
  padding: 9px 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(246, 242, 232, 0.045);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 8px 18px rgba(0, 0, 0, 0.18);
  color: var(--ink);
  overflow: hidden;
}

.chalk-swatch::before {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 18% 28%, rgba(255, 255, 255, 0.08) 0 1px, transparent 2px),
    radial-gradient(circle at 76% 70%, rgba(255, 255, 255, 0.06) 0 1px, transparent 2px);
  background-size: 18px 16px, 22px 20px;
  content: "";
  opacity: 0.7;
  pointer-events: none;
}

.chalk-swatch-stick {
  position: relative;
  display: block;
  width: min(74px, 100%);
  height: 18px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background:
    radial-gradient(circle at 18% 45%, rgba(255, 255, 255, 0.72) 0 1px, transparent 2px),
    radial-gradient(circle at 52% 35%, rgba(255, 255, 255, 0.32) 0 1px, transparent 2px),
    radial-gradient(circle at 73% 62%, rgba(0, 0, 0, 0.16) 0 1px, transparent 2px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.62), transparent 16%, transparent 82%, rgba(0, 0, 0, 0.22)),
    var(--swatch);
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, 0.22),
    inset 0 -4px 7px rgba(0, 0, 0, 0.16),
    0 5px 9px rgba(0, 0, 0, 0.28);
  transform: rotate(-3deg);
}

.chalk-swatch-stick::before,
.chalk-swatch-stick::after {
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 8px;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.62), transparent 42%),
    linear-gradient(rgba(255, 255, 255, 0.28), rgba(0, 0, 0, 0.08)),
    var(--swatch);
  content: "";
}

.chalk-swatch-stick::before {
  left: 2px;
}

.chalk-swatch-stick::after {
  right: 2px;
  filter: brightness(0.88);
}

.chalk-swatch-dust {
  position: absolute;
  inset: -5px 7px;
  background:
    radial-gradient(circle at 15% 70%, rgba(255, 255, 255, 0.34) 0 1px, transparent 2px),
    radial-gradient(circle at 44% 28%, rgba(255, 255, 255, 0.26) 0 1px, transparent 2px),
    radial-gradient(circle at 82% 64%, rgba(255, 255, 255, 0.22) 0 1px, transparent 2px);
  content: "";
  opacity: 0.9;
}

.chalk-swatch-name {
  position: relative;
  z-index: 1;
  max-width: 100%;
  color: #fff7d3;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.05;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chalk-swatch:hover,
.chalk-swatch.is-active {
  border-color: rgba(215, 194, 122, 0.8);
  transform: translateY(-1px);
}

.chalk-swatch.is-active::after {
  position: absolute;
  right: 6px;
  bottom: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #15130c;
  box-shadow: 0 0 0 2px rgba(255, 247, 211, 0.9);
  content: "";
}

.board-overview.hidden {
  display: none;
}

.board-overview-header,
.overview-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.board-overview-header div:first-child {
  display: grid;
  gap: 2px;
}

.board-overview-header strong {
  color: #fff7d3;
}

.board-overview-header span {
  color: var(--muted);
  font-size: 0.78rem;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.overview-tile {
  display: grid;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(246, 242, 232, 0.05);
  color: var(--ink);
  text-align: left;
}

.overview-tile:hover,
.overview-tile.is-active {
  border-color: rgba(215, 194, 122, 0.66);
  background: rgba(215, 194, 122, 0.14);
}

.overview-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid rgba(232, 222, 196, 0.12);
  border-radius: 6px;
  background: #103d34;
}

.overview-tile span {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.78rem;
}

.overview-tile strong,
.overview-tile em {
  font-style: normal;
  font-weight: 700;
}

.overview-tile strong {
  color: #fff7d3;
}

.guide-library.hidden {
  display: none;
}

.guide-library-header {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.guide-library-header div {
  display: grid;
  gap: 2px;
}

.guide-library-header strong {
  color: #fff7d3;
}

.guide-library-header span {
  color: var(--muted);
  font-size: 0.78rem;
}

.guide-category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.guide-category-button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(246, 242, 232, 0.06);
  color: var(--ink);
}

.guide-category-button.is-active {
  border-color: rgba(215, 194, 122, 0.66);
  background: rgba(215, 194, 122, 0.18);
  color: #fff7d3;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.guide-tile {
  display: grid;
  min-height: 74px;
  gap: 5px;
  align-content: center;
  justify-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(246, 242, 232, 0.05);
  color: var(--ink);
}

.guide-tile:hover,
.guide-tile.is-active {
  border-color: rgba(215, 194, 122, 0.66);
  background: rgba(215, 194, 122, 0.15);
}

.guide-tile svg {
  width: 34px;
  height: 34px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.guide-tile span {
  font-size: 0.78rem;
}

.guide-tile.is-letter {
  min-height: 62px;
}

.guide-letter-preview {
  color: #fff7d3;
  font-size: 1.65rem !important;
  font-weight: 700;
}

#chalkScene {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.scene-status {
  position: absolute;
  right: 18px;
  bottom: 18px;
  display: flex;
  gap: 10px;
  align-items: center;
  max-width: min(560px, calc(100% - 36px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(12px);
}

.board-transition {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  display: grid;
  width: 148px;
  height: 54px;
  place-items: center;
  border: 1px solid rgba(215, 194, 122, 0.46);
  border-radius: 8px;
  background: rgba(20, 21, 18, 0.76);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.38);
  color: #fff7d3;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) translateY(18px) scale(0.96);
  transition:
    opacity 160ms ease,
    transform 260ms ease;
  backdrop-filter: blur(12px);
}

.board-transition.is-prev {
  transform: translate(-50%, -50%) translateY(-18px) scale(0.96);
}

.board-transition.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) translateY(0) scale(1);
}

.scene-status strong {
  color: #fff7d3;
  font-size: 0.86rem;
}

[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  z-index: 6;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-solid);
  color: var(--ink);
  content: attr(data-tooltip);
  font-size: 0.72rem;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(3px);
  transition:
    opacity 120ms ease,
    transform 120ms ease;
  white-space: nowrap;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr auto auto;
  }

  .brand-lockup {
    grid-column: 1;
  }

  .tool-group {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: start;
  }

  .control-group {
    grid-column: 1;
  }

  .guide-group {
    grid-column: 1;
    grid-row: 4;
    justify-content: start;
  }

  .board-group {
    grid-column: 2;
    grid-row: 3;
  }

  .action-group {
    grid-column: 2 / -1;
    grid-row: 1;
  }
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .studio-shell {
    height: 100vh;
    min-height: 100vh;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .tool-group,
  .control-group,
  .guide-group,
  .board-group,
  .action-group {
    grid-column: 1;
    grid-row: auto;
    justify-content: start;
  }

  .tool-button {
    width: 40px;
  }

  .range-field {
    width: min(145px, 44vw);
  }

  .scene-status {
    left: 12px;
    right: 12px;
    bottom: 12px;
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .guide-library {
    top: 10px;
    left: 10px;
    width: calc(100% - 20px);
    max-height: calc(100% - 20px);
  }

  .chalk-palette {
    bottom: 10px;
    left: 10px;
    width: calc(100% - 20px);
    transform: none;
  }

  .board-overview {
    inset: 10px;
    padding: 12px;
  }

  .overview-grid {
    grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
  }

  .board-overview-header {
    align-items: flex-start;
    flex-direction: column;
  }
}
