/* === V2 browser-native layout === */

/* hide the macOS window chrome completely in v2 — body gets .v2 */
body.v2 { background: var(--bg); }

.app-v2 { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ============ Top Bar ============ */
.topbar {
  height: 52px; flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 14px 0 18px;
  background: var(--paper);
  border-bottom: 1px solid #DCD7CD;
  position: relative;
  z-index: 10;
}

.tb-left, .tb-right { display: flex; align-items: center; gap: 4px; }
.tb-right { justify-content: flex-end; }

.tb-brand {
  display: flex; align-items: stretch; gap: 0;
  border-right: 1px solid #E3DED3;
  margin: 0 14px 0 -18px;
  align-self: stretch;
}
.tb-brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  background: #111; color: #fff;
  border-radius: 6px;
  font-weight: 800; font-size: 13px; letter-spacing: -0.04em;
}
.tb-brand-logo {
  height: 52px; width: 52px; display: block;
  background: #fff;
  padding: 10px;
  box-sizing: border-box;
  object-fit: contain;
}
.tb-brand-name {
  display: inline-flex; align-items: center;
  padding: 0 14px;
  font-weight: 600; font-size: 14px; letter-spacing: -0.01em;
}

.tb-nav { display: flex; align-items: center; gap: 2px; }
.tb-nav-group { position: relative; }
.tb-menu-trigger {
  height: 32px; padding: 0 10px;
  background: transparent; border: none;
  color: var(--ink-2); font-size: 13px; font-weight: 500;
  border-radius: 6px;
  letter-spacing: -0.005em;
}
.tb-menu-trigger:hover { background: var(--hover); color: var(--ink); }
.tb-menu-trigger.active { background: var(--ink); color: #fff; }

.tb-menu {
  position: absolute; top: calc(100% + 4px); left: 0;
  min-width: 240px;
  background: var(--paper);
  border: 1px solid #DCD7CD;
  border-radius: 10px;
  box-shadow: var(--shadow-2);
  padding: 6px;
  z-index: 50;
  animation: menu-in 0.12s ease-out;
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.tb-menu-item {
  width: 100%; height: 32px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 10px 0 12px;
  background: transparent; border: none;
  color: var(--ink); font-size: 13px;
  border-radius: 6px; text-align: left;
}
.tb-menu-item:hover:not(:disabled) { background: var(--ink); color: #fff; }
.tb-menu-item:hover:not(:disabled) .tb-menu-kbd { color: rgba(255,255,255,0.7); }
.tb-menu-item:disabled { color: var(--ink-3); cursor: not-allowed; opacity: 0.6; }
.tb-menu-kbd { font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); letter-spacing: 0.02em; }
.tb-menu-check { font-size: 12px; color: var(--ink-3); min-width: 12px; }
.tb-menu-item:hover .tb-menu-check { color: rgba(255,255,255,0.8); }
.tb-menu-sep { height: 1px; background: #E3DED3; margin: 4px 4px; }

.tb-center {
  display: flex; align-items: center; gap: 14px;
  justify-content: center;
}
.tb-name {
  display: inline-flex; align-items: center;
  height: 32px; padding: 0 10px;
  background: transparent; border: 1px solid transparent;
  border-radius: 7px;
  font-size: 13.5px; font-weight: 500; color: var(--ink);
  max-width: 340px;
}
.tb-name:hover { background: var(--hover); }
.tb-name-text { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-name-ext { color: var(--ink-3); margin-left: 2px; }
.tb-name-input {
  height: 32px; padding: 0 10px;
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 7px;
  font-size: 13.5px; font-weight: 500; color: var(--ink);
  outline: none;
  min-width: 220px;
}
.tb-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 10.5px;
  color: var(--ink-3); letter-spacing: 0.08em; text-transform: uppercase;
}
.tb-status-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 2px rgba(133,202,89,0.18);
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot { 0%,100%{opacity:.8} 50%{opacity:.4} }

.tb-iconbtn {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 7px; border: none; background: transparent;
  color: var(--ink-2);
}
.tb-iconbtn:hover { background: var(--hover); color: var(--ink); }

.tb-btn-primary {
  height: 34px; padding: 0 14px;
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--ink); color: #fff; border: none;
  border-radius: 7px;
  font-size: 13px; font-weight: 600; letter-spacing: -0.005em;
  margin-left: 4px;
}
.tb-btn-primary:hover { background: #000; }

.tb-lang {
  display: inline-flex; align-items: center;
  height: 28px; padding: 2px;
  background: var(--surf-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  margin-right: 4px;
}
.tb-lang-btn {
  height: 22px; min-width: 28px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 5px;
  color: var(--ink-2); font: 600 10.5px/1 var(--ui);
  letter-spacing: 0.04em; cursor: pointer;
}
.tb-lang-btn:hover { color: var(--ink); }
.tb-lang-btn.active { background: var(--ink); color: #fff; box-shadow: 0 1px 0 rgba(0,0,0,0.04); }

.splash-lang {
  border: 1px solid var(--line, #E5E1D8);
  margin: 14px auto 22px;
}
.splash-lang .tb-lang-btn { color: var(--ink-2, #6A645A); }
.splash-lang .tb-lang-btn:hover { color: var(--ink, #141414); }
.splash-lang .tb-lang-btn.active { background: var(--ink, #141414); color: #fff; }

/* ============ Side Tools ============ */
.sidetools {
  position: absolute;
  top: 52px; left: 0; bottom: 0;
  width: 56px;
  background: var(--paper);
  border-right: 1px solid #DCD7CD;
  display: flex; flex-direction: column; align-items: center;
  padding: 10px 0;
  gap: 4px;
  z-index: 5;
  overflow-y: auto;
  scrollbar-width: none;
}
.sidetools::-webkit-scrollbar { display: none; }
.st-group { display: flex; flex-direction: column; gap: 3px; }
.st-sep { width: 28px; height: 1px; background: #E3DED3; margin: 6px 0; }
.st-btn {
  position: relative;
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink-2);
  transition: background .1s, color .1s;
}
.st-btn:hover { background: var(--hover); color: var(--ink); }
.st-btn.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.st-btn svg { width: 20px; height: 20px; }

/* side-tool tooltip (appears to the right) */
.st-tip {
  position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  display: inline-flex; align-items: center; gap: 8px;
  background: #111; color: #fff;
  padding: 6px 8px 6px 10px;
  border-radius: 6px;
  font-size: 11px; white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease .35s;
  box-shadow: 0 8px 24px -10px rgba(0,0,0,.4);
  z-index: 20;
}
.st-tip::before {
  content: ''; position: absolute; right: 100%; top: 50%; transform: translateY(-50%);
  border: 4px solid transparent; border-right-color: #111;
}
.st-tip-name { font-weight: 600; }
.st-tip-kbd {
  font-family: var(--font-mono); font-size: 10px; color: rgba(255,255,255,0.55);
  padding: 1px 4px; border: 1px solid rgba(255,255,255,0.18); border-radius: 3px;
}
.st-btn:hover .st-tip { opacity: 1; }

/* ============ Editor layout V2 ============ */
.editor-v2 {
  position: absolute; inset: 0;
  display: grid;
  grid-template-rows: 52px 1fr;
  grid-template-columns: 56px 1fr 300px;
  grid-template-areas:
    "top top top"
    "tools canvas panel";
  background: var(--bg);
}
.editor-v2 > .topbar { grid-area: top; }
.editor-v2 > .sidetools { position: static; grid-area: tools; top: auto; left: auto; bottom: auto; width: auto; }
.editor-v2 > .canvas-wrap-v2 { grid-area: canvas; }
.editor-v2 > .panel.v2 { grid-area: panel; }

.canvas-wrap-v2 {
  position: relative;
  min-width: 0; min-height: 0;
  padding: 20px 20px 0;
  display: flex; flex-direction: column;
}
.canvas-wrap-v2 > .stage-scroll {
  flex: 1 1 auto; min-height: 0; min-width: 0;
  width: 100%; max-width: 100%;
  display: flex; align-items: center; justify-content: center;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.canvas-wrap-v2 > .stage-scroll::-webkit-scrollbar { width: 0; height: 0; }
.canvas-wrap-v2 > .stage-scroll > .stage {
  flex: 0 0 auto; margin: auto;
}
.stage.v2 {
  border-radius: 10px;
  border: 1px solid #DCD7CD;
  box-shadow: 0 2px 0 rgba(0,0,0,.02), 0 24px 48px -36px rgba(0,0,0,.22);
  height: 100%;
  width: auto;
  aspect-ratio: var(--stage-ar, auto);
}

.canvas-footer {
  flex-shrink: 0;
  height: 40px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2px;
  color: var(--ink-3);
  font-size: 12px;
}
.cf-left, .cf-right { display: flex; align-items: center; gap: 8px; }
.cf-chip {
  display: inline-flex; align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid #E3DED3;
  font-family: var(--font-mono); font-size: 10.5px;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ink-2);
}
.cf-sep { color: var(--line-soft); }
.cf-muted { color: var(--ink-3); }
.cf-btn {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent;
  border-radius: 6px; color: var(--ink-2); font-size: 15px;
}
.cf-btn:hover { background: var(--hover); color: var(--ink); }
.cf-zoom {
  font-family: var(--font-mono); font-size: 11px;
  min-width: 46px; text-align: center;
}

/* ============ Panel in V2 ============ */
.panel.v2 {
  background: var(--paper);
  border-left: 1px solid #DCD7CD;
  border-right: none;
  display: flex; flex-direction: column;
  overflow-y: auto;
}

/* the inner Panel component paints its own sections; just tune spacing */
.panel.v2 .panel-head { background: var(--paper); border-bottom: 1px solid #E3DED3; }
.panel.v2 .panel-section { border-bottom: 1px solid #E3DED3; }

/* ============ Bottom sheet handle (mobile only) ============ */
.panel-handle {
  display: none;
}

/* ============ Responsive ============ */
@media (max-width: 1200px) {
  .editor-v2 { grid-template-columns: 56px 1fr 260px; }
  .tb-brand-name { display: none; }
}
/* Landscape phone / small tablet: keep 3-column but shrink panel */
@media (max-width: 900px) {
  .tb-nav { display: none; }
  .editor-v2 { grid-template-columns: 48px 1fr 200px; }
}
/* Portrait phone / very narrow: bottom sheet */
@media (max-width: 640px) {
  .editor-v2 {
    grid-template-columns: 48px 1fr;
    grid-template-areas: "top top" "tools canvas";
  }

  /* Panel becomes a bottom sheet */
  .editor-v2 > .panel.v2 {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: 62vh;
    border-left: none;
    border-top: 1px solid #DCD7CD;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.14);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32,0.72,0,1);
    z-index: 30;
    overflow-y: auto;
  }
  .editor-v2 > .panel.v2.sheet-open {
    transform: translateY(0);
  }

  /* Handle bar */
  .panel-handle {
    display: flex;
    align-items: center; justify-content: center;
    width: 100%; height: 36px;
    background: transparent; border: none;
    flex-shrink: 0;
    cursor: pointer;
  }
  .panel-handle::before {
    content: '';
    width: 36px; height: 4px;
    background: #C9C4BB;
    border-radius: 2px;
  }

  /* Dimmed backdrop when sheet open */
  .panel-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.25);
    z-index: 29;
  }
}


/* splash/picker — keep existing, but drop window-chrome offset */
body.v2 .splash, body.v2 .picker { inset: 0; }
