:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #697386;
  --line: #d9e1ec;
  --panel: #ffffff;
  --page: #f4f7fb;
  --tool: #eef3f8;
  --accent: #0f9f8f;
  --accent-dark: #08796e;
  --blue: #2563eb;
  --coral: #df5b45;
  --yellow: #f5b841;
  --shadow: 0 18px 45px rgba(23, 32, 51, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--page);
  color: var(--ink);
  font-family:
    "Yu Gothic UI",
    "Hiragino Sans",
    "Meiryo",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.topbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  padding: 12px 18px;
  position: sticky;
  top: 0;
  z-index: 5;
}

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

.brand-mark {
  background:
    linear-gradient(135deg, var(--accent) 0 48%, transparent 48%),
    linear-gradient(315deg, var(--yellow) 0 48%, transparent 48%),
    linear-gradient(45deg, var(--blue), var(--coral));
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
  display: inline-block;
  height: 34px;
  width: 34px;
}

.brand h1 {
  font-size: 1rem;
  letter-spacing: 0;
  line-height: 1.1;
  margin: 0;
}

.brand p {
  color: var(--muted);
  font-size: 0.76rem;
  margin: 2px 0 0;
}

.top-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.mobile-panel-tabs,
.mobile-sheet-scrim {
  display: none;
}

.button,
.icon-action {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  min-height: 38px;
  padding: 8px 12px;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    transform 140ms ease;
  white-space: nowrap;
}

.button:hover,
.icon-action:hover {
  border-color: #9fb0c6;
  transform: translateY(-1px);
}

.button:disabled,
.icon-action:disabled {
  cursor: not-allowed;
  opacity: 0.46;
  transform: none;
}

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

.button.primary:hover {
  background: var(--accent-dark);
}

.button.compact,
.icon-action {
  min-height: 32px;
  padding: 6px 9px;
}

.icon-action.danger {
  color: #b33121;
}

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

.tool-rail {
  align-content: start;
  background: #fbfcfe;
  border-right: 1px solid var(--line);
  display: grid;
  gap: 8px;
  padding: 12px 10px;
}

.tool-button {
  align-items: center;
  aspect-ratio: 1 / 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  justify-items: center;
  min-height: 54px;
  padding: 5px;
}

.tool-button span {
  color: var(--ink);
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0;
}

.tool-button small {
  font-size: 0.71rem;
  font-weight: 700;
  line-height: 1;
}

.tool-button:hover,
.tool-button.active {
  background: var(--tool);
  border-color: #c9d7e7;
  color: var(--ink);
}

.tool-button.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.stage-panel {
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto;
  min-width: 0;
  overflow: hidden;
}

.canvas-toolbar {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px;
}

.canvas-toolbar label,
.properties label {
  color: var(--muted);
  display: grid;
  font-size: 0.76rem;
  font-weight: 700;
  gap: 4px;
}

.canvas-toolbar input[type="number"] {
  width: 86px;
}

.background-controls,
.brush-controls {
  align-items: center;
  border-left: 1px solid var(--line);
  display: flex;
  gap: 10px;
  margin-left: 4px;
  padding-left: 12px;
}

.background-controls .check-label {
  align-self: end;
  min-height: 34px;
}

input,
select,
textarea {
  background: #ffffff;
  border: 1px solid #c8d3e2;
  border-radius: 7px;
  color: var(--ink);
  min-height: 34px;
  padding: 6px 8px;
}

input[type="range"] {
  accent-color: var(--accent);
  min-height: 24px;
  padding: 0;
}

input[type="color"] {
  min-width: 46px;
  padding: 3px;
}

textarea {
  min-height: 76px;
  resize: vertical;
}

.canvas-shell {
  align-items: center;
  background-color: #e8edf4;
  background-image:
    linear-gradient(45deg, #cfd8e5 25%, transparent 25%),
    linear-gradient(-45deg, #cfd8e5 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #cfd8e5 75%),
    linear-gradient(-45deg, transparent 75%, #cfd8e5 75%);
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  background-size: 16px 16px;
  display: flex;
  justify-content: center;
  min-height: 0;
  overflow: auto;
  padding: 22px;
}

.canvas-shell.is-dragging {
  outline: 3px solid rgba(15, 159, 143, 0.45);
  outline-offset: -8px;
}

#editorCanvas {
  background-color: #fbfdff;
  background-image:
    linear-gradient(45deg, #e0e7f0 25%, transparent 25%),
    linear-gradient(-45deg, #e0e7f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e0e7f0 75%),
    linear-gradient(-45deg, transparent 75%, #e0e7f0 75%);
  background-position:
    0 0,
    0 9px,
    9px -9px,
    -9px 0;
  background-size: 18px 18px;
  border: 2px solid #172033;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.9),
    0 0 0 7px rgba(15, 159, 143, 0.16),
    var(--shadow);
  display: block;
  max-height: 100%;
  max-width: 100%;
  touch-action: none;
}

.crop-actions {
  align-items: center;
  background: #ffffff;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 10px;
}

.side-panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: grid;
  grid-template-rows: minmax(210px, 42%) 1fr;
  min-height: 0;
  overflow: hidden;
}

.panel-section {
  border-bottom: 1px solid var(--line);
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

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

.section-title h2 {
  font-size: 0.92rem;
  letter-spacing: 0;
  margin: 0;
}

.mini-actions {
  display: flex;
  gap: 6px;
}

.layer-list {
  display: grid;
  gap: 8px;
}

.layer-row {
  align-items: center;
  background: #f8fafc;
  border: 1px solid #dfe7f2;
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: 34px 1fr auto;
  min-height: 54px;
  padding: 7px;
}

.layer-row.is-active {
  background: #edf8f7;
  border-color: rgba(15, 159, 143, 0.55);
}

.layer-thumb {
  align-items: center;
  background:
    linear-gradient(45deg, #dce4ef 25%, transparent 25%),
    linear-gradient(-45deg, #dce4ef 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dce4ef 75%),
    linear-gradient(-45deg, transparent 75%, #dce4ef 75%),
    #ffffff;
  background-position:
    0 0,
    0 5px,
    5px -5px,
    -5px 0;
  background-size: 10px 10px;
  border: 1px solid #cbd7e5;
  border-radius: 6px;
  display: flex;
  height: 34px;
  justify-content: center;
  overflow: hidden;
  width: 34px;
}

.layer-thumb img {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.layer-thumb span {
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 900;
}

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

.layer-name {
  color: var(--ink);
  display: block;
  font-size: 0.84rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-meta {
  color: var(--muted);
  display: block;
  font-size: 0.72rem;
  margin-top: 2px;
}

.layer-buttons {
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(2, 32px);
}

.layer-buttons button {
  background: #ffffff;
  border: 1px solid #d7e0eb;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  min-height: 26px;
  padding: 2px;
}

.layer-buttons button:hover {
  border-color: #93a4bb;
  color: var(--ink);
}

.properties {
  display: grid;
  gap: 14px;
}

.empty-state {
  background: #f5f7fb;
  border: 1px dashed #b9c7d8;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  padding: 14px;
  text-align: center;
}

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

.span-2 {
  grid-column: 1 / -1;
}

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

.property-block {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  padding-top: 13px;
}

.property-block h3 {
  color: var(--ink);
  font-size: 0.82rem;
  letter-spacing: 0;
  margin: 0;
}

.shadow-controls,
.outline-controls {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding-top: 12px;
}

.check-label {
  align-items: center;
  color: var(--ink);
  display: flex !important;
  flex-direction: row;
  font-size: 0.82rem !important;
  gap: 8px !important;
  grid-column: 1 / -1;
}

.check-label input {
  min-height: auto;
}

.properties.is-empty [data-prop-group] {
  display: none;
}

.properties:not(.is-empty) .empty-state {
  display: none;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 70px minmax(300px, 1fr);
    grid-template-rows: minmax(430px, 1fr) minmax(320px, auto);
  }

  .side-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    grid-column: 1 / -1;
    grid-template-columns: minmax(280px, 42%) 1fr;
    grid-template-rows: auto;
    max-height: 42vh;
  }

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

@media (max-width: 760px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .topbar {
    align-items: stretch;
    display: grid;
    gap: 10px;
    padding: 10px;
    z-index: 35;
  }

  .brand {
    min-width: 0;
  }

  .brand-mark {
    height: 30px;
    width: 30px;
  }

  .brand p {
    display: none;
  }

  .top-actions {
    flex-wrap: nowrap;
    justify-content: start;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .top-actions .button {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 6px 10px;
  }

  .mobile-panel-tabs {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mobile-panel-button.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
  }

  .workspace {
    display: block;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .tool-rail {
    background: rgba(255, 255, 255, 0.97);
    border-bottom: 0;
    border-right: 0;
    border-top: 1px solid var(--line);
    bottom: 0;
    box-shadow: 0 -12px 30px rgba(23, 32, 51, 0.12);
    display: flex;
    gap: 8px;
    left: 0;
    overflow-x: auto;
    padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
    position: fixed;
    right: 0;
    z-index: 30;
  }

  .tool-button {
    flex: 0 0 62px;
    min-height: 58px;
  }

  .stage-panel {
    height: 100%;
    min-height: 0;
    padding-bottom: calc(78px + env(safe-area-inset-bottom));
  }

  .canvas-toolbar {
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 8px 10px;
  }

  .canvas-toolbar label {
    flex: 0 0 auto;
  }

  .canvas-toolbar input[type="number"] {
    width: 76px;
  }

  .background-controls,
  .brush-controls {
    border-left: 0;
    flex: 0 0 auto;
    margin-left: 0;
    padding-left: 0;
  }

  .canvas-shell {
    min-height: 0;
    padding: 12px;
  }

  .side-panel {
    background: var(--panel);
    border-left: 0;
    border-radius: 12px 12px 0 0;
    border-top: 1px solid var(--line);
    bottom: calc(76px + env(safe-area-inset-bottom));
    box-shadow: 0 -18px 45px rgba(23, 32, 51, 0.18);
    display: block;
    left: 0;
    max-height: min(62dvh, 540px);
    overflow: hidden;
    position: fixed;
    right: 0;
    transform: translateY(calc(100% + 12px));
    transition: transform 180ms ease;
    z-index: 25;
  }

  body.mobile-sheet-open .side-panel {
    transform: translateY(0);
  }

  .panel-section {
    border-right: 0;
    max-height: min(62dvh, 540px);
    overflow: auto;
    padding: 14px 14px calc(18px + env(safe-area-inset-bottom));
  }

  body[data-mobile-panel="layers"] [data-mobile-panel-content="properties"],
  body[data-mobile-panel="properties"] [data-mobile-panel-content="layers"],
  body[data-mobile-panel="closed"] .side-panel {
    display: none;
  }

  body[data-mobile-panel="layers"] [data-mobile-panel-content="layers"],
  body[data-mobile-panel="properties"] [data-mobile-panel-content="properties"] {
    display: block;
  }

  .mobile-sheet-scrim {
    background: rgba(23, 32, 51, 0.18);
    border: 0;
    bottom: calc(76px + env(safe-area-inset-bottom));
    display: block;
    left: 0;
    padding: 0;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 22;
  }

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

  .property-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .layer-row {
    min-height: 60px;
  }

  .layer-buttons {
    grid-template-columns: repeat(2, 38px);
  }

  .layer-buttons button {
    min-height: 30px;
  }
}
