* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  margin: 0;
  padding: 0;
  overscroll-behavior: none;
}

body {
  --purple-50: #f0faf8;
  --purple-100: #d9f1ed;
  --purple-200: #b9e3db;
  --purple-400: #78c8ba;
  --purple-500: #56b4a3;
  --purple-600: #56b4a3;
  --purple-700: #429485;
  --purple-800: #34766b;
  --purple-900: #285d55;
  --nav-height: 90px;
  --header-height: 68px;

  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: #1f2937;
  background: #fff;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
}

svg {
  display: block;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hidden {
  display: none !important;
}

.app-header {
  position: relative;
  z-index: 20;
  display: flex;
  flex: 0 0 var(--header-height);
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid var(--purple-100);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  display: flex;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  align-items: center;
  justify-content: center;
  padding: 6px;
  color: #fff;
  background: var(--purple-600);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

.brand-icon svg {
  width: 20px;
  height: 20px;
}

.brand h1 {
  margin: 0;
  color: var(--purple-800);
  font-size: clamp(15px, 4vw, 16px);
  font-weight: 700;
  line-height: 20px;
}

.device-pill {
  display: flex;
  width: max-content;
  max-width: calc(100vw - 72px);
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  padding: 2px 6px;
  overflow: hidden;
  color: #16a34a;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  line-height: 14px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.device-pill svg {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
}

.main-content {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: rgba(250, 245, 255, .3);
}

.tab {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.tab-caliper {
  overflow: hidden;
}

.result-panel {
  position: absolute;
  inset: 16px 16px auto;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 680px;
  margin: 0 auto;
  padding: clamp(16px, 4vw, 20px);
  background: #fff;
  border: 1px solid var(--purple-100);
  border-radius: 24px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, .1), 0 8px 10px -6px rgba(0, 0, 0, .1);
}

.result-label {
  margin: 0 0 4px;
  color: #6b7280;
  font-size: 12px;
  font-weight: 600;
  line-height: 16px;
  letter-spacing: .025em;
  text-transform: uppercase;
}

.result-number {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 12px;
  color: var(--purple-700);
  font-size: clamp(44px, 14vw, 60px);
  font-weight: 900;
  line-height: 1;
}

.result-number .unit {
  color: var(--purple-400);
  font-size: clamp(20px, 6vw, 24px);
  font-weight: 500;
  line-height: 32px;
}

.suggest-card {
  width: 100%;
  padding: clamp(12px, 4vw, 16px);
  background: var(--purple-50);
  border: 1px solid var(--purple-100);
  border-radius: 16px;
}

.suggest-card p {
  margin: 0 0 4px;
  color: var(--purple-900);
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  text-align: center;
}

.suggest-card strong {
  display: block;
  color: var(--purple-700);
  font-size: clamp(20px, 6vw, 24px);
  font-weight: 700;
  line-height: 32px;
  text-align: center;
}

.caliper-bar {
  position: absolute;
  right: 0;
  left: 0;
  z-index: 20;
  display: flex;
  height: 40px;
  flex-direction: column;
  justify-content: center;
  cursor: ns-resize;
  touch-action: none;
  transform: translateY(-50%);
}

.caliper-line {
  width: 100%;
  height: 6px;
  background: var(--purple-400);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
  transition: background .15s;
}

.caliper-bar:active .caliper-line {
  background: var(--purple-600);
}

.drag-handle {
  position: absolute;
  left: min(85%, calc(100% - 44px));
  display: flex;
  width: 48px;
  height: 40px;
  align-items: center;
  justify-content: center;
  color: var(--purple-600);
  background: #fff;
  border: 2px solid var(--purple-500);
  border-radius: 9999px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, .1), 0 4px 6px -4px rgba(0, 0, 0, .1);
  cursor: grab;
  transform: translateX(-50%);
}

.drag-handle svg {
  width: 20px;
  height: 20px;
}

.caliper-bar:active .drag-handle {
  transform: translateX(-50%) scale(1.1);
}

.caliper-overlay {
  position: absolute;
  right: 0;
  left: 0;
  background: rgba(168, 85, 247, .1);
  pointer-events: none;
  transition: top .05s, height .05s;
}

.drag-hint {
  position: absolute;
  right: 16px;
  bottom: clamp(72px, 18vh, 112px);
  left: 16px;
  z-index: 10;
  text-align: center;
  pointer-events: none;
}

.drag-hint > div {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  color: var(--purple-800);
  background: var(--purple-100);
  border: 1px solid var(--purple-200);
  border-radius: 9999px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
  animation: bounce 1s infinite;
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
}

.drag-hint svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.edge-ruler-shell {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  width: clamp(84px, 24vw, 96px);
  overflow: hidden;
  background: #fff;
  border-right: 1px solid var(--purple-200);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}

.edge-ruler {
  position: relative;
  height: 100%;
}

.tick {
  position: absolute;
  left: 0;
  display: flex;
  align-items: center;
  transform: translateY(-50%);
}

.tick-line {
  background: #1f2937;
}

.tick-small {
  width: 16px;
  height: 1px;
}

.tick-half {
  width: 24px;
  height: 1.5px;
}

.tick-cm {
  width: 40px;
  height: 2px;
}

.tick-label {
  margin-left: 6px;
  color: #1f2937;
  font-size: clamp(12px, 3.4vw, 14px);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  text-shadow: 0 1px 1px rgba(255, 255, 255, .8);
}

.tick-label small {
  color: #6b7280;
  font-size: 10px;
  font-weight: 500;
}

.edge-guide-card {
  position: absolute;
  top: 50%;
  right: 16px;
  left: clamp(104px, 30vw, 112px);
  max-width: 720px;
  padding: clamp(16px, 4vw, 20px);
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--purple-100);
  border-radius: 16px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, .1), 0 4px 6px -4px rgba(0, 0, 0, .1);
  transform: translateY(-50%);
  backdrop-filter: blur(8px);
}

.edge-guide-card h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  color: var(--purple-800);
  font-size: 16px;
  font-weight: 700;
}

.edge-guide-card h3 svg {
  width: 20px;
  height: 20px;
}

.edge-guide-card ol {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 0;
  color: #4b5563;
  font-size: 14px;
  line-height: 20px;
  list-style: none;
}

.edge-guide-card li {
  display: flex;
  gap: 8px;
}

.edge-guide-card li > b {
  color: var(--purple-600);
}

.guide-page {
  height: 100%;
  padding: 20px 20px calc(var(--nav-height) + 24px);
  overflow-y: auto;
  touch-action: pan-y;
}

.guide-card,
.warning-card {
  width: min(100%, 760px);
  margin-right: auto;
  margin-left: auto;
  padding: clamp(16px, 4vw, 20px);
  background: #fff;
  border: 1px solid var(--purple-100);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}

.guide-card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  color: var(--purple-800);
  font-size: 20px;
  font-weight: 700;
  line-height: 28px;
}

.guide-card h2 svg {
  width: 24px;
  height: 24px;
  color: var(--purple-500);
}

.step-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.step {
  display: flex;
  gap: 12px;
}

.step-no {
  display: flex;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  align-items: center;
  justify-content: center;
  color: var(--purple-700);
  background: var(--purple-100);
  border-radius: 9999px;
  font-weight: 700;
}

.step-title {
  margin: 0;
  color: #1f2937;
  font-size: 16px;
  font-weight: 600;
}

.step p {
  margin: 4px 0 0;
  color: #4b5563;
  font-size: 14px;
  line-height: 20px;
}

.formula {
  margin-top: 8px;
  padding: 12px;
  color: var(--purple-800);
  background: var(--purple-50);
  border: 1px solid var(--purple-100);
  border-radius: 8px;
  font-size: 14px;
  line-height: 20px;
}

.example {
  color: #6b7280 !important;
  font-size: 12px !important;
  font-style: italic;
}

.warning-card {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 24px;
  color: #9a3412;
  background: #fff7ed;
  border-color: #ffedd5;
}

.warning-card svg {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}

.warning-card p {
  margin: 0;
  font-size: 14px;
  line-height: 20px;
}

.detail-link {
  display: flex;
  width: min(100%, 760px);
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 24px auto 0;
  padding: 16px;
  color: #fff;
  background: var(--purple-600);
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, .1), 0 2px 4px -2px rgba(0, 0, 0, .1);
  font-weight: 700;
  text-decoration: none;
  transition: background .15s;
}

.detail-link:hover {
  background: var(--purple-700);
}

.detail-link svg {
  width: 20px;
  height: 20px;
}

.bottom-nav {
  position: relative;
  z-index: 30;
  display: flex;
  height: var(--nav-height);
  flex: 0 0 var(--nav-height);
  align-items: center;
  justify-content: space-around;
  padding: 8px calc(8px + env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) calc(8px + env(safe-area-inset-left, 0px));
  background: #fff;
  border-top: 1px solid var(--purple-100);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, .05);
}

.nav-btn {
  display: flex;
  width: min(112px, 31vw);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  padding: 8px 0;
  color: #9ca3af;
  background: transparent;
  border: 0;
  cursor: pointer;
  transition: color .15s;
}

.nav-btn.active {
  color: var(--purple-700);
}

.icon-bg {
  padding: 6px;
  transition: all .15s;
}

.nav-btn.active .icon-bg {
  background: var(--purple-100);
  border-radius: 12px;
}

.nav-btn svg {
  width: 24px;
  height: 24px;
}

.nav-label {
  font-size: 11px;
  font-weight: 500;
  line-height: 16px;
}

.nav-btn.active .nav-label {
  font-weight: 700;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(-25%);
    animation-timing-function: cubic-bezier(.8, 0, 1, 1);
  }

  50% {
    transform: none;
    animation-timing-function: cubic-bezier(0, 0, .2, 1);
  }
}

@media (max-width: 360px), (max-height: 640px) {
  body {
    --header-height: 62px;
    --nav-height: 78px;
  }

  .app-header {
    padding: 9px 12px;
  }

  .brand-icon {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
  }

  .device-pill {
    max-width: calc(100vw - 64px);
  }

  .result-panel {
    inset: 10px 10px auto;
    border-radius: 20px;
  }

  .result-number {
    margin-bottom: 8px;
  }

  .suggest-card {
    padding: 10px;
  }

  .drag-hint {
    right: 10px;
    bottom: 56px;
    left: 10px;
  }

  .drag-hint > div {
    padding: 7px 12px;
  }

  .edge-guide-card {
    right: 10px;
    left: 100px;
    padding: 14px;
  }
}

@media (min-width: 768px) {
  .result-panel {
    right: 50%;
    left: 50%;
    width: min(680px, calc(100vw - 32px));
    transform: translateX(-50%);
  }

  .edge-guide-card {
    right: auto;
    width: min(720px, calc(100vw - 132px));
  }
}
