@import url("https://fonts.googleapis.com/css2?family=Yomogi&display=swap");

:root {
  --paper: #ffffff;
  --paper-deep: #f6f7f3;
  --ink: #20221d;
  --muted: #7b8078;
  --line: rgba(32, 34, 29, 0.06);
  --panel: rgba(255, 255, 255, 0.92);
  --panel-solid: #ffffff;
  --moss: #8aa05a;
  --moss-dark: #4f6b2f;
  --seal: #b34f3f;
  --shadow: 0 30px 80px rgba(32, 34, 29, 0.07);
  --soft-shadow: 0 14px 38px rgba(32, 34, 29, 0.045);
  --radius: 18px;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: #ffffff;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  min-height: 100vh;
  padding: 24px 28px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  margin: 0 auto 12px;
  padding: 8px 0 28px;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  text-decoration: none;
}

.brand b {
  display: block;
  font-family: "Yomogi", "Hannotate SC", "HanziPen SC", "YuKyokasho", "Klee", "Klee One", "Hiragino Maru Gothic ProN", sans-serif;
  font-size: 1.58rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  transform: rotate(-1deg);
}

.scribble-mark {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 50px;
  height: 44px;
  transform: rotate(-3deg);
}

.mark-head {
  position: absolute;
  left: 12px;
  top: 3px;
  width: 28px;
  height: 23px;
  content: "";
  border: 2px solid #343832;
  border-radius: 54% 46% 48% 52%;
  background: #f3af3f;
}

.mark-head::before,
.mark-head::after {
  position: absolute;
  top: 9px;
  width: 3px;
  height: 3px;
  content: "";
  border-radius: 50%;
  background: #93483e;
}

.mark-head::before {
  left: 9px;
}

.mark-head::after {
  right: 9px;
}

.mark-arm {
  position: absolute;
  top: 24px;
  width: 12px;
  height: 15px;
  border: 2px solid #343832;
  background: #d7ddd8;
}

.mark-arm.left {
  left: 6px;
  border-radius: 12px 5px 8px 10px;
  transform: rotate(16deg);
}

.mark-arm.right {
  right: 6px;
  border-radius: 5px 12px 10px 8px;
  transform: rotate(-16deg);
}

.mark-base {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 0;
  height: 11px;
  border: 2px solid #343832;
  border-radius: 50% 50% 44% 44%;
  background: #e6e8e3;
}

.mark-base::before {
  position: absolute;
  left: 13px;
  top: -11px;
  width: 13px;
  height: 8px;
  content: "";
  border: 2px solid #343832;
  border-radius: 50%;
  background: #8aa05a;
}

.scribble-mark.large {
  width: 92px;
  height: 82px;
  margin-bottom: 18px;
  transform: rotate(-3deg) scale(1.45);
  transform-origin: center bottom;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.soft-button,
.primary-button,
.segmented,
.canvas-tools,
.icon-button {
  border-radius: 14px;
  border: 0;
  background: #f7f8f5;
  color: var(--ink);
  box-shadow: none;
}

.soft-button,
.primary-button {
  min-height: 42px;
  padding: 0 16px;
}

.add-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  overflow: hidden;
}

.add-button input,
.drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.primary-button {
  background: var(--moss-dark);
  color: #ffffff;
  font-weight: 720;
  box-shadow: 0 16px 32px rgba(79, 107, 47, 0.24);
}

.segmented {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px;
}

.segmented button {
  min-width: 54px;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--moss);
  color: #ffffff;
  box-shadow: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(260px, 320px);
  gap: 36px;
  min-height: calc(100vh - 128px);
}

.start-screen {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 136px);
}

.start-upload {
  position: relative;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  width: min(680px, 100%);
  min-height: min(440px, calc(100vh - 220px));
  border: 1px solid rgba(79, 107, 47, 0.18);
  border-radius: 28px;
  background: #fbfcfa;
  box-shadow: 0 24px 70px rgba(32, 34, 29, 0.055);
  color: var(--ink);
  text-align: center;
  overflow: hidden;
}

.start-upload input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.start-upload b {
  margin-top: 2px;
  font-size: clamp(1.12rem, 1.8vw, 1.48rem);
  letter-spacing: 0;
}

.start-upload small {
  color: var(--muted);
  font-size: 0.86rem;
}

.start-upload em {
  margin-top: 12px;
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--moss-dark);
  color: #fff;
  font-style: normal;
  font-weight: 720;
}

.panel,
.editor-area {
  min-width: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 0;
  border-radius: var(--radius);
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 30px;
}

.panel-title h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 720;
}

.panel-title span {
  color: var(--muted);
  font-size: 0.78rem;
}

.layer-list,
.preview-list {
  display: grid;
  gap: 12px;
  overflow: auto;
}

.layer-card,
.preview-card {
  border-radius: 18px;
  background: #f8f9f6;
  box-shadow: none;
}

.layer-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  padding: 10px;
}

.layer-card > img,
.preview-card > img {
  width: 58px;
  height: 58px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--paper-deep);
}

.layer-main {
  min-width: 0;
}

.layer-line {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 30px;
  gap: 6px;
  align-items: center;
}

.layer-line b,
.preview-card b {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 0.83rem;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--moss-dark);
  background: #eef2e7;
  border-color: transparent;
}

.menu {
  color: var(--muted);
}

.opacity-row {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.72rem;
}

input[type="range"] {
  accent-color: var(--moss);
}

.opacity-row em {
  font-style: normal;
  text-align: right;
}

.layer-card small,
.preview-card small {
  display: block;
  margin-top: 5px;
  color: var(--moss);
  font-size: 0.72rem;
}

.drop-zone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 118px;
  margin-top: auto;
  border: 0;
  border-radius: 18px;
  background: #f8f9f6;
  color: var(--ink);
}

.drop-zone b {
  font-size: 0.92rem;
}

.drop-zone span,
.hint,
.note,
.message {
  color: var(--muted);
  font-size: 0.78rem;
}

.hint,
.note,
.message {
  margin: 0;
}

.editor-area {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 18px;
}

.canvas-panel {
  display: grid;
  place-items: center;
  min-height: 610px;
  padding: clamp(22px, 4vw, 46px);
  overflow: hidden;
  border-radius: 30px;
  background: #f7f8f5;
  box-shadow: var(--shadow);
}

.stage {
  position: relative;
  max-width: 100%;
  max-height: calc(100vh - 245px);
  line-height: 0;
  user-select: none;
  touch-action: none;
  filter: drop-shadow(0 24px 44px rgba(54, 47, 35, 0.18));
}

.layer-image {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border-radius: 6px;
  object-fit: fill;
  transition: opacity 140ms ease, transform 140ms ease;
  filter: saturate(1.04) contrast(1.02);
}

.base-image {
  position: relative;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 245px);
  object-fit: contain;
}

.mask {
  position: absolute;
  z-index: 5;
  background: rgba(20, 22, 18, 0.48);
  pointer-events: none;
}

.mask.top {
  top: 0;
  left: 0;
  right: 0;
}

.mask.bottom {
  left: 0;
  right: 0;
}

.mask.left {
  left: 0;
}

.crop-box {
  position: absolute;
  z-index: 8;
  border: 1.5px solid #ffffff;
  box-shadow: 0 0 0 1px rgba(79, 107, 47, 0.74);
  cursor: move;
  touch-action: none;
}

.crop-box::before,
.crop-box::after {
  position: absolute;
  content: "";
  pointer-events: none;
}

.crop-box::before {
  left: 33.333%;
  top: 0;
  bottom: 0;
  width: 33.333%;
  border-left: 1px solid rgba(255, 253, 246, 0.58);
  border-right: 1px solid rgba(255, 253, 246, 0.58);
}

.crop-box::after {
  top: 33.333%;
  left: 0;
  right: 0;
  height: 33.333%;
  border-top: 1px solid rgba(255, 253, 246, 0.58);
  border-bottom: 1px solid rgba(255, 253, 246, 0.58);
}

.handle,
.edge {
  position: absolute;
  z-index: 9;
  display: block;
}

.handle {
  width: 18px;
  height: 18px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--moss);
  box-shadow: 0 6px 16px rgba(79, 107, 47, 0.28);
}

.handle.nw {
  left: -10px;
  top: -10px;
  cursor: nwse-resize;
}

.handle.ne {
  right: -10px;
  top: -10px;
  cursor: nesw-resize;
}

.handle.sw {
  left: -10px;
  bottom: -10px;
  cursor: nesw-resize;
}

.handle.se {
  right: -10px;
  bottom: -10px;
  cursor: nwse-resize;
}

.edge.n,
.edge.s {
  left: 18px;
  right: 18px;
  height: 18px;
  cursor: ns-resize;
}

.edge.n {
  top: -10px;
}

.edge.s {
  bottom: -10px;
}

.edge.e,
.edge.w {
  top: 18px;
  bottom: 18px;
  width: 18px;
  cursor: ew-resize;
}

.edge.e {
  right: -10px;
}

.edge.w {
  left: -10px;
}

.empty-canvas {
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
}

.empty-canvas b {
  color: var(--ink);
  font-size: 1rem;
}

.canvas-tools {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  padding: 7px;
  background: #f7f8f5;
  backdrop-filter: none;
}

.canvas-tools span,
.canvas-tools code {
  flex: 0 0 auto;
  padding: 0 8px;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.canvas-tools code {
  color: var(--moss-dark);
}

.preview-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 28px 30px 34px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  transition: opacity 160ms ease, filter 160ms ease, background 160ms ease;
}

.preview-card.hidden {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0) 0 44%, rgba(79, 107, 47, 0.08) 44% 56%, rgba(255, 255, 255, 0) 56%),
    #f8f9f6;
  opacity: 0.58;
}

.preview-card.hidden > img {
  filter: grayscale(1);
  opacity: 0.46;
}

.preview-card > img {
  width: 72px;
  height: 72px;
}

.preview-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.76rem;
}

.preview-card a,
.eye-button,
.all-eye-button,
.base-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 10px;
  color: var(--moss-dark);
  text-decoration: none;
  background: #eef2e7;
}

.preview-card a {
  width: 34px;
  height: 34px;
  border-radius: 12px;
}

.eye-button {
  padding: 0;
  color: #a3a99a;
  background: transparent;
}

.base-button {
  width: 28px;
  height: 28px;
  padding: 0;
  color: #a3a99a;
  background: transparent;
}

.base-button.active {
  color: #fff;
  background: var(--moss);
}

.eye-button.visible {
  color: var(--moss-dark);
  background: #eef2e7;
}

.eye-button svg,
.all-eye-button svg,
.base-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.all-eye-button {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 7px;
  background: #743f36;
  color: #fff8ef !important;
}

.all-eye-button.will-show {
  background: var(--seal);
}

.all-eye-button svg {
  width: 15px;
  height: 15px;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .preview-panel {
    grid-column: auto;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .canvas-panel {
    min-height: 420px;
    padding: 18px;
  }

  .stage,
  .layer-image {
    max-height: 55vh;
  }

  .canvas-tools {
    justify-self: stretch;
    justify-content: flex-start;
    overflow-x: auto;
  }
}
