/* ============================================
   base.css
   果赖蛋糕坊 - 基础样式与主布局
   CSS Reset · Body · Header · Main · Control · TabBar
   ============================================ */

/* ---------- CSS Reset ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%;
  font-size: 16px;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs);
  font-weight: var(--fw-normal);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: linear-gradient(
    135deg,
    var(--bg-gradient-start) 0%,
    var(--bg-gradient-mid) 50%,
    var(--bg-gradient-end) 100%
  );
  background-attachment: fixed;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
main,
menu,
nav,
section,
summary {
  display: block;
}

audio,
canvas,
progress,
video {
  display: inline-block;
  vertical-align: baseline;
}

audio:not([controls]) {
  display: none;
  height: 0;
}

[hidden],
template {
  display: none;
}

a {
  background-color: transparent;
  color: inherit;
  text-decoration: none;
}

abbr[title] {
  border-bottom: 1px dotted;
}

b,
strong {
  font-weight: var(--fw-bold);
}

img {
  border: 0;
  max-width: 100%;
}

svg:not(:root) {
  overflow: hidden;
}

hr {
  height: 1px;
  border: 0;
  background: var(--border);
}

button,
input,
optgroup,
select,
textarea {
  color: inherit;
  font: inherit;
  margin: 0;
  outline: none;
  border: none;
  background: none;
}

button {
  overflow: visible;
  cursor: pointer;
}

button,
select {
  text-transform: none;
}

button,
html input[type="button"],
input[type="reset"],
input[type="submit"] {
  -webkit-appearance: button;
  appearance: button;
  cursor: pointer;
}

button[disabled],
html input[disabled] {
  cursor: default;
  opacity: 0.5;
}

button::-moz-focus-inner,
input::-moz-focus-inner {
  border: 0;
  padding: 0;
}

input {
  line-height: normal;
}

input[type="checkbox"],
input[type="radio"] {
  box-sizing: border-box;
  padding: 0;
  cursor: pointer;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  height: auto;
}

input[type="search"] {
  -webkit-appearance: textfield;
  appearance: textfield;
  box-sizing: content-box;
}

input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
}

fieldset {
  border: 1px solid var(--border-strong);
  margin: 0 2px;
  padding: 0.35em 0.625em 0.75em;
}

legend {
  border: 0;
  padding: 0;
}

textarea {
  overflow: auto;
  resize: none;
}

optgroup {
  font-weight: var(--fw-bold);
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

td,
th {
  padding: 0;
}

ul,
ol {
  list-style: none;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: var(--fw-bold);
  line-height: 1.3;
}

/* ---------- App 容器 ---------- */
#app,
body {
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
.header {
  flex-shrink: 0;
  height: var(--header-h);
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) var(--space-md) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space);
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: var(--z-header);
}

.header .logo {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  font-weight: var(--fw-black);
  color: var(--pink-dark);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  white-space: nowrap;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 2px rgba(255, 143, 168, 0.2);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* ---------- Main Area (Canvas) ---------- */
.main-area {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: var(--z-canvas);
}

.module-panel {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: var(--space);
  gap: var(--space);
}

.module-panel.active {
  display: flex;
  animation: fadeIn var(--t) var(--ease-out);
}

.canvas-toolbar {
  flex-shrink: 0;
  width: 100%;
  max-width: 680px;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space);
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.canvas-scale {
  flex: 1;
  display: flex;
  align-items: center;
  margin-left: auto;
  min-width: 80px;
}

.canvas-scale input[type="range"] {
  width: 100%;
}

/* ---------- Canvas Wrapper ---------- */
.canvas-wrapper {
  flex: 1 1 auto;
  width: 100%;
  max-width: 680px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
}

.canvas-wrapper canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.5);
  box-shadow: var(--shadow-md);
  touch-action: none;
  object-fit: contain;
}

.voice-hint {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--purple-light);
  border-radius: var(--radius-full);
  font-size: var(--fs-sm);
  color: var(--purple-dark);
  font-weight: var(--fw-medium);
}

.voice-hint .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pink-dark);
  animation: pulse 1s var(--ease-smooth) infinite;
}

/* ---------- Control Panel (slide up) ---------- */
.control-panel {
  flex-shrink: 0;
  position: relative;
  z-index: var(--z-control);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top-left-radius: var(--radius-xl);
  border-top-right-radius: var(--radius-xl);
  box-shadow: 0 -6px 24px rgba(180, 140, 170, 0.18);
  max-height: var(--control-h);
  max-height: calc(var(--control-h) + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  transition: max-height var(--t-slow) var(--ease-smooth),
    transform var(--t-slow) var(--ease-smooth);
  overflow: hidden;
}

.control-panel.collapsed {
  max-height: var(--control-h-collapsed);
  max-height: calc(var(--control-h-collapsed) + var(--safe-bottom));
}

.panel-handle {
  flex-shrink: 0;
  width: 44px;
  height: 6px;
  margin: var(--space-sm) auto;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  cursor: pointer;
  transition: background var(--t);
}

.panel-handle:active {
  background: var(--purple-dark);
}

.control-content {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 var(--space-md) var(--space-md);
  padding-bottom: calc(var(--space-md) + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.control-section {
  display: none;
  flex-direction: column;
  gap: var(--space);
  animation: slideUp var(--t) var(--ease-out);
}

.control-section.active,
.control-section[style*="display: block"],
.control-section:not([style*="display: none"]):first-child {
  display: flex;
}

/* ---------- Tab Bar ---------- */
.tab-bar {
  flex-shrink: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  height: var(--tabbar-h);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(180, 140, 170, 0.12);
  position: relative;
  z-index: var(--z-tabbar);
}

.tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  padding: var(--space-xs) 0;
  color: var(--text-light);
  font-size: var(--fs-xs);
  transition: color var(--t), transform var(--t-fast);
  position: relative;
  min-height: var(--btn-h);
}

.tab .tab-icon {
  font-size: var(--fs-lg);
  line-height: 1;
  transition: transform var(--t-bounce);
}

.tab .tab-label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1;
}

.tab.active {
  color: var(--pink-dark);
}

.tab.active .tab-icon {
  transform: translateY(-2px) scale(1.15);
}

.tab.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 3px;
  border-radius: var(--radius-full);
  background: var(--pink-dark);
  box-shadow: var(--shadow-glow-pink);
}

.tab:active {
  transform: scale(0.92);
}

/* ---------- 滚动条美化 ---------- */
.control-content::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.control-content::-webkit-scrollbar-track {
  background: transparent;
  margin: var(--space-sm) 0;
}

.control-content::-webkit-scrollbar-thumb {
  background: var(--purple);
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  background-clip: content-box;
}

.control-content::-webkit-scrollbar-thumb:hover {
  background: var(--purple-dark);
  background-clip: content-box;
}

.control-content {
  scrollbar-width: thin;
  scrollbar-color: var(--purple) transparent;
}

/* 全局滚动条 */
*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--purple);
  border-radius: var(--radius-full);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--purple) transparent;
}

/* ---------- 通用辅助类 ---------- */
.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.text-pink {
  color: var(--pink-dark);
}

.text-purple {
  color: var(--purple-dark);
}

.mt-sm {
  margin-top: var(--space-sm);
}

.mt {
  margin-top: var(--space);
}

.mt-md {
  margin-top: var(--space-md);
}

.mt-lg {
  margin-top: var(--space-lg);
}

.flex {
  display: flex;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.gap-sm {
  gap: var(--space-sm);
}

.gap {
  gap: var(--space);
}

/* ---------- 选区与聚焦 ---------- */
::selection {
  background: var(--pink-light);
  color: var(--pink-dark);
}

:focus-visible {
  outline: 2px solid var(--purple-dark);
  outline-offset: 2px;
}

/* ---------- 图片禁用拖拽 ---------- */
img {
  -webkit-user-drag: none;
  user-drag: none;
}
