/* ============================================================
   cuBe.LOG — light, tidy design system
   ============================================================ */
:root {
  --bg:          #fdfdfb;
  --card:        #ffffff;
  --text:        #1c1c28;
  --muted:       #6b6b76;
  --accent:      #0b7a75;
  --accent-soft: rgba(11, 122, 117, 0.08);
  --border:      #e5e5e0;
  --band-bg:     #f2f2ee;   /* grey band behind home article area */
  --tag-bg:      #ece8e0;   /* very light brown/grey tag chips */
  --tag-text:    #6f6353;
  --code-bg:     #f6f6f2;
  --code-border: #e8e8e2;
  --cube-char:   #20202c;   /* ascii cube + mini cube color */
  --cube-ring:   #9a9aa4;   /* saturn ring text color */
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

/* ---------------- nav ---------------- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 clamp(16px, 4vw, 48px);
  height: 58px;
  background: rgba(253, 253, 251, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  letter-spacing: 0.02em;
}
.brand:hover { text-decoration: none; }

canvas.mini-cube { display: block; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 22px;
}
.nav-links a {
  color: var(--muted);
  font-size: 15px;
  letter-spacing: 0.03em;
}
.nav-links a:hover,
.nav-links a.active { color: var(--accent); text-decoration: none; }

.nav-search input {
  width: clamp(110px, 16vw, 190px);
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
}
.nav-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.nav-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.nav-icon:hover,
.lang-menu[open] > .nav-icon { color: var(--accent); border-color: var(--border); background: var(--card); }

.search-toggle { display: none; }

.lang-menu { position: relative; }
.lang-menu > summary { list-style: none; }
.lang-menu > summary::-webkit-details-marker { display: none; }

.lang-list {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 150px;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(28, 28, 40, 0.08);
}
.lang-list a {
  display: block;
  padding: 7px 12px;
  border-radius: 6px;
  color: var(--text);
  font-size: 14.5px;
}
.lang-list a:hover { background: var(--accent-soft); text-decoration: none; }
.lang-list a[aria-current] { color: var(--accent); font-weight: 600; }
.lang-list a[aria-current]::after { content: " \2713"; }

/* no sideways scrolling on phones, even if one element misbehaves (clip keeps the sticky nav working) */
html, body { overflow-x: clip; }

@media (max-width: 640px) {
  .site-nav { gap: 12px; padding: 0 12px; }
  .brand { font-size: 15px; letter-spacing: 0; }
  .nav-links { gap: 12px; min-width: 0; }
  .nav-links a { font-size: 14px; letter-spacing: 0; white-space: nowrap; }
  .nav-tools { gap: 2px; }
  canvas.mini-cube { display: none; }

  .search-toggle { display: inline-flex; }
  .nav-search {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    padding: 10px 12px;
    background: rgba(253, 253, 251, 0.97);
    border-bottom: 1px solid var(--border);
  }
  .site-nav.search-open .nav-search { display: block; }
  .nav-search input { width: 100%; font-size: 16px; }  /* 16px stops iOS zooming on focus */
}

/* ---------------- layout ---------------- */
.wrap        { max-width: 960px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 32px); }
.wrap-narrow { max-width: 760px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 32px); }

.section-title {
  font-size: 14px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--muted);
  margin: 48px 0 18px;
}

/* ---------------- hero (home) ---------------- */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 0 8px;
}

.cube-stage {
  position: relative;
  width: min(92vw, 860px);
  height: min(52vh, 420px);
  overflow: hidden;   /* the ascii pre can never bleed over the tagline */
}

#ring-back  { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none; }
#ring-front { position: absolute; top: 0; left: 0; z-index: 3; pointer-events: none; }

#cube-pre {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  margin: 0;
  color: var(--cube-char);
  font: 10pt/1.2 'Courier New', Courier, monospace;
  white-space: pre;
  background: transparent;
  pointer-events: none;
  user-select: none;
}

.hero-tagline {
  margin: 6px 0 0;
  font-family: var(--mono);
  font-size: clamp(15px, 2.4vw, 19px);
  color: var(--muted);
  letter-spacing: 0.06em;
  text-align: center;
}

/* ---------------- home band + side panel ---------------- */
.home-band {
  margin-top: 34px;
  padding: 4px 0 26px;
  background: var(--band-bg);
  border-top: 1px solid var(--border);
}

.side-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 40px;
  align-items: start;
}

.side-panel { position: sticky; top: 76px; }

.side-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 860px) {
  .side-grid { grid-template-columns: 1fr; gap: 0; }
  .side-panel { position: static; }
}

/* ---------------- article cards ---------------- */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 56px;
}

.article-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  color: var(--text);
  overflow: hidden;   /* clips the banner to the rounded corners */
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.article-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  text-decoration: none;
}

.card-banner {
  margin: -20px -24px 16px;
  height: 170px;
  background: var(--code-bg);
}
.card-banner img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.article-card h3 {
  margin: 0 0 6px;
  font-size: 19px;
  line-height: 1.4;
}

.article-card p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 15px;
}

.card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------------- tags ---------------- */
.tag-chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.7;
  white-space: nowrap;
}
a.tag-chip:hover { text-decoration: none; filter: brightness(0.94); }

.tag-chip.active {
  background: var(--accent);
  color: #fff;
}

.tag-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 20px 0 26px;
}

/* ---------------- article page ---------------- */
.article-banner { margin: 40px 0 0; }
.article-banner img {
  display: block;
  width: 100%;
  max-height: 340px;
  object-fit: cover;
  border-radius: 12px;
}
.article-banner + .article-header { margin-top: 26px; }

.article-header { margin: 48px 0 8px; }

.article-header h1 {
  font-size: clamp(26px, 4.5vw, 36px);
  line-height: 1.25;
  margin: 0 0 12px;
}

.article-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.article-body { padding-bottom: 64px; }

.article-body h2 {
  font-size: 24px;
  margin: 44px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.article-body h3 { font-size: 19px; margin: 32px 0 10px; }
.article-body p  { margin: 0 0 18px; }
.article-body li { margin-bottom: 6px; }

.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 22px;
  font-size: 15px;
}
.article-body th,
.article-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.article-body th { background: var(--code-bg); font-family: var(--mono); font-size: 13.5px; }

/* wide content scrolls inside itself instead of widening the page */
.article-body .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
@media (max-width: 640px) {
  .article-body table { display: block; overflow-x: auto; font-size: 14px; }
  .article-body th,
  .article-body td { padding: 6px 8px; white-space: nowrap; }
}

.article-body code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 1px 5px;
}

blockquote {
  margin: 0 0 18px;
  padding: 10px 18px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
  color: var(--text);
}

/* ---------------- code blocks + results ---------------- */
.code-block {
  margin: 0 0 4px;
  border: 1px solid var(--code-border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--code-bg);
}

.code-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 12px;
  border-bottom: 1px solid var(--code-border);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: #f0f0ea;
}

.code-copy {
  border: none;
  background: none;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
}
.code-copy:hover { color: var(--accent); }

.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.55;
  background: transparent;
}
.code-block pre code { background: none; border: none; padding: 0; font-size: inherit; }

.code-result {
  margin: 0 0 22px;
  border: 1px dashed var(--border);
  border-radius: 0 0 8px 8px;
  border-top: none;
  background: var(--card);
}

.code-result-label {
  display: block;
  padding: 5px 12px 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.code-result pre {
  margin: 0;
  padding: 8px 16px 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text);
}

/* standalone result (no code block above) */
.code-result.standalone { border-radius: 8px; border-top: 1px dashed var(--border); }

/* ---------------- embeds ---------------- */
.embed-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin: 0 0 22px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card);
}
.embed-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* generic full-width block for maps / charts an article mounts JS into */
.viz-box {
  width: 100%;
  margin: 0 0 22px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

/* ---------------- about ---------------- */
.about-hero {
  display: flex;
  align-items: center;
  gap: 24px;
  margin: 56px 0 24px;
}

/* ---------------- footer ---------------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 22px 0 30px;
  text-align: center;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
}

/* ---------------- pill button ---------------- */
.btn {
  display: inline-block;
  padding: 7px 18px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-family: var(--mono);
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.1); text-decoration: none; }

.btn.ghost {
  background: transparent;
  color: var(--accent);
}
.btn.danger { background: #b3372f; border-color: #b3372f; }
.btn.small  { padding: 3px 10px; font-size: 12.5px; }

/* ---------------- admin ---------------- */
.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 32px clamp(16px, 3vw, 32px) 64px; }

.admin-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 26px;
}
.admin-bar h1 { font-size: 22px; margin: 0; font-family: var(--mono); }
.admin-bar .spacer { margin-left: auto; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  font-size: 14.5px;
}
.admin-table th, .admin-table td {
  border: 1px solid var(--border);
  padding: 9px 12px;
  text-align: left;
  vertical-align: middle;
}
.admin-table th {
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.admin-table .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.status-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 6px;
}
.status-dot.on  { background: #2e9e46; }
.status-dot.off { background: #c2c2ba; }

/* forms */
.form-grid { display: flex; flex-direction: column; gap: 16px; }

.form-row { display: flex; flex-direction: column; gap: 5px; }
.form-row label {
  font-family: var(--mono);
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.form-row input[type="text"],
.form-row input[type="password"],
.form-row select,
.form-row textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  padding: 9px 12px;
}
.form-row textarea { resize: vertical; line-height: 1.5; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-inline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.banner-row { display: flex; gap: 8px; align-items: center; }
.banner-row input[type="text"] {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  padding: 9px 12px;
}
.banner-row input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* uploads gallery */
.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.upload-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.upload-card img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--code-bg);
}
.upload-card .upload-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
}
.upload-card .upload-meta span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }

.flash {
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 18px;
  font-size: 14.5px;
}
.flash.ok  { background: rgba(46, 158, 70, 0.1); color: #1e7a33; border: 1px solid rgba(46,158,70,.3); }
.flash.err { background: rgba(179, 55, 47, 0.08); color: #b3372f; border: 1px solid rgba(179,55,47,.3); }

/* playground */
.playground-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
@media (max-width: 980px) { .playground-grid { grid-template-columns: 1fr; } }

.playground-grid textarea { font-size: 13px; }

#pg-frame {
  width: 100%;
  height: 640px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

/* editor + live preview */
.admin-wrap.wide { max-width: 1680px; }

.editor-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.preview-pane {
  position: sticky;
  top: 74px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.preview-bar .spacer { margin-left: auto; }
.preview-bar label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.preview-bar .btn[aria-pressed="true"] { background: var(--accent-soft); }
.preview-status { text-transform: none; letter-spacing: 0; color: var(--accent); }

.preview-viewport {
  position: relative;
  height: calc(100vh - 140px);
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--band-bg);
}

#pv-frame {
  position: absolute;
  top: 0;
  left: 0;
  border: 0;
  background: #fff;
  transform-origin: 0 0;
}
.preview-viewport.phone #pv-frame { box-shadow: 0 0 0 1px var(--border), 0 6px 24px rgba(28, 28, 40, 0.1); }

@media (max-width: 1100px) {
  .editor-split { grid-template-columns: 1fr; }
  .preview-pane { position: static; }
  .preview-viewport { height: 80vh; }
}

/* login */
.login-box {
  max-width: 360px;
  margin: 14vh auto 0;
  padding: 30px 30px 26px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.login-box h1 { margin: 0 0 18px; font-size: 19px; font-family: var(--mono); }

/* 404 */
.notfound {
  text-align: center;
  padding: 12vh 20px 16vh;
  font-family: var(--mono);
}
.notfound h1 { font-size: 56px; margin: 0 0 8px; color: var(--accent); }
