* {
    box-sizing: border-box;
}

:root {
    --bg: #f7f7f5;
    --card: #fff;
    --ink: #111;
    --muted: #646464;
    --line: #d9d9d4;
    --soft-line: #ececea;
    --panel-bg: #fafaf8;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--bg);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

h1, h2, p {
    margin: 0;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    width: min(1220px, calc(100% - 48px));
    margin: 0 auto;
    padding: 24px 0 18px;
}

.top-bar h1 {
    font-size: 30px;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.01em;
}

.home-link {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid #d8d2c0;
  border-radius: 50%;
  color: #2f5d4f;
  background: #faf8f1;
  box-shadow: 0 1px 2px rgba(28,43,37,.05), 0 12px 32px -16px rgba(28,43,37,.28);
  text-decoration: none;
  transition: transform .2s ease, border-color .2s ease;
}
.home-link:hover,
.home-link:focus-visible {
  border-color: #8a9a5b;
  color: #3f7060;
  transform: translateY(-2px);
  outline: none;
}
.home-link svg { display: block; }

.preset-group {
    display: flex;
    align-items: center;
}

.segmented-control {
    display: inline-flex;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 3px;
    gap: 3px;
}

.mode-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.15;
    padding: 7px 16px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.mode-button small {
    font-size: 0.68rem;
    font-weight: 500;
    opacity: 0.8;
}

.mode-button.active {
    background: var(--ink);
    color: #fff;
}

.layout {
    width: min(1220px, calc(100% - 48px));
    margin: 0 auto;
    padding: 0 0 8px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.stage-panel {
    padding: 14px;
}

.stage {
    width: 100%;
    overflow-x: auto;
}

canvas#caliper {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    outline: none;
    touch-action: none;
}

.readout-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 16px 22px;
    flex-wrap: wrap;
}

.readout {
    display: flex;
    align-items: stretch;
    gap: 12px;
    flex-wrap: wrap;
}

.read-card {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 130px;
    padding: 10px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-bg);
}

.read-label {
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.read-card strong {
    font-size: 1.18rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.read-op {
    display: flex;
    align-items: center;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--muted);
}

.read-card.total {
    background: var(--ink);
    border-color: var(--ink);
}

.read-card.total .read-label {
    color: rgba(255, 255, 255, 0.7);
}

.read-card.total strong {
    color: #ffffff;
    font-size: 1.6rem;
}

.actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.ghost-button {
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    padding: 9px 20px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.ghost-button:hover {
    background: var(--soft-line);
}

.reveal-button {
    border: 1px solid var(--ink);
    background: var(--ink);
    color: #ffffff;
    font: inherit;
    font-weight: 600;
    padding: 9px 20px;
    border-radius: 6px;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.reveal-button:hover {
    opacity: 0.85;
}

.reveal-button.hidden-state {
    background: #ffffff;
    color: var(--ink);
    border-color: var(--line);
}

.read-card strong.masked {
    color: var(--muted);
    letter-spacing: 0.12em;
}

footer {
    width: min(1220px, calc(100% - 48px));
    margin: 0 auto;
    padding: 6px 0 28px;
}

footer p {
    font-size: 0.85rem;
    color: var(--muted);
    text-align: center;
}
