/* BoardCraft — standalone stylesheet following the MasterCraft design tokens. */

:root {
  --bg: #f8f9fa;
  --surface: #e9ecef;
  --ink: #0a1d37;
  --muted: #6d6e71;
  --border: #bcbec0;
  --primary: #0f69f0;
  --accent: #3d348b;
  --danger: #d90429;
  --shadow: 0 1px 3px rgba(10, 29, 55, 0.12);
  --radius-control: 8px;
  --radius-panel: 12px;
  --transition: 150ms cubic-bezier(0.25, 1, 0.5, 1);
  /* Board studio fonts: self-hosted faces from assets/font (assets/fonts.css does not ship yet). */
  --mc-font-display: 'Polymath Display', 'Archivo', system-ui, sans-serif;
  --mc-font-body: 'Polymath Body', 'Inter', system-ui, sans-serif;
}

@font-face {
  font-family: 'Polymath Display';
  src: url('fonts/Polymath-Bold.woff2') format('woff2');
  font-weight: 600 700;
  font-display: swap;
}
@font-face {
  font-family: 'Polymath Body';
  src: url('fonts/Polymath-Regular.woff2') format('woff2');
  font-weight: 400 600;
  font-display: swap;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over class display values. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-rows: 56px 1fr 28px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mc-font-body);
  font-size: 14px;
  line-height: 1.5;
}

.mono { font-family: ui-monospace, 'Cascadia Mono', 'Consolas', monospace; }

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

button i,
button svg { pointer-events: none; }
button svg { width: 18px; height: 18px; stroke-width: 2; }

/* ---- Top bar ------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--accent);
  flex: none;
}

.brand-name {
  font-family: var(--mc-font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
  flex: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--ink);
  transition: background var(--transition);
}
.icon-btn:hover { background: var(--surface); }
.icon-btn:disabled { color: var(--border); cursor: default; background: transparent; }

.zoom-pill {
  min-width: 52px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: transparent;
  font-variant-numeric: tabular-nums;
  transition: background var(--transition);
}
.zoom-pill:hover { background: var(--surface); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: #fff;
  color: var(--ink);
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition);
}
.btn:hover { background: var(--surface); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #0b55c4; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn svg { width: 16px; height: 16px; }

/* ---- Main area ----------------------------------------------------------- */

.main {
  display: flex;
  min-height: 0;
  min-width: 0;
}

.toolbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 48px;
  padding: 8px 0;
  background: #fff;
  border-right: 1px solid var(--border);
  flex: none;
  overflow-y: auto;
}

.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--ink);
  transition: background var(--transition), color var(--transition);
}
.tool:hover { background: var(--surface); }
.tool[aria-pressed="true"] {
  background: rgba(61, 52, 139, 0.12);
  color: var(--accent);
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  background: #fff;
}

#stage-container { position: absolute; inset: 0; }
#stage-container .konvajs-content { outline: none; }

/* ---- Text editor overlay -------------------------------------------------- */

.text-editor {
  position: absolute;
  z-index: 5;
  margin: 0;
  padding: 0;
  border: 1px dashed var(--accent);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-family: var(--mc-font-body);
  resize: none;
  overflow: hidden;
  white-space: pre;
}
.text-editor:focus { outline: none; border-color: var(--primary); }

/* ---- Properties panel ----------------------------------------------------- */

.props {
  width: 260px;
  flex: none;
  padding: 16px;
  background: var(--bg);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.props-title {
  margin: 0 0 12px;
  font-family: var(--mc-font-display);
  font-weight: 600;
  font-size: 16px;
}

.props-empty { margin: 0; color: var(--muted); font-size: 13px; }

.props-body { display: flex; flex-direction: column; gap: 12px; }

.prop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.prop-label { color: var(--muted); font-size: 13px; flex: none; }

.prop-row input[type="color"] {
  width: 44px;
  height: 30px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: #fff;
}

.prop-row input[type="number"] {
  width: 72px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: #fff;
  font: inherit;
}

.prop-row input[type="range"] { flex: 1; min-width: 0; accent-color: var(--primary); }

.prop-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }

.prop-row output { min-width: 40px; text-align: right; font-variant-numeric: tabular-nums; }

.layer-btns { display: flex; gap: 6px; }

.props-toggle {
  display: none;
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 20;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
}

/* ---- Status bar ------------------------------------------------------------ */

.statusbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 12px;
  background: #fff;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
}

.status-item { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ---- Modals ----------------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 29, 55, 0.4);
}

.modal {
  width: min(420px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px;
  background: #fff;
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow);
}

.modal h2 {
  margin: 0 0 14px;
  font-family: var(--mc-font-display);
  font-weight: 600;
  font-size: 20px;
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field span { font-size: 13px; color: var(--muted); }
.field input {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: #fff;
  font: inherit;
  color: var(--ink);
}

.modal-hint { margin: 0 0 12px; font-size: 13px; color: var(--muted); min-height: 1em; }
.modal-hint.error { color: var(--danger); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.open-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
}

.open-list li {
  border-bottom: 1px solid var(--surface);
}

.open-item {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 8px;
  border: none;
  background: transparent;
  text-align: left;
  border-radius: var(--radius-control);
  transition: background var(--transition);
}
.open-item:hover { background: var(--surface); }
.open-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.open-item .date { color: var(--muted); font-size: 12px; flex: none; }

/* ---- Legacy .toast styles (MCStudio.toast renders .mc-toast via studio-chrome.css) */

.toast-zone {
  position: fixed;
  right: 16px;
  bottom: 40px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 14px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-control);
  box-shadow: var(--shadow);
  max-width: 320px;
}
.toast.error { background: var(--danger); }

/* ---- Responsive --------------------------------------------------------------- */

@media (max-width: 900px) {
  .props {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 28px;
    z-index: 30;
    width: auto;
    max-height: 50vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: var(--radius-panel) var(--radius-panel) 0 0;
    transform: translateY(calc(100% + 28px));
    transition: transform var(--transition);
  }
  .props.open { transform: translateY(0); }
  .props-toggle { display: inline-flex; }
}

@media (max-width: 740px) {
  .brand-name { display: none; }
  .btn-label { display: none; }
  .btn { padding: 0 10px; }
  #zoom-out, #zoom-in { display: none; }
  .topbar-sep { margin: 0; }
  .statusbar { gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Studio chrome bar occupies the first grid row (see assets/css/studio-chrome.css). */
body { grid-template-rows: var(--mc-h) 56px 1fr 28px; }
