:root {
  color-scheme: light;
  --ink: #111;
  --muted: #707070;
  --paper: #f5f5f5;
  --panel: #fff;
  --line: #d8d8d8;
  --soft-line: #ececec;
  --button: #111;
  --caption-red: #d60000;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) 300px;
  gap: 14px;
  align-items: center;
  min-height: 100vh;
  height: 100vh;
  padding: 14px;
}

.workspace {
  display: grid;
  place-items: center;
  min-width: 0;
}

.stage-wrap {
  position: relative;
  width: min(calc(100vh - 28px), 100%);
  max-width: 760px;
  aspect-ratio: 1;
  background: #f2f2f2;
  border: 1px solid var(--line);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  touch-action: none;
}

.meme-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
  cursor: grab;
}

.meme-canvas.dragging {
  cursor: grabbing;
}

.upload-prompt {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  color: #8a8a8a;
  cursor: pointer;
}

.upload-prompt[hidden] {
  display: none;
}

.upload-prompt .plus {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 1.5px solid #9a9a9a;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
  font-size: 38px;
  line-height: 1;
  font-weight: 200;
}

.upload-copy {
  color: #777;
  font-size: 14px;
}

.panel {
  align-self: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(100vh - 28px);
  overflow: auto;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.08);
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.control-group {
  display: grid;
  gap: 8px;
}

.control-group label {
  font-weight: 800;
}

.button-row,
.action-grid,
.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.camera-actions {
  grid-template-columns: 1fr 1fr 1fr;
}

.file-button,
.primary-button,
.secondary-button {
  display: grid;
  place-items: center;
  min-height: 46px;
  border-radius: 6px;
  border: 1px solid var(--ink);
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
}

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

.file-button,
.primary-button {
  background: var(--button);
  color: #fff;
}

.secondary-button {
  background: transparent;
  color: var(--ink);
}

.input-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 10px;
}

.text-tools {
  grid-template-columns: 1fr 1fr;
}

.text-tools #captionInput {
  grid-column: 1 / -1;
}

#captionInput {
  width: 100%;
  min-height: 46px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

input[type="range"] {
  width: 100%;
  accent-color: #555;
}

.compact-button {
  min-height: 46px;
}

.hint,
.status {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.status {
  min-height: 40px;
}

.camera-dialog,
.crop-dialog {
  width: min(92vw, 560px);
  padding: 14px;
  border: 0;
  border-radius: 8px;
  background: var(--panel);
}

.crop-dialog {
  width: min(92vw, 620px);
}

.camera-dialog::backdrop,
.crop-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.crop-header h2 {
  margin: 0 0 12px;
  font-size: 20px;
  letter-spacing: 0;
}

#cropCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  background: #f2f2f2;
  cursor: move;
  touch-action: none;
  margin-bottom: 10px;
}

#cameraVideo {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #000;
  margin-bottom: 12px;
}

@media (max-width: 720px) {
  body {
    min-height: 100dvh;
    overflow: hidden;
  }

  .app-shell {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    min-height: 100dvh;
    padding: 10px;
    gap: 8px;
  }

  .workspace {
    align-self: end;
  }

  .stage-wrap {
    width: min(100%, 42dvh);
    max-width: none;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.08);
  }

  .panel {
    align-self: stretch;
    gap: 10px;
    min-height: 0;
    max-height: none;
    overflow: auto;
    padding: 12px;
    box-shadow: none;
  }

  .brand p {
    font-size: 14px;
  }

  .control-group {
    gap: 6px;
  }

  .control-group label {
    font-size: 14px;
  }

  .button-row,
  .action-grid,
  .dialog-actions {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .camera-actions {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .file-button,
  .primary-button,
  .secondary-button {
    min-height: 36px;
    border-radius: 5px;
    font-size: 14px;
  }

  .input-action {
    gap: 8px;
  }

  #captionInput {
    min-height: 38px;
    padding: 0 10px;
    font-size: 14px;
  }

  input[type="range"] {
    height: 22px;
  }

  .hint {
    display: none;
  }

  .status {
    min-height: 18px;
    font-size: 12px;
    line-height: 1.35;
  }

  .upload-prompt {
    gap: 8px;
  }

  .upload-prompt .plus {
    width: 48px;
    height: 48px;
    font-size: 32px;
  }

  .upload-copy {
    font-size: 13px;
  }
}

@media (max-width: 420px) {
  .input-action {
    grid-template-columns: minmax(0, 1fr) 68px;
  }

  .text-tools {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 390px), (max-height: 760px) {
  .app-shell {
    padding: 8px;
    gap: 6px;
  }

  .stage-wrap {
    width: min(100%, 39dvh);
  }

  .panel {
    gap: 6px;
    padding: 10px;
  }

  .brand {
    display: none;
  }

  .control-group {
    gap: 4px;
  }

  .control-group label {
    font-size: 13px;
  }

  .file-button,
  .primary-button,
  .secondary-button {
    min-height: 30px;
    font-size: 13px;
  }

  #captionInput {
    min-height: 32px;
    font-size: 13px;
  }

  input[type="range"] {
    height: 18px;
  }

  .status {
    display: none;
  }
}
