:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --panel: #ffffff;
  --text: #18202f;
  --muted: #6b7280;
  --line: #d8dde8;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --danger: #dc2626;
  --shadow: 0 -10px 30px rgba(17, 24, 39, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 100%;
}

.canvas-area {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 12px 12px 8px;
}

#drawingCanvas {
  display: block;
  width: 100%;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  touch-action: none;
  cursor: auto;
}

.image-status {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 24px;
  z-index: 2;
  display: none;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(17, 24, 39, 0.88);
  color: #ffffff;
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  pointer-events: auto;
}

.image-status.show {
  display: block;
}

.image-status.error {
  background: rgba(185, 28, 28, 0.94);
}

@media (hover: hover) and (pointer: fine) {
  #drawingCanvas.cursor-brush {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M4 25l3 3 16-16-3-3L4 25z' fill='%232563eb' stroke='%23111827' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M21 8l3-3 3 3-3 3z' fill='%23f59e0b' stroke='%23111827' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M4 25l-1 5 5-1z' fill='%23111827'/%3E%3C/svg%3E") 4 25, auto;
  }

  #drawingCanvas.cursor-eraser {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M6 22l12-12a4 4 0 015.7 0l2.3 2.3a4 4 0 010 5.7L17 27H9z' fill='%23fca5a5' stroke='%23111827' stroke-width='1.6' stroke-linejoin='round'/%3E%3Cpath d='M14 14l8 8' stroke='%23111827' stroke-width='1.4' stroke-linecap='round'/%3E%3Cpath d='M7 27h18' stroke='%23111827' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") 8 24, auto;
  }
}

.toolbar {
  flex: none;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.tool-row,
.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-row {
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

.tool-row::-webkit-scrollbar {
  display: none;
}

.control-row {
  justify-content: space-between;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.tool-button.active {
  border-color: var(--primary);
  background: #dbeafe;
  color: var(--primary-strong);
}

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

.tool-button.danger {
  color: var(--danger);
}

.control-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.color-control input {
  width: 38px;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.size-control {
  flex: 1;
}

.size-control input {
  flex: 1;
  min-width: 80px;
  accent-color: var(--primary);
}

.size-control output {
  width: 24px;
  color: var(--text);
  text-align: right;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

@media (min-width: 720px) {
  .app {
    max-width: 980px;
    margin: 0 auto;
  }

  .canvas-area {
    padding: 18px 18px 12px;
  }

  .toolbar {
    border-right: 1px solid var(--line);
    border-left: 1px solid var(--line);
    border-radius: 8px 8px 0 0;
  }

  .tool-row {
    justify-content: center;
  }

  .control-row {
    max-width: 640px;
    margin: 0 auto;
  }
}
