:root {
  --bg: #0b0c0e;
  --bg-elevated: #12141a;
  --bg-panel: #161922;
  --border: #2a2f3a;
  --text: #e8eaed;
  --muted: #8b93a7;
  --orange: #ff8200;
  --orange-dim: #c46500;
  --green: #7dce9a;
  --danger: #ff6b6b;
  --font: "IBM Plex Mono", "Share Tech Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  user-select: none;
}

.brand-mark {
  color: var(--orange);
  font-size: 1.4rem;
  line-height: 1;
}

.brand-title {
  font-weight: 600;
  letter-spacing: 0.04em;
  font-size: 0.95rem;
}

.brand-tag {
  color: var(--muted);
  font-size: 0.7rem;
}

.tabs {
  display: flex;
  gap: 0.35rem;
}

.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
  border-color: var(--border);
}

.tab.active {
  color: var(--bg);
  background: var(--orange);
  border-color: var(--orange);
  font-weight: 600;
}

/* Views */
main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
  flex: 1;
  min-height: 0;
}

.view.active {
  display: flex;
  flex-direction: column;
}

/* Home */
.home-shell {
  max-width: 720px;
  margin: 4rem auto;
  padding: 0 1.5rem;
}

.home-shell h1 {
  margin: 0 0 0.5rem;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.home-lead {
  color: var(--muted);
  margin: 0 0 2rem;
}

.home-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.home-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  padding: 1.25rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: inherit;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.home-card:not(.muted):hover {
  border-color: var(--orange);
  transform: translateY(-2px);
}

.home-card.muted {
  cursor: default;
  opacity: 0.55;
}

.home-card-icon {
  color: var(--orange);
  font-size: 1.25rem;
}

.home-card-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.home-card-desc {
  color: var(--muted);
  font-size: 0.75rem;
}

/* BlockyFlipper toolbar */
.bf-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: space-between;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.bf-toolbar-left,
.bf-toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.btn {
  font-family: inherit;
  font-size: 0.75rem;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  cursor: pointer;
}

.btn:hover {
  border-color: var(--muted);
}

.btn-ghost {
  background: transparent;
}

.btn-primary {
  background: var(--orange);
  border-color: var(--orange);
  color: #111;
  font-weight: 600;
}

.btn-primary:hover {
  background: #ff9326;
}

.btn-accent {
  border-color: var(--orange-dim);
  color: var(--orange);
}

.btn-tiny {
  font-size: 0.65rem;
  padding: 0.2rem 0.45rem;
}

/* Layout */
.bf-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr minmax(280px, 340px);
  gap: 0;
}

.bf-workspace-wrap {
  min-height: 0;
  border-right: 1px solid var(--border);
  position: relative;
}

#blockly-div {
  position: absolute;
  inset: 0;
}

.bf-side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-bottom: 1px solid var(--border);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.panel-hint {
  color: var(--orange);
  font-size: 0.65rem;
}

/* Simulator */
.sim-panel {
  flex: 0 0 auto;
}

.flipper-device {
  padding: 1rem 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.flipper-bezel {
  background: #1a1c22;
  border: 2px solid #3a3f4b;
  border-radius: 8px;
  padding: 8px;
  box-shadow: inset 0 0 0 1px #000, 0 8px 24px rgba(0, 0, 0, 0.45);
}

#sim-canvas {
  display: block;
  width: 256px;
  height: 128px;
  image-rendering: pixelated;
  background: #8fbf8f;
  border-radius: 2px;
}

.flipper-controls {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 0.35rem;
  width: 100%;
  max-width: 200px;
}

.fz-mid {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.fz-btn {
  font-family: inherit;
  font-size: 0.7rem;
  min-width: 40px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid #444a58;
  background: linear-gradient(180deg, #2a2e38, #1c1f27);
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.fz-btn:active,
.fz-btn.pressed {
  background: var(--orange);
  color: #111;
  border-color: var(--orange);
}

.fz-ok {
  min-width: 48px;
  font-weight: 600;
}

.fz-back {
  margin-top: 0.25rem;
  width: 100%;
  max-width: 120px;
  font-size: 0.65rem;
}

.sim-note {
  margin: 0 0.75rem 0.75rem;
  font-size: 0.65rem;
  color: var(--muted);
  text-align: center;
}

/* Code panel */
.code-panel {
  flex: 1;
  min-height: 160px;
}

#code-output {
  margin: 0;
  padding: 0.75rem;
  overflow: auto;
  flex: 1;
  font-size: 0.68rem;
  line-height: 1.45;
  color: #c8d0e0;
  background: #0e1015;
  white-space: pre;
}

#code-output code {
  font-family: inherit;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 480px;
  width: 100%;
}

.modal-card h3 {
  margin: 0 0 0.75rem;
  color: var(--orange);
}

.modal-card p {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text);
}

.modal-card .muted {
  color: var(--muted);
  font-size: 0.8rem;
}

.modal-code {
  background: #0e1015;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.75rem;
  overflow-x: auto;
  color: var(--green);
}

/* Blockly dark-ish overrides */
.blocklyMainBackground {
  fill: #0e1015 !important;
}

.blocklyToolboxDiv {
  background: var(--bg-elevated) !important;
  border-right: 1px solid var(--border) !important;
  color: var(--text);
}

.blocklyTreeRow {
  color: var(--text) !important;
}

.blocklyTreeLabel {
  font-family: var(--font) !important;
  font-size: 12px !important;
}

.blocklyFlyoutBackground {
  fill: #14171f !important;
}

@media (max-width: 960px) {
  .bf-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .bf-workspace-wrap {
    min-height: 420px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  #blockly-div {
    position: absolute;
  }

  .bf-side {
    max-height: 50vh;
  }
}

/* PHP layout + Run button */
.brand {
  text-decoration: none;
  color: inherit;
}

a.tab {
  text-decoration: none;
}

a.home-card {
  text-decoration: none;
}

.bf-page {
  display: flex !important;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.btn-run {
  background: #1f6f43;
  border-color: #2a9a5c;
  color: #e8ffe8;
  font-weight: 600;
}

.btn-run:hover {
  background: #258a52;
}

.btn-run.running {
  background: var(--orange);
  border-color: var(--orange);
  color: #111;
}
