:root {
  --bg: #f3f1eb;
  --panel: #ffffff;
  --ink: #171512;
  --muted: #6f6a5f;
  --line: #d8d2c5;
  --accent: #1d6a73;
  --accent-dark: #124e56;
  --warning: #9c5a20;
  --shadow: 0 18px 40px rgba(30, 24, 15, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  border-color: #b9ad9b;
  background: #fff9ec;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

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

button.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

button.wide-button {
  width: 100%;
  margin-top: 10px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  min-height: 100vh;
  padding: 20px;
}

.workspace,
.controls {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

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

.workspace-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.25;
}

h2 {
  margin-bottom: 12px;
  font-size: 16px;
}

.workspace-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.preview-frame {
  min-height: 0;
  overflow: auto;
  padding: 22px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    #ebe7dc;
  background-size: 24px 24px;
}

.preview-mount {
  width: 100%;
  min-width: 0;
}

.preview-mount svg {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.16);
}

.preview-mount svg [data-panel-id] {
  cursor: pointer;
}

.preview-mount svg [data-panel-id]:hover > rect:last-child {
  stroke: var(--accent);
  stroke-width: 2.2;
}

.controls {
  overflow: auto;
  padding: 18px;
}

.dimension-settings {
  display: none;
}

.controls section + section {
  margin-top: 26px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.controls .dimension-settings + section {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.section-note {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.file-input-host {
  display: grid;
  gap: 14px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

input[type="range"] {
  width: 100%;
}

input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input[type="file"] {
  width: 100%;
  color: var(--muted);
  font-size: 12px;
}

.panel-controls {
  display: grid;
  gap: 14px;
}

.panel-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  padding: 12px;
  transition:
    border-color 0.16s ease,
    background-color 0.16s ease,
    box-shadow 0.16s ease;
}

.panel-editor.is-dragging {
  border-color: var(--accent);
  background: #eef8f6;
  box-shadow: 0 0 0 3px rgba(29, 106, 115, 0.14);
}

.panel-editor.has-image {
  border-color: rgba(29, 106, 115, 0.5);
  background: #f4fbf8;
}

.panel-editor.has-ratio-warning {
  border-color: rgba(156, 90, 32, 0.65);
  background: #fff8eb;
}

.panel-editor.has-image .drop-hint {
  color: var(--accent-dark);
  font-weight: 700;
}

.panel-editor.has-ratio-warning .drop-hint {
  color: var(--warning);
}

.panel-editor header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-editor strong {
  font-size: 14px;
}

.panel-editor .row {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 10px;
  align-items: end;
  margin-top: 10px;
}

.panel-editor .select-row {
  margin-top: 10px;
}

.panel-editor .client-hidden {
  display: none;
}

.panel-editor .range-row {
  display: grid;
  grid-template-columns: 1fr 58px;
  gap: 10px;
  align-items: center;
  margin-top: 9px;
}

.panel-editor .range-row span,
.preview-zoom-row span,
.guide-opacity-row span {
  color: var(--ink);
  font-size: 12px;
  text-align: right;
}

.panel-editor .range-row span.is-disabled,
.preview-zoom-row span.is-disabled,
.guide-opacity-row span.is-disabled {
  color: var(--muted);
  opacity: 0.7;
}

.preview-zoom-row,
.guide-opacity-row {
  display: grid;
  grid-template-columns: 1fr 58px;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}

.preset-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.preset-actions button {
  min-height: 36px;
  padding: 0 10px;
  font-size: 13px;
}

.preset-actions button.is-active {
  border-color: var(--accent);
  background: #eaf6f4;
  color: var(--accent-dark);
  font-weight: 700;
}

.view-mode-status {
  margin-top: 8px;
  border-left: 3px solid var(--accent);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
  padding-left: 9px;
}

.view-mode-status.is-clean {
  border-left-color: var(--muted);
  color: var(--muted);
}

.view-mode-status.is-custom {
  border-left-color: var(--warning);
  color: var(--warning);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
}

.check-row + .check-row {
  margin-top: 10px;
}

.drop-hint {
  color: var(--warning);
  font-size: 12px;
  line-height: 1.45;
  margin-top: 8px;
}

.layout-size {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8f4eb;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
  padding: 10px 12px;
}

.layout-size.is-changed {
  border-color: rgba(156, 90, 32, 0.55);
  background: #fff3dc;
}

.filename-preview {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.filename-preview.is-large {
  color: var(--warning);
  font-weight: 700;
}

.image-status {
  min-height: 20px;
  margin-top: 12px;
  border-left: 3px solid var(--warning);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
  padding-left: 9px;
}

.image-status.is-ready {
  border-left-color: var(--accent);
}

.image-status.is-large {
  border-left-color: var(--warning);
  color: var(--warning);
  font-weight: 700;
}

.save-status {
  min-height: 18px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

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

  .controls {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
  }

  .workspace-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .actions button {
    min-width: 0;
    padding: 0 8px;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .preview-frame {
    padding: 12px;
  }

  .panel-editor .row {
    grid-template-columns: 1fr;
  }

  .panel-editor .row button {
    width: 100%;
  }

  .panel-editor header {
    display: grid;
    grid-template-columns: 1fr;
  }

  .panel-editor header button {
    width: 100%;
  }
}
