:root {
  --bg: #ffffff;
  --ink: #47472c;
  --muted: #77745d;
  --panel: rgba(255, 255, 255, 0.94);
  --line: rgba(71, 71, 44, 0.22);
  --active: #47472c;
  --active-text: #ffffff;
  --blue: #fbad19;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(71, 71, 44, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body,
.app {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

.app {
  position: relative;
}

.background-mascot {
  position: fixed;
  right: 18px;
  bottom: 10px;
  z-index: 6;
  width: clamp(130px, 18vw, 230px);
  height: auto;
  pointer-events: none;
  user-select: none;
}

button,
input,
label {
  font: inherit;
}

.hidden {
  display: none !important;
}

.file-input {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.empty-state {
  position: relative;
  z-index: 2;
  display: grid;
  width: 100%;
  height: 100%;
  align-content: center;
  place-items: center;
  gap: 14px;
  padding: 24px;
  background: #ffffff;
}

.import-panel {
  display: grid;
  width: min(360px, 100%);
  justify-items: center;
  gap: 10px;
  padding: 28px 28px 32px;
  border: 2px solid rgba(251, 173, 25, 0.46);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: center;
}

.import-panel:hover,
.import-panel:focus-within {
  border-color: var(--blue);
}

.brand-logo {
  display: block;
  object-fit: contain;
  user-select: none;
}

.brand-logo.large {
  width: 118px;
  height: 118px;
  margin-bottom: 2px;
}

.toolbar-logo {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
}

.pdf-mark {
  display: grid;
  width: 64px;
  height: 76px;
  place-items: center;
  border: 2px solid var(--blue);
  border-radius: 5px;
  color: var(--ink);
  font-weight: 850;
}

.import-panel strong {
  font-size: 24px;
}

.import-panel span:last-child {
  color: var(--muted);
  font-size: 15px;
}

.restore-btn {
  min-width: 132px;
  height: 40px;
  padding: 0 18px;
  border: 1px solid var(--ink);
  border-radius: 7px;
  background: var(--ink);
  color: #ffffff;
  cursor: pointer;
  font-weight: 760;
}

.restore-btn:hover,
.restore-btn:focus-visible {
  outline: none;
  background: #5a5938;
}

.folder-home-btn {
  background: #ffffff;
  color: var(--ink);
}

.folder-home-btn:hover,
.folder-home-btn:focus-visible {
  border-color: var(--blue);
  background: rgba(251, 173, 25, 0.1);
}

.workspace {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  background: #ffffff;
}

.toolbar {
  position: fixed;
  z-index: 40;
  top: 12px;
  bottom: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  width: 72px;
  max-height: calc(100vh - 24px);
  padding: 8px;
  border: 1px solid rgba(71, 71, 44, 0.22);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(71, 71, 44, 0.16);
  backdrop-filter: blur(18px);
  overflow-x: hidden;
  overflow-y: auto;
}

.tool-btn {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  touch-action: manipulation;
  user-select: none;
}

.tool-btn:hover,
.tool-btn:focus-visible {
  border-color: var(--blue);
  background: rgba(251, 173, 25, 0.1);
  outline: none;
}

.tool-btn.active {
  border-color: var(--active);
  background: var(--active);
  color: var(--active-text);
}

.lock-btn {
  width: 54px;
  font-size: 11px;
  letter-spacing: 0;
}

.lock-btn.locked {
  border-color: var(--blue);
  background: var(--blue);
  color: var(--ink);
}

.save-btn {
  width: 58px;
  font-size: 11px;
  letter-spacing: 0;
}

.folder-btn {
  width: 68px;
  font-size: 10px;
  letter-spacing: 0;
}

.save-status {
  min-width: 54px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

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

.import-btn {
  font-size: 12px;
  letter-spacing: 0;
}

.danger {
  color: var(--danger);
}

.divider {
  width: 100%;
  height: 1px;
  flex: 0 0 auto;
  background: var(--line);
}

.color-input {
  width: 38px;
  height: 38px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  cursor: pointer;
}

.range-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.range-wrap input {
  width: 58px;
  accent-color: var(--ink);
}

.page-info,
.zoom-info {
  min-width: 58px;
  color: var(--ink);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.zoom-info {
  min-width: 44px;
}

.viewer {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: auto;
  padding: 32px 32px 32px 104px;
  background: #ffffff;
}

.page-wrap {
  position: relative;
  width: max-content;
  min-width: 1px;
  min-height: 1px;
  margin: 0 auto;
  border: 1px solid rgba(71, 71, 44, 0.16);
  box-shadow: 0 18px 45px rgba(71, 71, 44, 0.18);
}

.folder-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(71, 71, 44, 0.3);
}

.folder-panel {
  width: min(520px, 100%);
  max-height: min(620px, calc(100vh - 36px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(71, 71, 44, 0.26);
}

.folder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.folder-header strong {
  font-size: 18px;
}

.folder-close {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-size: 20px;
  font-weight: 850;
}

.folder-list {
  display: grid;
  gap: 8px;
  max-height: 480px;
  overflow: auto;
  padding: 12px;
}

.folder-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafc;
}

.folder-title {
  margin: 0 0 5px;
  color: var(--ink);
  font-weight: 800;
}

.folder-meta {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.folder-open {
  min-width: 66px;
  height: 36px;
  border: 1px solid var(--ink);
  border-radius: 7px;
  background: var(--ink);
  color: #ffffff;
  cursor: pointer;
  font-weight: 800;
}

.folder-empty {
  margin: 0;
  padding: 24px 16px;
  color: var(--muted);
  text-align: center;
}

.pdf-canvas {
  display: block;
  background: #ffffff;
}

.ink-canvas {
  position: absolute;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.ink-canvas.pen,
.ink-canvas.pencil {
  cursor: crosshair;
}

.ink-canvas.eraser {
  cursor: grab;
}

.ink-canvas.ruler {
  cursor: crosshair;
}

.ink-canvas.protractor {
  cursor: cell;
}

.ruler-tool {
  position: absolute;
  z-index: 12;
  width: 520px;
  max-width: calc(100vw - 48px);
  height: 74px;
  border: 1px solid rgba(71, 71, 44, 0.36);
  border-radius: 5px;
  background:
    repeating-linear-gradient(90deg, rgba(71, 71, 44, 0.5) 0 1px, transparent 1px 10px),
    #fbad19;
  box-shadow: 0 12px 26px rgba(71, 71, 44, 0.18);
  transform-origin: center center;
  pointer-events: none;
  touch-action: none;
}

.ruler-scale {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 49px, rgba(71, 71, 44, 0.65) 49px 51px);
}

.ruler-labels {
  position: absolute;
  inset: 34px 8px auto 8px;
  display: grid;
  grid-template-columns: repeat(10, 50px);
  align-items: start;
  color: rgba(71, 71, 44, 0.86);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

.ruler-labels span {
  transform: translateX(28px);
  white-space: nowrap;
}

.ruler-handle {
  position: absolute;
  z-index: 2;
  top: 50%;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(71, 71, 44, 0.44);
  border-radius: 50%;
  background: #ffffff;
  cursor: grab;
  pointer-events: auto;
  transform: translateY(-50%);
  touch-action: none;
}

.ruler-handle.move {
  left: 12px;
}

.ruler-handle.rotate {
  right: 12px;
}

.ruler-handle.move::before {
  content: "↕";
  font-weight: 900;
}

.ruler-handle.rotate::before {
  content: "↻";
  font-weight: 900;
}

.protractor-tool {
  position: absolute;
  z-index: 13;
  width: 300px;
  height: 160px;
  transform-origin: 50% 100%;
  pointer-events: none;
  touch-action: none;
}

.protractor-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 2px solid rgba(71, 71, 44, 0.72);
  border-bottom: 5px solid rgba(71, 71, 44, 0.88);
  border-radius: 300px 300px 0 0;
  background:
    radial-gradient(circle at 50% 100%, transparent 0 38px, rgba(255, 255, 255, 0.82) 39px 100%),
    repeating-conic-gradient(
      from 270deg at 50% 100%,
      rgba(71, 71, 44, 0.7) 0deg 0.7deg,
      transparent 0.7deg 5deg
    ),
    rgba(251, 173, 25, 0.34);
  box-shadow: 0 12px 26px rgba(71, 71, 44, 0.16);
}

.protractor-face::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #47472c;
  transform: translateX(-50%);
}

.angle-label {
  position: absolute;
  color: #47472c;
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

.angle-label.a0 {
  right: 10px;
  bottom: 14px;
}

.angle-label.a30 {
  right: 35px;
  top: 84px;
}

.angle-label.a60 {
  right: 82px;
  top: 38px;
}

.angle-label.a90 {
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
}

.angle-label.a120 {
  left: 82px;
  top: 38px;
}

.angle-label.a150 {
  left: 35px;
  top: 84px;
}

.angle-label.a180 {
  left: 10px;
  bottom: 14px;
}

.protractor-handle {
  position: absolute;
  z-index: 2;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(71, 71, 44, 0.44);
  border-radius: 50%;
  background: #ffffff;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
}

.protractor-handle.move {
  left: 50%;
  bottom: -16px;
  transform: translateX(-50%);
}

.protractor-handle.rotate {
  right: 18px;
  bottom: 18px;
}

.protractor-handle.move::before {
  content: "↕";
  font-weight: 900;
}

.protractor-handle.rotate::before {
  content: "↻";
  font-weight: 900;
}

.compass-tool {
  position: absolute;
  z-index: 14;
  width: 1px;
  height: 1px;
  touch-action: none;
}

.compass-hinge {
  position: absolute;
  z-index: 3;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: #47472c;
  box-shadow: 0 8px 18px rgba(71, 71, 44, 0.25);
  cursor: move;
  touch-action: none;
}

.compass-arm,
.compass-leg {
  position: absolute;
  left: 0;
  top: 0;
  height: 6px;
  border-radius: 99px;
  background: #47472c;
  box-shadow: 0 8px 16px rgba(71, 71, 44, 0.18);
  transform-origin: 0 50%;
  pointer-events: none;
}

.compass-leg {
  background: #6d6b45;
}

.compass-pin,
.compass-pencil {
  position: absolute;
  z-index: 2;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 8px 18px rgba(71, 71, 44, 0.25);
  touch-action: none;
}

.compass-pin {
  left: -15px;
  top: -15px;
  background: #47472c;
  cursor: move;
}

.compass-pencil {
  background: var(--blue);
  cursor: crosshair;
}

@media (max-width: 760px) {
  .toolbar {
    top: 8px;
    bottom: 8px;
    left: 8px;
    width: 68px;
    max-height: calc(100vh - 16px);
    justify-content: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .tool-btn,
  .color-input {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
  }

  .lock-btn {
    width: 52px;
  }

  .save-btn {
    width: 56px;
  }

  .folder-btn {
    width: 64px;
  }

  .save-status {
    flex: 0 0 auto;
  }

  .range-wrap {
    flex: 0 0 auto;
  }

  .range-wrap input {
    width: 54px;
  }

  .viewer {
    padding: 18px 14px 18px 88px;
  }

  .page-info {
    min-width: 54px;
  }
}
