:root {
  color-scheme: light;
  font-family:
    "Inter", "Noto Sans JP", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #ecece7;
  color: #202326;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #ecece7;
  overflow-y: auto;
}

button,
input {
  font: inherit;
}

a {
  color: #176b62;
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(780px, 1080px) 390px;
  column-gap: 16px;
  justify-content: center;
  align-items: start;
  min-height: 100vh;
  padding: 22px;
}

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

.preview-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1.28fr) minmax(240px, 0.82fr);
  align-items: start;
  gap: 14px;
  min-height: auto;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(32, 35, 38, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(32, 35, 38, 0.04) 1px, transparent 1px),
    #f7f6f1;
  background-size: 28px 28px;
  border: 1px solid rgba(32, 35, 38, 0.12);
  border-radius: 10px;
}

.edit-tools {
  display: grid;
  grid-template-columns: minmax(320px, 1.25fr) 150px;
  gap: 12px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid rgba(32, 35, 38, 0.12);
  border-radius: 10px;
}

.tool-main {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 230px;
  gap: 12px;
  align-items: end;
}

.tool-row {
  display: grid;
  gap: 8px;
}

.preview-card {
  align-self: start;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  transition:
    border-color 0.18s ease,
    background 0.18s ease,
    opacity 0.18s ease;
}

.preview-card.active {
  order: 1;
  border-color: #176b62;
  background: rgba(255, 255, 255, 0.78);
}

.preview-card:not(.active) {
  order: 2;
  opacity: 0.82;
}

.preview-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #434a50;
  font-size: 13px;
}

.preview-head strong {
  color: #202326;
}

canvas {
  width: 100%;
  aspect-ratio: 2211 / 2069;
  display: block;
  background: #eeece5;
  border: 1px solid rgba(32, 35, 38, 0.16);
  box-shadow: 0 16px 50px rgba(32, 35, 38, 0.16);
  touch-action: none;
  cursor: grab;
}

canvas.dragging {
  cursor: grabbing;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: auto;
}

.control-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: #ffffff;
  border: 1px solid rgba(32, 35, 38, 0.12);
}

.setup-card {
  border-radius: 10px;
}

.submit-card {
  border-radius: 8px;
}

.brand-logo {
  display: block;
  width: min(100%, 213px);
  height: auto;
  margin-inline: auto;
  object-fit: contain;
}

.brand {
  text-align: center;
}

.brand p,
.hint,
.format-note,
.size-note,
.status-text {
  margin: 8px 0 0;
  color: #667078;
  font-size: 14px;
  line-height: 1.6;
}

.format-note {
  margin-top: -6px;
  padding: 12px;
  border-left: 3px solid #176b62;
  background: #f5f8f6;
  border-radius: 6px;
}

.size-note {
  margin-top: -10px;
  color: #7b858d;
  font-size: 12px;
  line-height: 1.5;
}

.status-text {
  min-height: 22px;
  color: #176b62;
  font-weight: 700;
}

.status-text.sending {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid rgba(23, 107, 98, 0.25);
  border-radius: 8px;
  background: #eef8f5;
}

.status-text.sending::before {
  content: "";
  width: 18px;
  height: 18px;
  border: 3px solid rgba(23, 107, 98, 0.22);
  border-top-color: #176b62;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.status-text.error {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 42px;
  margin: 6px 0 0;
  color: #c62323;
  text-align: center;
  font-size: 16px;
  line-height: 1.35;
  padding: 10px 12px;
  border: 1px solid rgba(198, 35, 35, 0.35);
  border-radius: 6px;
  background: #fff1f1;
}

.input-error {
  border-color: #c62323 !important;
  box-shadow: 0 0 0 3px rgba(198, 35, 35, 0.14);
}

.pulse {
  animation: pulse-alert 0.7s ease;
}

.shake {
  animation: shake-alert 0.35s ease;
}

@keyframes pulse-alert {
  0% {
    box-shadow: 0 0 0 0 rgba(198, 35, 35, 0.26);
  }
  45% {
    box-shadow: 0 0 0 5px rgba(198, 35, 35, 0.14);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(198, 35, 35, 0);
  }
}

@keyframes shake-alert {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

.control-group,
.control-grid label {
  display: grid;
  gap: 10px;
}

.edit-tools .measure-panel,
.edit-tools .control-grid,
.edit-tools .scale-tool,
.edit-tools .axis-tool {
  min-width: 0;
}

.label {
  color: #434a50;
  font-size: 13px;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: #e9edf0;
  border-radius: 8px;
}

.compact-segmented .segment {
  min-height: 36px;
}

.segmented.three {
  grid-template-columns: repeat(3, 1fr);
}

.segment {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  color: #4e5961;
  background: transparent;
  cursor: pointer;
}

.segment.active {
  color: #111517;
  background: #ffffff;
  box-shadow: 0 1px 8px rgba(32, 35, 38, 0.12);
}

.file-drop {
  position: relative;
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 14px;
  min-height: 80px;
  padding: 14px;
  border: 1px dashed #88939c;
  border-radius: 8px;
  background: #fbfbf8;
  cursor: pointer;
}

.file-drop input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: #ffffff;
  background: #176b62;
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.file-drop strong,
.file-drop small {
  display: block;
}

.file-drop small {
  margin-top: 3px;
  color: #667078;
}

input[type="range"] {
  width: 100%;
  accent-color: #176b62;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  grid-column: 1 / -1;
}

.measure-panel {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px;
  border: 1px solid #dce1e4;
  border-radius: 8px;
  background: #fbfbf8;
  grid-column: 1 / -1;
}

.measure-panel div {
  display: grid;
  gap: 3px;
  color: #667078;
  font-size: 12px;
}

.measure-panel strong {
  color: #202326;
  font-weight: 700;
  text-align: right;
}

input[type="number"],
input[type="text"] {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #cfd5d9;
  border-radius: 6px;
}

.nudge-panel {
  display: grid;
  gap: 6px;
  justify-items: center;
}

.nudge-grid {
  display: grid;
  grid-template-columns: repeat(3, 38px);
  grid-template-areas:
    ". up ."
    "left down right";
  gap: 5px;
  justify-content: center;
}

.icon-button {
  min-width: 38px;
  min-height: 34px;
  font-size: 17px;
  font-weight: 800;
}

[data-nudge="up"] {
  grid-area: up;
}

[data-nudge="left"] {
  grid-area: left;
}

[data-nudge="down"] {
  grid-area: down;
}

[data-nudge="right"] {
  grid-area: right;
}

.copyright-check {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid #dce1e4;
  border-radius: 8px;
  background: #fbfbf8;
  color: #434a50;
  font-size: 13px;
  line-height: 1.55;
}

.copyright-check input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: #176b62;
}

.copyright-link {
  margin-top: -8px;
  font-size: 13px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.design-name-action {
  margin-top: 6px;
  padding-top: 18px;
  border-top: 3px solid #244c9a;
  box-shadow: inset 0 1px 0 rgba(36, 76, 154, 0.12);
}

.placement-actions {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  grid-column: 1 / -1;
}

.placement-actions .secondary {
  min-width: 0;
}

.primary,
.secondary {
  min-height: 38px;
  border-radius: 6px;
  cursor: pointer;
}

.primary {
  border: 0;
  color: #ffffff;
  background: #176b62;
  font-weight: 700;
}

.primary:disabled {
  cursor: wait;
  opacity: 0.78;
}

.primary.drive {
  background: #244c9a;
}

.secondary {
  border: 1px solid #cfd5d9;
  color: #202326;
  background: #ffffff;
}

.mobile-edit-bar {
  display: none;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 0;
  }

  .preview-wrap {
    grid-template-columns: minmax(0, 1.24fr) minmax(170px, 0.76fr);
    min-height: auto;
    padding: 12px;
    border: 0;
    border-radius: 0;
  }

  .controls {
    min-height: auto;
    max-height: none;
  }

  .setup-card,
  .submit-card {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
}

@media (min-width: 1101px) {
  .controls {
    position: sticky;
    top: 22px;
  }

  .submit-card {
    position: relative;
    border: 2px solid rgba(36, 76, 154, 0.5);
    box-shadow:
      0 0 0 3px rgba(36, 76, 154, 0.08),
      0 12px 28px rgba(32, 35, 38, 0.12);
  }

  .submit-card::before {
    content: "配置が決まったら保存・送信";
    display: block;
    margin: -2px -2px 2px;
    padding: 8px 10px;
    color: #ffffff;
    background: #244c9a;
    border-radius: 6px 6px 0 0;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
  }
}

@media (max-width: 720px) {
  body {
    padding-bottom: 70px;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .controls {
    display: contents;
  }

  .setup-card {
    order: 1;
  }

  .workspace {
    order: 2;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .submit-card {
    order: 3;
  }

  .preview-wrap {
    grid-template-columns: 1fr;
    gap: 8px;
    align-items: start;
    padding: 8px;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .preview-card {
    gap: 6px;
    padding: 8px;
    min-width: 0;
    max-width: 100%;
  }

  .preview-card.active {
    width: 100%;
    max-width: 100%;
    border-width: 2px;
  }

  canvas {
    max-width: 100%;
  }

  .preview-card:not(.active) {
    align-self: start;
    justify-self: center;
    width: min(34%, 150px);
  }

  .preview-card:not(.active) .preview-head {
    display: block;
    font-size: 11px;
    line-height: 1.25;
  }

  .preview-card:not(.active) .preview-head span {
    display: none;
  }

  .preview-card:not(.active) canvas {
    box-shadow: none;
  }

  .controls {
    padding: 18px;
    gap: 18px;
  }

  .control-grid,
  .scale-tool,
  .axis-tool,
  .tool-main,
  .nudge-panel,
  .placement-actions {
    display: none;
  }

  .edit-tools {
    display: grid;
    width: 100%;
    max-width: 100vw;
    padding: 0 8px 8px;
    background: transparent;
    border: 0;
    border-radius: 0;
  }

  .measure-panel {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px;
    width: 100%;
    max-width: calc(100vw - 16px);
    min-width: 0;
  }

  .measure-panel div {
    font-size: 12px;
  }

  .measure-panel strong {
    font-size: 12px;
  }

  .brand-logo {
    width: min(66%, 213px);
    margin-inline: auto;
  }

  .brand p {
    text-align: center;
  }

  .actions {
    position: static;
    margin: 0;
    padding: 0;
    background: transparent;
    border-top: 0;
    backdrop-filter: none;
  }

  .mobile-edit-bar {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: 8px;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 8px;
    border: 2px solid #244c9a;
    border-radius: 10px;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(244, 248, 255, 0.98));
    box-shadow:
      0 0 0 3px rgba(36, 76, 154, 0.14),
      0 14px 38px rgba(32, 35, 38, 0.28);
    backdrop-filter: blur(10px);
    transform: translateY(calc(100% + 16px));
    transition: transform 0.18s ease;
  }

  body.mobile-edit-mode .mobile-edit-bar {
    transform: translateY(0);
  }

  .mobile-tool {
    min-height: 42px;
    padding: 0 6px;
    border: 1px solid #aebbd3;
    border-radius: 7px;
    color: #202326;
    background: #ffffff;
    font-size: 12px;
    font-weight: 700;
  }

  #mobileDoneButton {
    grid-column: 3 / 5;
  }

  #mobileDetailsButton {
    grid-column: 2 / 3;
  }

  #mobileFrontButton {
    grid-column: 1 / 3;
  }

  #mobileBackButton {
    grid-column: 3 / 5;
  }

  #mobileFitButton {
    grid-column: 1 / 2;
  }

  #mobileCenterButton {
    grid-column: 2 / 3;
  }

  #mobileHorizontalCenterButton {
    grid-column: 3 / 4;
  }

  #mobileTopButton {
    grid-column: 4 / 5;
  }

  #mobileResetButton {
    grid-column: 1 / 2;
  }

  .mobile-tool.active {
    color: #ffffff;
    border-color: #176b62;
    background: #176b62;
    box-shadow: 0 3px 10px rgba(23, 107, 98, 0.24);
  }

  .mobile-tool.return-tool {
    color: #ffffff;
    border-color: #244c9a;
    background: #244c9a;
    box-shadow: 0 3px 10px rgba(36, 76, 154, 0.24);
  }

  .mobile-tool.finish-tool {
    color: #ffffff;
    border-color: #2d3338;
    background: #2d3338;
    box-shadow: 0 3px 10px rgba(32, 35, 38, 0.28);
  }

  body.mobile-edit-mode .preview-wrap {
    position: sticky;
    top: 0;
    z-index: 10;
    background:
      linear-gradient(90deg, rgba(32, 35, 38, 0.04) 1px, transparent 1px),
      linear-gradient(rgba(32, 35, 38, 0.04) 1px, transparent 1px),
      #f7f6f1;
    box-shadow: 0 10px 28px rgba(32, 35, 38, 0.14);
  }

  body.mobile-edit-mode .preview-card.active canvas {
    width: 100%;
  }

  body.mobile-edit-mode .preview-head {
    font-size: 12px;
  }

  body.mobile-edit-mode .controls {
    padding-top: 12px;
  }

  body.mobile-edit-mode .setup-card,
  body.mobile-edit-mode .submit-card {
    display: none;
  }

  body.mobile-edit-mode .brand,
  body.mobile-edit-mode .format-note,
  body.mobile-edit-mode .size-note,
  body.mobile-edit-mode .control-grid,
  body.mobile-edit-mode .scale-tool,
  body.mobile-edit-mode .axis-tool,
  body.mobile-edit-mode .nudge-panel,
  body.mobile-edit-mode .placement-actions,
  body.mobile-edit-mode .hint {
    display: none;
  }
}
