:root {
  --c1: #3d6cb9;
  --c2: #00d1ff;
  --c4: #fafaf6;
  --text: #252525;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", sans-serif;
  background: var(--c4);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body.picker-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

#app {
  min-height: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

.view {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
}

.view.active {
  display: flex;
}

/* Home */
.home-header {
  text-align: center;
  padding: calc(30px + env(safe-area-inset-top, 0px)) 24px 0;
}

.home-header h1 {
  margin: 0;
  font-size: 28px;
  color: var(--c1);
}

.subtitle {
  margin: 10px 0 0;
  color: #888;
  font-size: 16px;
}

.deco-line {
  width: 120px;
  height: 1px;
  background: rgba(61, 108, 185, 0.3);
  margin: 15px auto 0;
}

.home-actions {
  padding: 30px 30px 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.btn {
  border: none;
  cursor: pointer;
  font-size: 18px;
  font-weight: 600;
  border-radius: 15px;
  padding: 14px 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  font-family: inherit;
}

.btn-block {
  width: 100%;
}

.pick-label {
  position: relative;
  cursor: pointer;
  text-align: center;
  overflow: hidden;
}

/* 部分 WebView（Via 等，UA 未必能识别）对 display:none 的 file 选图后返回空，统一透明盖住按钮 */
html.xiaomi-via .pick-label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 55px;
}

.file-in-label {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  z-index: 5;
  font-size: 48px;
  cursor: pointer;
  border: none;
}

.browser-tip {
  margin: 12px 24px 0;
  padding: 12px 14px;
  background: #fff8e6;
  border: 1px solid #ffe08a;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: #5c4a00;
}

.browser-tip p {
  margin: 0 0 10px;
}

.browser-tip-btn {
  border: 1px solid #c9a227;
  background: #fff;
  color: #5c4a00;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
}

.btn-primary {
  background: var(--c1);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-secondary {
  background: var(--c2);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-outline {
  background: transparent;
  color: var(--c1);
  border: 1px solid var(--c1);
  font-size: 16px;
  font-weight: 500;
  width: 160px;
  margin: 10px auto 0;
}

.home-footer {
  margin-top: auto;
  padding: 24px 16px calc(20px + var(--safe-bottom));
}

.info-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 10px;
  padding: 10px 15px;
  font-size: 13px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.info-bar-mode {
  margin: 0;
  line-height: 1.4;
  word-break: break-word;
}

.info-bar-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.info-bar .version {
  flex: 1;
  min-width: 0;
  text-align: left;
  color: #aaa;
  font-size: 11px;
  line-height: 1.3;
}

.link-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--c1);
  font-size: 13px;
  cursor: pointer;
}

/* Picker */
#view-picker {
  background: #111;
}

#view-picker.active {
  position: fixed;
  z-index: 200;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.picker-stage {
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
  touch-action: none;
  background: #000;
}

#picker-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.picker-dock {
  flex-shrink: 0;
  position: relative;
  z-index: 20;
  background: #0a0a0a;
  padding-bottom: var(--safe-bottom);
}

.magnifier {
  position: absolute;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 2px solid #fff;
  overflow: hidden;
  pointer-events: none;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  z-index: 2;
}

.magnifier canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.magnifier-cross::before,
.magnifier-cross::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.9);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.magnifier-cross::before {
  width: 14px;
  height: 1px;
}

.magnifier-cross::after {
  width: 1px;
  height: 14px;
}

.btn-ai {
  position: relative;
  border: none;
  border-radius: 22px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(90deg, var(--c2), var(--c1));
  box-shadow: 0 4px 12px rgba(61, 108, 185, 0.4);
  cursor: pointer;
  z-index: 10;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}

.picker-ai-row {
  flex-shrink: 0;
  padding: 10px 16px;
  text-align: center;
  background: #0a0a0a;
}

.picker-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 12px;
  background: rgba(38, 38, 38, 0.95);
  border-radius: 20px 20px 0 0;
  min-height: 90px;
}

.picker-info {
  flex: 1;
  min-width: 0;
}

.color-value {
  margin: 0 0 6px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
}

.color-name {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-palette-sm {
  flex-shrink: 0;
  border: none;
  border-radius: 15px;
  padding: 8px 10px;
  font-size: 12px;
  color: #fff;
  background: linear-gradient(90deg, var(--c1), var(--c2));
  cursor: pointer;
}

.picker-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}

/* Palette */
#view-palette {
  background: linear-gradient(180deg, var(--c4) 0%, #fff 30%);
}

.palette-header {
  text-align: center;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 8px;
  position: relative;
}

.palette-header h2 {
  margin: 0;
  color: var(--c1);
  font-size: 24px;
}

.palette-header p {
  margin: 5px 0 0;
  color: #888;
  font-size: 14px;
}

.icon-close {
  position: absolute;
  right: 16px;
  top: calc(16px + env(safe-area-inset-top, 0px));
  border: none;
  background: none;
  color: var(--c1);
  font-size: 22px;
  cursor: pointer;
}

.palette-preview {
  padding: 16px;
  text-align: center;
}

.palette-preview img {
  max-width: 90%;
  max-height: 180px;
  border-radius: 10px;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.palette-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 15px 80px;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: 15px;
  background: #fff;
  border-radius: 12px;
  padding: 15px;
  margin-bottom: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.palette-swatch {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  flex-shrink: 0;
}

.palette-meta {
  flex: 1;
  min-width: 0;
}

.palette-meta strong {
  display: block;
  font-size: 16px;
}

.palette-meta span {
  font-size: 13px;
  color: #888;
}

.palette-copy {
  border: none;
  background: none;
  color: var(--c1);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

.palette-footer {
  position: sticky;
  bottom: 0;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
  text-align: center;
}

.palette-footer .btn-primary {
  width: 200px;
  background: linear-gradient(90deg, var(--c1), var(--c2));
}

/* Settings & Web */
.nav-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: #fff;
  border-bottom: 1px solid #eee;
}

.nav-header h2 {
  margin: 0;
  font-size: 18px;
  flex: 1;
  text-align: center;
  margin-right: 48px;
}

.nav-back {
  border: none;
  background: none;
  color: var(--c1);
  font-size: 16px;
  cursor: pointer;
}

.settings-hero {
  text-align: center;
  padding: 24px 16px;
}

.settings-icon {
  font-size: 48px;
}

.settings-hero p {
  margin: 10px 0 0;
  font-weight: 700;
  color: var(--c1);
}

.settings-group {
  padding: 0 16px 24px;
}

.settings-group h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--c1);
}

.setting-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  margin-bottom: 8px;
  border: none;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  font-size: 16px;
  cursor: pointer;
  text-align: left;
}

.setting-value {
  color: #888;
  font-size: 14px;
}

.chevron {
  color: #ccc;
  font-size: 20px;
}

#web-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 9999;
  pointer-events: none;
}

.toast[hidden],
.error-modal[hidden] {
  display: none !important;
}

.error-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
}

.error-modal-panel {
  width: 100%;
  max-width: 360px;
  max-height: min(70vh, 420px);
  background: #fff;
  border-radius: 14px;
  padding: 18px 16px 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.error-modal-panel h3 {
  margin: 0;
  font-size: 17px;
  color: #c62828;
}

#error-modal-body {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  flex: 1;
  color: #333;
}

.error-modal-panel .btn {
  margin-top: 4px;
}

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  max-width: 480px;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
}

.sheet-overlay[hidden] {
  display: none !important;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.sheet-inner {
  position: relative;
  z-index: 1;
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 8px 0 calc(16px + var(--safe-bottom));
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
}

.sheet-action {
  display: block;
  width: 100%;
  padding: 16px;
  border: none;
  background: none;
  font-size: 17px;
  text-align: center;
  cursor: pointer;
  color: var(--text);
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  touch-action: manipulation;
}

.sheet-hint {
  text-align: center;
  padding: 16px 20px 8px;
  margin: 0;
  color: #666;
  font-size: 14px;
  line-height: 1.4;
}

.sheet-action.cancel {
  color: #888;
  margin-top: 8px;
  border-top: 8px solid #f0f0f0;
}

.sheet-action.destructive {
  color: #c00;
}
