:root {
  color-scheme: light;
  --bg: #f2f4f1;
  --panel: #ffffff;
  --ink: #202124;
  --muted: #69706a;
  --line: #d8ded7;
  --accent: #0f7b6c;
  --accent-strong: #0a5f54;
  --danger: #bd3d31;
  --shadow: 0 14px 40px rgba(30, 38, 34, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Poppins", "Noto Sans JP", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 500;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  padding: 12px 8px;
  background: #28352f;
  border-right: 1px solid rgba(0, 0, 0, 0.18);
}

.tool-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: transparent;
  color: #f8fbf7;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.tool-button:hover,
.tool-button:focus-visible {
  border-color: rgba(255, 255, 255, 0.5);
  outline: none;
}

.tool-button.is-active {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

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

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  min-height: 64px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.control,
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.control select,
.command-button {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.control select {
  min-width: 110px;
  padding: 0 30px 0 10px;
}

input[type="color"] {
  width: 38px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.width-control {
  min-width: 178px;
}

.font-size-input {
  width: 62px;
}

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

output {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.number-input {
  width: 52px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 6px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.number-input:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.command-button {
  padding: 0 13px;
  cursor: pointer;
}

.menu-popover {
  position: relative;
}

.menu-popover summary {
  list-style: none;
}

.menu-popover summary::-webkit-details-marker {
  display: none;
}

.icon-menu-button,
.icon-command {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.icon-menu-button:hover,
.icon-menu-button:focus-visible,
.icon-command:hover,
.icon-command:focus-visible {
  border-color: var(--accent);
  color: var(--accent-strong);
  outline: none;
}

.align-icon {
  font-size: 20px;
  line-height: 1;
  transform: rotate(90deg);
}

.menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(2, 36px);
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.align-glyph {
  position: relative;
  display: block;
  width: 22px;
  height: 22px;
}

.align-glyph::before,
.align-glyph::after {
  content: "";
  position: absolute;
  background: currentColor;
}

.center-x::before {
  left: 10px;
  top: 2px;
  width: 2px;
  height: 18px;
}

.center-x::after {
  left: 3px;
  top: 5px;
  width: 16px;
  height: 12px;
  border: 2px solid currentColor;
  background: transparent;
}

.center-y::before {
  left: 2px;
  top: 10px;
  width: 18px;
  height: 2px;
}

.center-y::after {
  left: 5px;
  top: 3px;
  width: 12px;
  height: 16px;
  border: 2px solid currentColor;
  background: transparent;
}

.distribute-x,
.distribute-y {
  border: 0;
}

.distribute-x::before {
  left: 2px;
  top: 4px;
  width: 3px;
  height: 14px;
  box-shadow: 8px 0 0 currentColor, 16px 0 0 currentColor;
}

.distribute-x::after {
  left: 2px;
  top: 10px;
  width: 19px;
  height: 2px;
}

.distribute-y::before {
  left: 4px;
  top: 2px;
  width: 14px;
  height: 3px;
  box-shadow: 0 8px 0 currentColor, 0 16px 0 currentColor;
}

.distribute-y::after {
  left: 10px;
  top: 2px;
  width: 2px;
  height: 19px;
}

.command-button:hover,
.command-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent-strong);
  outline: none;
}

#clearButton:hover,
#clearButton:focus-visible {
  border-color: var(--danger);
  color: var(--danger);
}

.canvas-frame {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 10px;
  background-image:
    linear-gradient(#dfe5df 1px, transparent 1px),
    linear-gradient(90deg, #dfe5df 1px, transparent 1px);
  background-size: 24px 24px;
}

#board {
  display: block;
  background: #fffefb;
  border: 1px solid #ccd4cd;
  box-shadow: var(--shadow);
  cursor: crosshair;
  touch-action: none;
}

#board[data-tool="select"] {
  cursor: default;
}

#board[data-tool="eraser"] {
  cursor: cell;
}

#board[data-tool="text"] {
  cursor: text;
}

.text-editor {
  position: absolute;
  z-index: 3;
  min-width: 80px;
  min-height: 42px;
  margin: 0;
  padding: 0;
  border: 1px dashed #1677ff;
  outline: none;
  background: rgba(255, 254, 251, 0.84);
  color: #000;
  resize: none;
  overflow: hidden;
  line-height: 1.25;
  white-space: pre;
}

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

  .toolbar {
    padding: 8px 6px;
  }

  .tool-button {
    width: 40px;
    height: 40px;
  }

  .topbar {
    align-content: start;
    max-height: 156px;
    overflow-y: auto;
  }

  .canvas-frame {
    padding: 8px;
  }
}
