:root {
  color-scheme: light;
  --bg: #f5f6f2;
  --surface: #ffffff;
  --surface-soft: #eef3ef;
  --text: #191b1f;
  --muted: #687076;
  --line: #d8ded7;
  --accent: #0f8b8d;
  --accent-strong: #0a6f70;
  --accent-soft: #e4f5f2;
  --danger: #d64045;
  --gold: #d99b26;
  --shadow: 0 20px 50px rgba(25, 27, 31, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Noto Sans TC", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(15, 139, 141, 0.28);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
}

.topbar {
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent);
}

.brand h1,
.brand p,
.control-group h2 {
  margin: 0;
}

.brand h1 {
  font-size: 1.18rem;
  line-height: 1.25;
}

.brand p {
  max-width: 52vw;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
}

.workspace {
  display: grid;
  min-height: 0;
  grid-template-columns: 360px minmax(0, 1fr);
}

.sidebar {
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #fbfbfa;
}

.control-group {
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.control-group h2 {
  margin-bottom: 12px;
  font-size: 0.92rem;
  line-height: 1.2;
}

.upload-box {
  display: flex;
  min-height: 94px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px dashed #b8c3ba;
  border-radius: 8px;
  background: var(--surface);
  transition:
    border-color 160ms ease,
    background-color 160ms ease;
}

.upload-box.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-copy {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.upload-copy svg {
  flex: 0 0 auto;
  color: var(--gold);
}

#fileName {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#fileInput {
  display: none;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  min-width: 104px;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  line-height: 1.2;
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-strong);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.secondary-button:hover {
  border-color: #aeb9b1;
  background: var(--surface-soft);
}

.primary-button:active:not(:disabled),
.secondary-button:active {
  transform: translateY(1px);
}

.primary-button:disabled {
  cursor: not-allowed;
  background: #b7c3bf;
  color: #f5f7f6;
}

svg {
  width: 20px;
  height: 20px;
  stroke-width: 2;
}

.stamp-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stamp-option {
  display: grid;
  min-width: 0;
  min-height: 104px;
  grid-template-rows: 64px auto;
  gap: 7px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

.stamp-option:hover {
  border-color: #aeb9b1;
}

.stamp-option[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px rgba(15, 139, 141, 0.22);
}

.stamp-art {
  display: grid;
  width: 100%;
  height: 64px;
  place-items: center;
}

.stamp-art img {
  display: block;
  max-width: 100%;
  max-height: 58px;
  object-fit: contain;
  filter: drop-shadow(0 6px 8px rgba(25, 27, 31, 0.13));
}

.stamp-name {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.range-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.range-heading h2 {
  margin-bottom: 0;
}

#scaleValue,
#rotationValue {
  min-width: 54px;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  text-align: right;
}

.range-input {
  width: 100%;
  accent-color: var(--accent);
}

.stage {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  padding: 24px;
  background:
    linear-gradient(rgba(25, 27, 31, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(25, 27, 31, 0.04) 1px, transparent 1px),
    #f8f9f7;
  background-size: 32px 32px;
}

.empty-state {
  display: grid;
  width: min(420px, 100%);
  min-height: 260px;
  place-items: center;
  gap: 14px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.empty-state > svg {
  width: 42px;
  height: 42px;
  color: var(--accent);
}

.empty-state strong {
  font-size: 1.05rem;
}

.canvas-frame {
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: #ffffff;
  background-image:
    linear-gradient(45deg, #e6ece8 25%, transparent 25%),
    linear-gradient(-45deg, #e6ece8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e6ece8 75%),
    linear-gradient(-45deg, transparent 75%, #e6ece8 75%);
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
  box-shadow: var(--shadow);
}

.canvas-frame[hidden],
.empty-state[hidden] {
  display: none;
}

#resultCanvas {
  display: block;
  width: auto;
  height: auto;
  max-width: min(100%, 1180px);
  max-height: calc(100vh - 126px);
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .topbar {
    align-items: flex-start;
    padding: 14px 16px;
  }

  .brand p {
    max-width: 42vw;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(58vh, 1fr);
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .control-group {
    padding: 16px;
  }

  .stamp-grid {
    grid-template-columns: repeat(5, 112px);
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .stage {
    min-height: 58vh;
  }

  #resultCanvas {
    max-height: calc(100vh - 230px);
  }
}

@media (max-width: 600px) {
  .topbar {
    flex-direction: column;
  }

  .brand {
    width: 100%;
  }

  .brand p {
    max-width: 100%;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions .primary-button,
  .top-actions .secondary-button {
    flex: 1 1 0;
    min-width: 0;
  }

  .upload-box {
    align-items: stretch;
    flex-direction: column;
  }

  .upload-box .secondary-button {
    width: 100%;
  }

  .stage {
    padding: 12px;
  }

  .empty-state {
    min-height: 220px;
    padding: 22px;
  }
}
