:root {
  color-scheme: light;
  --ink: #20242a;
  --muted: #69717d;
  --line: #d9dde4;
  --panel: #ffffff;
  --field: #f4f7f8;
  --accent: #06c755;
  --accent-dark: #049a43;
  --danger: #e94444;
  --shadow: 0 18px 46px rgba(32, 36, 42, 0.13);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: "Segoe UI", "Yu Gothic UI", "Hiragino Sans", Meiryo, sans-serif;
  background: #eef2f3;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  min-height: 40px;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease, transform 120ms ease;
}

button:hover {
  border-color: var(--accent);
}

button:active {
  transform: translateY(1px);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  width: min(1440px, 100%);
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  padding: 16px;
  overflow: hidden;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.topbar,
.side-panel,
.canvas-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.25;
  letter-spacing: 0;
}

h2 {
  font-size: 14px;
  line-height: 1.3;
}

#statusText {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 18px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

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

.file-button input {
  display: none;
}

.drop-zone {
  min-height: 0;
  overflow: hidden;
}

.drop-zone.dragging .canvas-panel {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(6, 199, 85, 0.14);
}

.canvas-panel {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 18px;
  overflow: auto;
  overscroll-behavior: contain;
  box-shadow: var(--shadow);
}

.canvas-stage {
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
}

.canvas-stage.checker {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #dfe4e8 25%, transparent 25%),
    linear-gradient(-45deg, #dfe4e8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dfe4e8 75%),
    linear-gradient(-45deg, transparent 75%, #dfe4e8 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
}

.canvas-stage.white {
  background: #fff;
}

.canvas-stage.black {
  background: #111;
}

.canvas-stage.line {
  background: #06c755;
}

canvas {
  grid-area: 1 / 1;
  display: block;
  width: 1px;
  height: 1px;
}

#maskCanvas {
  pointer-events: none;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  padding: 14px;
  overflow: auto;
}

.tool-group {
  display: grid;
  gap: 10px;
}

.tool-grid,
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tool.active,
.preview.active {
  border-color: var(--accent);
  background: #e8fff1;
  color: #026c30;
  font-weight: 700;
}

.range-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.range-row b {
  color: var(--ink);
  text-align: right;
}

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

.swatch-row,
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

#colorSwatch {
  width: 42px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.segmented button {
  min-height: 36px;
  font-size: 13px;
}

.pan-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.pan-grid button {
  min-height: 34px;
}

.toggle-row {
  justify-content: flex-start;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

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

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100dvh;
    padding: 10px;
    overflow: visible;
  }

  .side-panel {
    overflow: visible;
  }

  .canvas-panel {
    height: 58vh;
    min-height: 360px;
  }

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