:root {
  color-scheme: light;
  --paper: #f6f4ef;
  --panel: #ffffff;
  --ink: #201d18;
  --muted: #6e6658;
  --line: #d6cbb9;
  --accent: #8b5e24;
  --accent-2: #2f6f88;
}

* {
  box-sizing: border-box;
}

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

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

.appbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 12px 18px;
  background: rgba(246, 244, 239, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.title-block {
  min-width: 0;
}

.project-mark {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  overflow: hidden;
  font-size: 20px;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 44px);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  background: #eee7dc;
}

.segmented-button,
.tool-button {
  height: 36px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.segmented-button.is-active,
.tool-button:hover {
  background: var(--ink);
  color: #fff;
}

.tool-button {
  min-width: 42px;
  border-color: var(--line);
  background: var(--panel);
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}

.reading-panel {
  padding: 22px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.panel-kicker {
  margin-bottom: 8px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.reading-panel h2 {
  margin-bottom: 12px;
  font-size: 24px;
  line-height: 1.12;
}

.reading-panel p {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

dl {
  display: grid;
  gap: 14px;
  margin: 24px 0 0;
}

dt {
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.hash {
  overflow-wrap: anywhere;
  font-family: Consolas, "Liberation Mono", monospace;
  font-size: 11px;
}

.viewer {
  min-width: 0;
}

.viewer-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 14px;
  background: #ebe4d9;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.viewer-status strong {
  color: var(--ink);
}

.diagram-stage {
  overflow: auto;
  height: calc(100vh - 116px);
  background: #f8f3e8;
}

.diagram-stage img {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
  user-select: none;
}

@media (max-width: 900px) {
  .appbar {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    white-space: normal;
  }

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

  .reading-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .diagram-stage {
    height: 72vh;
  }
}

@media (max-width: 520px) {
  .controls {
    flex-wrap: wrap;
  }

  .reading-panel {
    padding: 18px;
  }
}
