* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #16181d;
  color: #e8eaf0;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

/* 顶栏 */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #20232a;
  border-bottom: 1px solid #2c3038;
  flex-shrink: 0;
}
#topbar .title { font-size: 17px; font-weight: 600; }
.icon-btn {
  background: #2a2e36;
  border: none;
  color: #e8eaf0;
  width: 40px; height: 40px;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:active { background: #3a3f49; }

/* 画布区 */
#stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}
#canvas {
  position: absolute;
  inset: 0;
  display: block;
  touch-action: none;
  background: #0c0d10;
  cursor: crosshair;
}
#canvas.calibrating { outline: 2px dashed #3b82f6; outline-offset: -4px; }

#emptyHint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #5c6370;
  gap: 10px;
  pointer-events: none;
  text-align: center;
  padding: 20px;
}
#emptyHint .hint-icon { font-size: 52px; }
.hint-sub { font-size: 13px; color: #454b56; }

/* 工具栏 */
#toolbar {
  flex-shrink: 0;
  background: #20232a;
  border-top: 1px solid #2c3038;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  transition: transform .2s ease;
}
#toolbar.hidden { display: none; }

.toolbar-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 4px 0;
}

.tool-btn {
  flex: 1;
  min-width: 0;
  background: #2a2e36;
  border: none;
  color: #e8eaf0;
  padding: 12px 6px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.tool-btn:active { background: #3a3f49; }
.tool-btn.primary { background: #3b82f6; color: #fff; font-weight: 600; }
.tool-btn:active.primary { background: #2f6fd6; }
.tool-btn:disabled { opacity: .4; }
.tool-btn.disabled { opacity: .55; }

.opt {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #9aa1ad;
}
.opt select, .opt input[type=color] {
  width: 100%;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: #2a2e36;
  color: #e8eaf0;
  font-size: 14px;
  padding: 0 6px;
  cursor: pointer;
}
.opt input[type=color] { padding: 3px; }

.zoom-opt { flex: 1; }
.zoom-btns { display: flex; gap: 4px; }
.zoom-btn {
  flex: 1;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: #2a2e36;
  color: #e8eaf0;
  font-size: 18px;
  cursor: pointer;
}
.zoom-btn.fit { font-size: 12px; }
.zoom-btn:active { background: #3a3f49; }

.cal-hint { font-size: 13px; color: #9aa1ad; flex-shrink: 0; white-space: nowrap; }
#calValue {
  width: 90px;
  height: 42px;
  background: #1b1e24;
  border: 1px solid #3b82f6;
  border-radius: 8px;
  color: #fff;
  font-size: 17px;
  padding: 0 10px;
  outline: none;
  flex: 0 0 auto;
}
#calUnit {
  height: 42px;
  background: #2a2e36;
  border: none;
  border-radius: 8px;
  color: #e8eaf0;
  font-size: 14px;
  padding: 0 6px;
  flex: 0 0 auto;
}
#calRow { justify-content: flex-start; }
#btnCalOk { flex: 0 0 auto; padding: 12px 22px; }

.zoom-hint {
  font-size: 12px;
  color: #575e6b;
  text-align: center;
  padding-top: 6px;
}

/* toast 提示 */
#toast {
  position: fixed;
  left: 50%;
  bottom: 180px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,0.82);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 999;
  max-width: 80%;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
