*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:               #f0ede8;
  --panel:            #faf8f6;
  --border:           #d6d1c9;
  --text:             #2c2926;
  --text-muted:       #7a7268;
  --accent:           #4a6b5d;
  --accent-hover:     #3a5549;
  --accent-light:     #e8f0ec;
  --sidebar-bg:       #e8e4dd;
  --btn-sec-bg:       #d6d1c9;
  --shadow:           0 2px 14px rgba(0, 0, 0, 0.08);
}

html, body {
  height: 100%;
  font-size: 14px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

.sidebar {
  width: 460px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  position: relative;
  padding: 22px 22px 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.github-link {
  position: absolute;
  top: 22px;
  right: 22px;
  color: var(--text-muted);
}

.github-link:hover {
  color: var(--text);
}

/* ── Controls ────────────────────────────────────────────────────────────── */

.controls {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.control-row:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.label-hint {
  font-size: 10px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  opacity: 0.7;
}

select {
  width: 100%;
  padding: 8px 32px 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-size: 13.5px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%237a7268' d='M5 7L0 2h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  cursor: pointer;
  transition: border-color 0.15s;
}

select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  padding: 8px 15px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--btn-sec-bg);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

/* ── Input ───────────────────────────────────────────────────────────────── */

.source-toggle {
  display: flex;
  flex-shrink: 0;
  margin: 16px 22px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.source-toggle label {
  flex: 1;
  justify-content: center;
  padding: 7px;
  background: var(--panel);
  cursor: pointer;
}

.source-toggle label:has(:checked) {
  background: var(--accent);
  color: #fff;
}

.source-toggle label:has(:focus-visible) {
  outline: 2px solid var(--accent-hover);
  outline-offset: -2px;
}

.source-toggle input {
  position: absolute;
  opacity: 0;
}

.input-section:not([hidden]) {
  display: flex;
  flex-direction: column;
  padding: 16px 22px;
  gap: 7px;
  border-bottom: 1px solid var(--border);
}

.input-section label {
  flex-direction: column;
  gap: 2px;
}

textarea {
  height: 110px;
  resize: vertical;
  white-space: pre;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--text);
  background: var(--panel);
  outline: none;
  transition: border-color 0.15s;
}

textarea.links {
  height: 70px;
}

.sheet-status:empty {
  display: none;
}

.sheet-status {
  font-size: 12px;
  color: #6C1600;
  overflow-wrap: anywhere;
}

.sheet-updated {
  font-size: 12px;
  color: var(--text-muted);
}

.link-button {
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.link-button:disabled {
  color: var(--text-muted);
  text-decoration: none;
  cursor: default;
}

textarea:focus {
  border-color: var(--accent);
}

textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.65;
}

/* ── Format guide ────────────────────────────────────────────────────────── */

.format-guide {
  padding: 16px 22px 22px;
  font-size: 12px;
  color: var(--text-muted);
}

.format-guide summary {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  cursor: pointer;
}

.format-guide details + details {
  margin-top: 14px;
}

.format-guide p {
  margin-bottom: 8px;
}

.format-guide .prompt {
  max-height: 220px;
  overflow: auto;
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-size: 11px;
  white-space: pre-wrap;
}

.format-guide a {
  color: var(--accent);
}

/* ── Preview area ────────────────────────────────────────────────────────── */

.preview-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}

.preview-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.preview-size-description {
  max-width: 760px;
  flex: none;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.3;
}

.preview-canvas {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.preview-notices {
  display: grid;
  gap: 6px;
  align-content: start;
  height: 72px;
  width: min(100%, 768px);
  padding: 10px 24px;
  align-self: center;
  flex: none;
  overflow: auto;
}

.preview-notices[hidden] {
  display: grid;
  visibility: hidden;
}

.preview-notice {
  padding: 8px 12px;
  border: 1px solid;
  border-radius: 6px;
}

.preview-notice-warning {
  color: #654b00;
  border-color: #e5cf83;
  background: #fff5cf;
}

.preview-notice-error {
  color: #7d2924;
  border-color: #e0aaa5;
  background: #fce8e6;
}

/* ── Menus ───────────────────────────────────────────────────────────────── */

.menu {
  inset: auto;
  top: 72px;
  right: 24px;
  width: min(340px, calc(100vw - 32px));
  margin: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.menu:popover-open {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.menu-option {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.menu-option[hidden] {
  display: none;
}

.menu-option:hover,
.menu-option:focus-visible {
  border-color: var(--accent);
  background: var(--accent-light);
}

.menu-option-name {
  font-size: 13px;
  font-weight: 600;
}

.menu-option-text {
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-muted);
}

.preview-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.svg-container {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 28px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
}

.svg-container svg {
  width: auto;
  height: auto;
  flex: none;
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.12));
  display: block;
}

.svg-container > svg,
.svg-container > .preview-size-description {
  /* Four 64 mm faces keep the left edge fixed when a guide gains a face. */
  margin-left: max(0px, calc((100% - 256mm) / 2));
}

.svg-container > .preview-size-description {
  margin-top: 12px;
}

/* ── Example ─────────────────────────────────────────────────────────────── */

.example {
  max-width: 760px;
  width: 100%;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  color: var(--text-muted);
  font-size: 13px;
}

.example h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.svg-container .example-card svg {
  height: auto;
}

.example-notes {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.example-notes b {
  color: var(--text);
  font-weight: 600;
}

/* ── Empty state ─────────────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  margin-inline: auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  user-select: none;
}

.empty-icon {
  font-size: 36px;
  opacity: 0.25;
  line-height: 1;
  margin-bottom: 4px;
}

.empty-state p {
  font-size: 14px;
}

.mobile-scroll-hint,
.mobile-location {
  display: none;
}

/* ── Narrow screens ──────────────────────────────────────────────────────── */

@media (max-width: 800px) {
  .app {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    width: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }

  .preview-area {
    flex: none;
    overflow: visible;
  }

  .preview-header {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 16px 22px;
  }

  .preview-title {
    overflow-wrap: anywhere;
  }

  .preview-size-description {
    max-width: none;
    font-size: 12px;
    line-height: 1.5;
  }

  .preview-actions {
    flex-wrap: nowrap;
  }

  .preview-actions .btn {
    flex: 1;
    min-height: 44px;
  }

  .preview-notices {
    height: auto;
    padding: 12px 16px 0;
  }

  .preview-notices[hidden] {
    display: none;
  }

  .svg-container {
    flex: none;
    padding: 20px 16px;
  }

  .example {
    min-width: 0;
  }

  .example-card {
    overflow-x: auto;
  }

  .mobile-scroll-hint,
  .mobile-location {
    display: inline;
  }

  .desktop-location {
    display: none;
  }

  .format-guide {
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border);
    overflow-wrap: anywhere;
  }

  .format-guide .btn {
    min-height: 44px;
  }

  .menu {
    position: fixed;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
  }
}
