:root {
  --paper: #f2ecde;
  --paper-2: #e8e0cc;
  --ink: #2a2420;
  --ink-2: #5b5146;
  --line: #cfc3a8;
  --red: #b8402e;
  --red-2: #9a3222;
  --sel: #b8402e;
  --shadow: 0 6px 24px rgba(40, 30, 20, .18), 0 1px 3px rgba(40, 30, 20, .12);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #d9d0bb; color: var(--ink); font: 14px/1.4 var(--sans); }

.bar {
  position: fixed; inset: 0 0 auto 0; height: 56px; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 16px; background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px); border-bottom: 1px solid var(--line);
}
.title { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.t1 { font: 600 19px/1.1 var(--serif); letter-spacing: .06em; text-transform: uppercase; }
.t2 { font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.tools { display: flex; align-items: center; gap: 6px; }
#zoom-readout { min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 13px; }

button {
  white-space: nowrap;
  font: inherit; color: var(--ink); background: #fbf8f1; border: 1px solid var(--line);
  border-radius: 6px; height: 34px; padding: 0 12px; cursor: pointer;
}
button:hover { background: #fff; border-color: #b9aa88; }
button:focus-visible, select:focus-visible { outline: 2px solid var(--red); outline-offset: 1px; }
.tools > button:first-child, #btn-zoom-in { width: 34px; padding: 0; font-size: 18px; }
button.toggle.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
button.primary { background: var(--red); color: #fff; border-color: var(--red-2); }
button.primary:hover { background: var(--red-2); }
button.primary.on { background: var(--red-2); color: #fff; box-shadow: inset 0 2px 4px rgba(0,0,0,.25); }
button.icon { width: 30px; height: 30px; padding: 0; font-size: 20px; line-height: 1; border: none; background: none; }
button.wide { width: 100%; height: 40px; font-weight: 600; }
button:disabled { opacity: .55; cursor: progress; }

#viewer { position: fixed; inset: 56px 0 0 0; background: #d9d0bb; }
#viewer.selecting .openseadragon-canvas { cursor: crosshair; }

/* selection frame (OpenSeadragon overlay) */
.sel-frame {
  border: 2px solid var(--sel); background: rgba(184, 64, 46, .06);
  box-shadow: 0 0 0 9999px rgba(30, 22, 15, .28); cursor: move;
}
.sel-frame .h { position: absolute; width: 12px; height: 12px; background: #fff; border: 2px solid var(--sel); border-radius: 2px; }
.sel-frame .h[data-h="nw"] { left: -7px; top: -7px; cursor: nwse-resize; }
.sel-frame .h[data-h="ne"] { right: -7px; top: -7px; cursor: nesw-resize; }
.sel-frame .h[data-h="sw"] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.sel-frame .h[data-h="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.sel-frame .h[data-h="n"] { left: calc(50% - 6px); top: -7px; cursor: ns-resize; }
.sel-frame .h[data-h="s"] { left: calc(50% - 6px); bottom: -7px; cursor: ns-resize; }
.sel-frame .h[data-h="w"] { top: calc(50% - 6px); left: -7px; cursor: ew-resize; }
.sel-frame .h[data-h="e"] { top: calc(50% - 6px); right: -7px; cursor: ew-resize; }
.sel-frame.fixed .h { display: none; }
.sel-label {
  position: absolute; left: -2px; top: -26px; white-space: nowrap; pointer-events: none;
  background: var(--sel); color: #fff; font: 600 11px/1 var(--sans); padding: 5px 7px; border-radius: 4px 4px 0 0;
}

.sheet-box { border: 1.5px dashed rgba(42, 36, 32, .55); pointer-events: none; }
.sheet-box span {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font: 700 22px/1 var(--serif); color: var(--ink); background: rgba(242, 236, 222, .85);
  padding: 6px 12px; border-radius: 4px; letter-spacing: .05em;
}

#panel {
  position: fixed; top: 68px; right: 12px; width: 300px; z-index: 15;
  max-height: calc(100% - 80px); overflow: auto;
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 14px 16px 16px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.panel-head h2 { margin: 0; font: 600 17px/1.2 var(--serif); }
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
select { font: inherit; height: 34px; border: 1px solid var(--line); border-radius: 6px; background: #fbf8f1; padding: 0 8px; color: var(--ink); }
.seg { display: flex; }
.seg button { flex: 1; border-radius: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; border-left: none; }
.seg button.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.field.disabled { opacity: .45; pointer-events: none; }

.stats { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 14px 0 6px; padding: 10px 12px; background: #fbf8f1; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.stats dt { color: var(--ink-2); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.note { min-height: 0; margin: 6px 0 12px; font-size: 12.5px; color: var(--ink-2); }
.note.warn { color: var(--red-2); }
.hint { margin: 12px 0 0; font-size: 12px; color: var(--ink-2); }
kbd { font: 11px var(--sans); padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: #fff; }

#progress { margin-top: 10px; font-size: 12px; color: var(--ink-2); }
.bar-track { height: 6px; border-radius: 3px; background: var(--paper-2); overflow: hidden; margin-bottom: 4px; }
.bar-fill { height: 100%; width: 0; background: var(--red); transition: width .15s; }

.help {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 15;
  background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: 20px; font-size: 13px;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s;
}
.help kbd { background: transparent; color: var(--paper); border-color: #776a5c; }
.help.show { opacity: 1; }

/* OpenSeadragon navigator */
.navigator { border: 1px solid var(--line) !important; border-radius: 6px; box-shadow: var(--shadow); background: var(--paper) !important; }
.displayregion { border-color: var(--red) !important; }

@media (max-width: 900px) {
  .t1 { font-size: 15px; white-space: nowrap; }
  .t2 { display: none; }
  .tools button { padding: 0 9px; }
}
@media (max-width: 760px) {
  .t2, #btn-home, #btn-sheets, #zoom-readout { display: none; }
  .t1 { font-size: 15px; }
  #panel { left: 8px; right: 8px; width: auto; top: auto; bottom: 8px; max-height: 60%; }
}
