:root {
  --sage-green: #486C2F;
  --sage-dark-green: #2d451f;
  --sage-paper: #f5f3ec;
  --sage-ink: #20251e;
  --sage-line: #d7d7ce;
  --nav-height: 92px;
  --control-width: 166px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--sage-paper);
  color: var(--sage-ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.sage-nav {
  position: relative;
  z-index: 500;
  height: var(--nav-height);
  display: grid;
  place-items: center;
  background: var(--sage-green);
}

.sage-title {
  color: #f8f5eb;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(2rem, 3vw, 3rem);
  font-weight: 400;
  letter-spacing: 0.08em;
  line-height: 1;
  text-decoration: none;
}

.page-surface {
  position: relative;
  min-height: calc(100vh - var(--nav-height));
  isolation: isolate;
  overflow: clip;
}

.background-layer {
  position: absolute;
  z-index: 0;
  top: 0;
  left: 0;
  width: 100%;
  overflow: hidden;
  pointer-events: none;
}

.background-tile {
  width: 100%;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  transform-origin: center;
}

.background-tile.is-flipped {
  transform: scaleY(-1);
}

.main-layout {
  position: relative;
  z-index: 10;
  width: min(1180px, calc(100% - 32px));
  min-height: calc(100vh - var(--nav-height));
  margin: 0 auto;
  padding: 26px calc(var(--control-width) + 54px) 90px 0;
}

.content-stack {
  position: relative;
  display: grid;
  width: min(920px, 100%);
  min-height: calc(100vh - var(--nav-height) - 52px);
  margin: 0 auto;
}

.content-layer {
  grid-area: 1 / 1;
  min-width: 0;
}

.words-layer {
  z-index: 30;
  width: 64%;
  justify-self: start;
  padding: 18px;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(1.05rem, 1.25vw, 1.3rem);
  line-height: 1.55;
}

.word-entry {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0 0 1.5em;
}

.images-layer {
  z-index: 20;
  width: 48%;
  justify-self: end;
  padding: 30px 16px 18px;
}

.image-entry {
  margin: 0 0 30px;
}

.image-entry img {
  display: block;
  width: 100%;
  height: auto;
}

.bazil-layer {
  position: relative;
  z-index: 40;
  width: 100%;
  pointer-events: none;
}

.bazil-item {
  position: absolute;
  display: block;
  width: auto;
  height: auto;
  max-width: min(320px, 42vw);
  opacity: 0.72;
  pointer-events: none;
  user-select: none;
}

.layer-is-hidden {
  display: none !important;
}

.control-panel {
  position: fixed;
  z-index: 300;
  top: calc(var(--nav-height) + 26px);
  right: max(16px, calc((100vw - 1180px) / 2));
  width: var(--control-width);
  display: grid;
  gap: 10px;
  padding: 14px;
  background: var(--sage-dark-green);
}

.control-button {
  min-height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 0;
  background: #f6f4eb;
  color: #1e2d17;
  text-align: left;
  padding: 0 14px;
}

.control-button:hover,
.control-button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.control-button.layer-toggle:not(.is-on) {
  opacity: 0.5;
  text-decoration: line-through;
}

#frameButton[aria-pressed='true'] {
  background: #1f2f17;
  color: #fff;
}

.site-status {
  position: fixed;
  z-index: 320;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  margin: 0;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.92);
  color: #602424;
  font-size: 0.85rem;
}

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

/* Temporary frame guide. Off by default; site.js adds .show-frame to body. */
.show-frame .frame-nav {
  outline: 3px solid #aa00ff;
  outline-offset: -3px;
}

.show-frame .frame-background {
  outline: 3px solid #7a160e;
  outline-offset: -3px;
}

.show-frame .frame-bazil {
  outline: 3px solid #3c00ff;
  outline-offset: -3px;
}

.show-frame .frame-words {
  outline: 3px solid #008fe8;
  outline-offset: -3px;
}

.show-frame .frame-images {
  outline: 3px solid #ff1010;
  outline-offset: -3px;
}

.show-frame .frame-controls {
  outline: 3px solid #007b22;
  outline-offset: -3px;
}

/* Editor */
.editor-main {
  min-height: calc(100vh - var(--nav-height));
  padding: 44px 20px 80px;
}

.editor-shell {
  width: min(880px, 100%);
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--sage-line);
}

.editor-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--sage-line);
}

.tab-button {
  min-height: 54px;
  border: 0;
  border-right: 1px solid var(--sage-line);
  border-radius: 0;
  background: #ecebe5;
  color: var(--sage-ink);
}

.tab-button:last-child {
  border-right: 0;
}

.tab-button.is-active {
  background: var(--sage-green);
  color: #fff;
}

.tab-button:focus-visible,
.submit-button:focus-visible,
.drop-zone:focus-within {
  outline: 3px solid #1f4a0d;
  outline-offset: 2px;
}

.tab-panel {
  padding: 30px;
}

.editor-form {
  display: grid;
  gap: 18px;
}

.editor-form > label:not(.drop-zone),
.coordinate-grid label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

textarea,
input[type='number'] {
  width: 100%;
  border: 1px solid #9a9d95;
  border-radius: 0;
  background: #fff;
  color: #111;
  padding: 12px;
}

textarea {
  min-height: 280px;
  resize: vertical;
  line-height: 1.5;
}

.drop-zone {
  min-height: 260px;
  display: grid;
  place-content: center;
  gap: 8px;
  border: 2px dashed #829078;
  background: #f4f6f1;
  text-align: center;
  cursor: pointer;
}

.drop-zone.is-dragging {
  border-style: solid;
  background: #e8eee3;
}

.drop-zone-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.45rem;
}

.drop-zone-copy,
.form-note {
  color: #5a6255;
  font-size: 0.92rem;
}

.upload-preview {
  min-height: 90px;
  border: 1px solid var(--sage-line);
  padding: 12px;
  background: #fff;
}

.upload-preview img {
  display: block;
  max-width: 100%;
  max-height: 280px;
  margin: 0 auto;
}

.upload-preview-name {
  margin: 8px 0 0;
  text-align: center;
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

.coordinate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.number-field {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border: 1px solid #9a9d95;
  background: #fff;
}

.number-field input {
  border: 0;
}

.number-field span {
  padding-right: 12px;
  color: #62665f;
}

.submit-button {
  justify-self: start;
  min-width: 150px;
  min-height: 48px;
  border: 0;
  border-radius: 0;
  background: var(--sage-green);
  color: #fff;
  padding: 0 20px;
}

.submit-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.editor-status {
  min-height: 1.4em;
  margin: 0 30px 30px;
  color: #30422a;
}

.editor-status.is-error {
  color: #8b1d1d;
}

code {
  font-family: Consolas, 'Courier New', monospace;
}

@media (max-width: 780px) {
  :root {
    --nav-height: 76px;
  }

  .main-layout {
    width: 100%;
    padding: 18px 14px 128px;
  }

  .content-stack {
    width: 100%;
  }

  .words-layer {
    width: 72%;
    padding: 10px;
  }

  .images-layer {
    width: 56%;
    padding: 24px 8px 10px;
  }

  .control-panel {
    top: auto;
    right: 10px;
    bottom: 10px;
    left: 10px;
    width: auto;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
  }

  .control-button {
    min-height: 42px;
    padding: 0 8px;
    text-align: center;
    font-size: 0.86rem;
  }

  .site-status {
    bottom: 118px;
  }

  .editor-main {
    padding: 20px 10px 48px;
  }

  .editor-tabs {
    grid-template-columns: repeat(2, 1fr);
  }

  .tab-button:nth-child(2) {
    border-right: 0;
  }

  .tab-button:nth-child(-n + 2) {
    border-bottom: 1px solid var(--sage-line);
  }

  .tab-panel {
    padding: 20px;
  }

  .coordinate-grid {
    grid-template-columns: 1fr;
  }
}
