:root {
  color-scheme: light;
  --ink: #16243c;
  --ink-soft: #586174;
  --paper: #f6f1e7;
  --card: #fffdf8;
  --line: #dcd5c8;
  --line-dark: #bdb6aa;
  --red: #ef4e3a;
  --yellow: #f1bd38;
  --blue: #2f6fd6;
  --shadow: 5px 5px 0 rgba(22, 36, 60, 0.11);
  font-family: system-ui, -apple-system, "Noto Sans JP", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--paper);
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 11%, rgba(239, 78, 58, 0.07) 0 3px, transparent 4px),
    radial-gradient(circle at 88% 85%, rgba(47, 111, 214, 0.07) 0 3px, transparent 4px),
    var(--paper);
  background-size: 32px 32px, 38px 38px, auto;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
label:has(input:focus-visible) {
  outline: 3px solid rgba(47, 111, 214, 0.35);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 0 24px 42px;
}

.site-header {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line-dark);
}

.brand {
  display: grid;
  grid-template-columns: 30px auto;
  grid-template-rows: auto auto;
  column-gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  grid-row: 1 / 3;
  align-self: center;
  display: grid;
  grid-template-columns: repeat(3, 7px);
  gap: 2px;
  transform: rotate(-7deg);
}

.brand-mark i {
  width: 7px;
  height: 7px;
  background: var(--ink);
}

.brand-mark i:nth-child(1),
.brand-mark i:nth-child(3),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(5),
.brand-mark i:nth-child(7) {
  background: var(--red);
}

.brand-name {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
}

.brand-tag,
.eyebrow {
  font-family: "DM Mono", monospace;
  letter-spacing: 0.14em;
}

.brand-tag {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 8px;
  line-height: 1;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-button,
.save-button,
.mini-button,
.tool-button,
.size-options button,
.export-button {
  border: 1.5px solid var(--ink);
  background: var(--card);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.icon-button:active,
.save-button:active,
.mini-button:active,
.tool-button:active,
.size-options button:active,
.export-button:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  box-shadow: 2px 2px 0 rgba(22, 36, 60, 0.12);
}

.icon-button:disabled {
  opacity: 0.34;
  cursor: default;
}

.install-button {
  color: white;
  background: var(--red);
  box-shadow: 2px 2px 0 #ba3023;
}

.icon-button svg,
.save-button svg,
.project-name svg,
.tool-icon svg,
.current-color svg,
.setting-icon svg,
.export-button svg,
.canvas-hint svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: square;
  stroke-linejoin: miter;
  stroke-width: 1.8;
}

.save-button {
  min-width: 94px;
  height: 42px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 4px;
  color: white;
  font-size: 13px;
  font-weight: 700;
  background: var(--ink);
  box-shadow: 3px 3px 0 rgba(22, 36, 60, 0.18);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 0.78fr);
  gap: 32px;
  padding-top: 28px;
}

.editor-column,
.controls-column {
  min-width: 0;
}

.project-row {
  min-height: 40px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.project-name {
  max-width: 70%;
  display: flex;
  align-items: center;
  gap: 6px;
}

.project-name input {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  border-bottom: 1px dashed transparent;
  color: var(--ink);
  background: transparent;
  font-size: 18px;
  font-weight: 700;
}

.project-name input:hover,
.project-name input:focus {
  border-bottom-color: var(--line-dark);
  outline: 0;
}

.project-name svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--ink-soft);
}

.canvas-meta {
  padding: 6px 9px;
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line-dark);
  border-radius: 3px;
  background: rgba(255, 253, 248, 0.72);
  font-family: "DM Mono", monospace;
  font-size: 11px;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  background: #44a874;
  box-shadow: 0 0 0 2px rgba(68, 168, 116, 0.16);
}

.canvas-card {
  position: relative;
  padding: clamp(14px, 3vw, 28px);
  border: 1.5px solid var(--ink);
  background: #ddd6c9;
  box-shadow: var(--shadow);
}

.canvas-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image: linear-gradient(45deg, #aaa 25%, transparent 25%), linear-gradient(-45deg, #aaa 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #aaa 75%), linear-gradient(-45deg, transparent 75%, #aaa 75%);
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
  background-size: 10px 10px;
}

.canvas-wrap {
  position: relative;
  width: min(100%, 590px);
  margin: 0 auto;
  border: 2px solid var(--ink);
  background-color: #fff;
  background-image: linear-gradient(45deg, #ececec 25%, transparent 25%), linear-gradient(-45deg, #ececec 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ececec 75%), linear-gradient(-45deg, transparent 75%, #ececec 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  box-shadow: 0 0 0 5px rgba(255, 253, 248, 0.48);
  touch-action: none;
  user-select: none;
}

#pixelCanvas {
  width: 100%;
  aspect-ratio: 1;
  display: block;
  cursor: crosshair;
  image-rendering: pixelated;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.canvas-hint {
  position: relative;
  margin: 17px 0 -5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #5d5d5d;
  font-size: 11px;
  font-weight: 600;
}

.canvas-hint svg {
  width: 17px;
  height: 17px;
}

.canvas-corner {
  position: absolute;
  z-index: 2;
  width: 14px;
  height: 14px;
  border-color: var(--red);
}

.corner-top-left { top: 8px; left: 8px; border-top: 3px solid; border-left: 3px solid; }
.corner-top-right { top: 8px; right: 8px; border-top: 3px solid; border-right: 3px solid; }
.corner-bottom-left { bottom: 8px; left: 8px; border-bottom: 3px solid; border-left: 3px solid; }
.corner-bottom-right { right: 8px; bottom: 8px; border-right: 3px solid; border-bottom: 3px solid; }

.tool-dock {
  width: min(480px, calc(100% - 24px));
  margin: -1px auto 0;
  padding: 9px;
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  border: 1.5px solid var(--ink);
  background: var(--card);
  box-shadow: 4px 4px 0 rgba(22, 36, 60, 0.1);
}

.tool-button {
  min-width: 0;
  min-height: 62px;
  padding: 7px 4px 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-color: transparent;
  border-radius: 3px;
  color: var(--ink-soft);
  background: transparent;
  box-shadow: none;
  font-size: 10px;
  font-weight: 700;
}

.tool-button.is-active {
  border-color: var(--ink);
  color: white;
  background: var(--ink);
  box-shadow: 2px 2px 0 rgba(22, 36, 60, 0.16);
}

.tool-icon {
  display: grid;
  place-items: center;
}

.tool-icon svg {
  width: 22px;
  height: 22px;
}

.controls-column {
  padding-top: 56px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  padding: 17px;
  border: 1.5px solid var(--ink);
  background: var(--card);
  box-shadow: 3px 3px 0 rgba(22, 36, 60, 0.09);
}

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

.compact-heading {
  margin-bottom: 13px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--red);
  font-size: 8px;
  font-weight: 500;
}

.panel h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.mini-button {
  min-height: 34px;
  padding: 0 11px;
  border-color: var(--line-dark);
  border-radius: 3px;
  color: var(--ink-soft);
  background: transparent;
  font-size: 10px;
  font-weight: 700;
}

.preview-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.preview-box {
  flex: 0 0 auto;
  width: 78px;
  padding: 7px;
  border: 1px solid var(--line-dark);
  background-color: #fff;
  background-image: linear-gradient(45deg, #ececec 25%, transparent 25%), linear-gradient(-45deg, #ececec 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ececec 75%), linear-gradient(-45deg, transparent 75%, #ececec 75%);
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  background-size: 8px 8px;
}

#previewCanvas {
  width: 100%;
  display: block;
  image-rendering: pixelated;
}

.preview-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.preview-copy strong {
  font-family: "DM Mono", monospace;
  font-size: 12px;
}

.preview-copy span {
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.7;
}

.current-color {
  position: relative;
  height: 35px;
  min-width: 76px;
  padding: 5px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line-dark);
  cursor: pointer;
}

.current-color span {
  width: 21px;
  height: 21px;
  border: 1px solid var(--ink);
  background: var(--red);
}

.current-color input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.current-color svg {
  width: 13px;
  height: 13px;
}

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

.swatch {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border: 1.5px solid var(--ink);
  border-radius: 1px;
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(22, 36, 60, 0.1);
}

.swatch.is-active::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 2px solid var(--ink);
  pointer-events: none;
}

.setting-block {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.setting-label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 700;
}

.size-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.size-options button {
  min-height: 38px;
  border-color: var(--line-dark);
  border-radius: 2px;
  color: var(--ink-soft);
  font-family: "DM Mono", monospace;
  font-size: 11px;
  box-shadow: none;
}

.size-options button::after {
  content: "×" attr(data-size);
  margin-left: 1px;
}

.size-options button.is-active {
  border-color: var(--ink);
  color: white;
  background: var(--ink);
}

.toggle-row {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.toggle-row:last-child {
  border-bottom: 0;
}

.toggle-label {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.toggle-label > span:nth-child(2) {
  display: flex;
  flex-direction: column;
}

.toggle-label strong {
  font-size: 11px;
}

.toggle-label small {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 8px;
}

.setting-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-dark);
  background: #f4f0e7;
}

.setting-icon svg {
  width: 17px;
  height: 17px;
}

.switch {
  width: 39px;
  height: 22px;
  margin: 0;
  position: relative;
  flex: 0 0 auto;
  appearance: none;
  border: 1.5px solid var(--ink);
  border-radius: 0;
  background: #d9d3c8;
  cursor: pointer;
  transition: background 120ms ease;
}

.switch::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 13px;
  height: 13px;
  background: white;
  border: 1px solid var(--ink);
  transition: transform 120ms ease;
}

.switch:checked {
  background: var(--red);
}

.switch:checked::before {
  transform: translateX(16px);
}

.export-button {
  min-height: 62px;
  padding: 10px 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 3px;
  color: white;
  background: var(--red);
  box-shadow: 4px 4px 0 #ba3023;
}

.export-button > span {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 800;
}

.export-button small {
  opacity: 0.75;
  font-size: 8px;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  color: white;
  background: var(--ink);
  border: 1px solid white;
  box-shadow: 4px 4px 0 rgba(22, 36, 60, 0.2);
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 860px) {
  .app-shell {
    padding-inline: 18px;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    gap: 22px;
  }

  .controls-column {
    padding-top: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-panel,
  .export-button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 0 12px calc(26px + env(safe-area-inset-bottom));
  }

  .site-header {
    min-height: 68px;
  }

  .brand-mark {
    grid-template-columns: repeat(3, 6px);
    gap: 1.5px;
  }

  .brand-mark i {
    width: 6px;
    height: 6px;
  }

  .brand-name {
    font-size: 18px;
  }

  .brand-tag {
    font-size: 7px;
  }

  .header-actions {
    gap: 5px;
  }

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

  .save-button {
    min-width: 73px;
    padding-inline: 11px;
  }

  .save-button svg {
    display: none;
  }

  .workspace {
    padding-top: 17px;
  }

  .project-row {
    margin-bottom: 11px;
  }

  .project-name input {
    font-size: 15px;
  }

  .canvas-card {
    padding: 14px;
    box-shadow: 4px 4px 0 rgba(22, 36, 60, 0.11);
  }

  .canvas-wrap {
    box-shadow: 0 0 0 3px rgba(255, 253, 248, 0.48);
  }

  .canvas-hint {
    margin-top: 13px;
    font-size: 9px;
  }

  .tool-dock {
    width: calc(100% - 18px);
    padding: 6px;
    gap: 3px;
  }

  .tool-button {
    min-height: 58px;
    font-size: 9px;
  }

  .controls-column {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .settings-panel,
  .export-button {
    grid-column: auto;
  }

  .panel {
    padding: 15px;
  }

  .palette {
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
  }

  .export-button {
    position: sticky;
    z-index: 5;
    bottom: max(10px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 360px) {
  .brand-tag {
    display: none;
  }

  .brand {
    grid-template-rows: 1fr;
  }

  .brand-mark {
    grid-row: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
