:root {
  color-scheme: light;
  font-family: "Yu Gothic UI", "Meiryo", sans-serif;
  color: #1f2933;
  background: #eef1f4;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: #eef1f4;
}

button, input, select { font: inherit; }

.app-header {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  color: #fff;
  background: #27313b;
  border-bottom: 3px solid #d55428;
}

.app-header h1 { margin: 0; font-size: 20px; letter-spacing: 0; }
.app-header p { display: inline; margin: 0 0 0 8px; color: #c9d2da; font-size: 12px; }
.save-state { color: #dce4ea; font-size: 12px; }

.workspace {
  min-height: calc(100vh - 58px);
  display: grid;
  grid-template-columns: minmax(400px, 470px) minmax(520px, 1fr);
  align-items: start;
  gap: 10px;
  padding: 10px;
}

.controls, .preview-panel {
  min-width: 0;
  background: #fff;
  border: 1px solid #cbd2d9;
}

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

.result-head { min-height: 68px; border-bottom: 1px solid #d9dee3; margin-bottom: 9px; }
.fit-result { display: block; font-size: 23px; color: #111827; }
.fit-result.ok { color: #176b3a; }
.fit-result.error { color: #b42318; }
.result-head p { margin: 5px 0 9px; font-size: 13px; line-height: 1.45; }

fieldset {
  min-width: 0;
  margin: 0 0 8px;
  padding: 8px;
  border: 1px solid #c9d0d7;
}

legend { padding: 0 5px; font-weight: 700; color: #34404b; }

.margin-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; text-align: center; }
.margin-grid strong { font-size: 14px; white-space: nowrap; }
.blank-ratio { margin-top: 7px; text-align: center; color: #b42318; font-size: 17px; font-weight: 700; }

.preset-list { margin-bottom: 8px; }
.preset-row {
  display: grid;
  grid-template-columns: 76px minmax(120px, 1fr) 58px 58px;
  gap: 6px;
  align-items: center;
  margin-bottom: 5px;
}

label { font-size: 13px; font-weight: 600; }

input, select {
  width: 100%;
  height: 30px;
  padding: 3px 7px;
  color: #17212b;
  background: #fff;
  border: 1px solid #9da8b3;
  border-radius: 3px;
}

input:focus, select:focus, button:focus-visible {
  outline: 2px solid #2176ae;
  outline-offset: 1px;
}

button {
  min-height: 30px;
  padding: 4px 10px;
  color: #fff;
  background: #2f6f9f;
  border: 1px solid #225a84;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover { background: #275f89; }
button:active { transform: translateY(1px); }
button.secondary { color: #24313c; background: #f5f7f8; border-color: #aeb7bf; }
button.secondary:hover { background: #e8edf0; }

.important-settings { border-color: #d78c83; }
.important-settings > legend { color: #b42318; font-size: 14px; }
.important-settings .field-grid > label:not(.check-label) { color: #b42318; font-weight: 700; }
.important-settings input, .important-settings select { font-size: 15px; font-weight: 700; }

.field-grid {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) 92px minmax(0, 1fr);
  gap: 6px 8px;
  align-items: center;
}

.field-grid > * { min-width: 0; }
.stepper { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) 28px 28px; gap: 2px; }
.stepper input { min-width: 0; padding-left: 5px; padding-right: 3px; }
.stepper button { min-width: 0; padding: 0; font-size: 17px; }
.check-label { display: flex; align-items: center; gap: 6px; grid-column: 3 / 5; }
.check-label input { width: 18px; height: 18px; }

.gutter-details { margin: 8px 0 0; }
.detail-axis + .detail-axis { margin-top: 7px; padding-top: 7px; border-top: 1px solid #d7dde2; }
.axis-title { margin-bottom: 5px; font-size: 12px; font-weight: 700; color: #4a5560; }
.axis-fields { display: grid; grid-template-columns: repeat(4, minmax(62px, 1fr)); gap: 5px; }
.axis-field { display: grid; grid-template-columns: 20px 1fr; align-items: center; }
.axis-field input { height: 28px; font-size: 13px; font-weight: 500; }

.orientation-row { display: grid; grid-template-columns: 76px minmax(0, 180px); gap: 6px; align-items: center; margin-top: 8px; }
.orientation-row label { font-weight: 700; color: #34404b; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.copy-button { width: 100%; margin-top: 7px; background: #176b3a; border-color: #10532c; }
.copy-button:hover { background: #125a30; }
.settings-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 7px; }
.toast { min-height: 20px; padding-top: 4px; color: #176b3a; text-align: center; font-size: 12px; }

.best-paper-dialog { width: min(520px, calc(100vw - 28px)); padding: 0; border: 1px solid #9aa7b2; background: #fff; color: #1f2933; }
.best-paper-dialog::backdrop { background: rgba(15, 23, 42, 0.35); }
.best-paper-dialog form { padding: 0; margin: 0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid #d2d8de; background: #f5f7f8; }
.icon-button { min-width: 34px; height: 34px; padding: 0; border-radius: 50%; font-size: 20px; line-height: 1; }
.best-paper-list { max-height: 360px; overflow: auto; padding: 10px 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.best-paper-option { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 7px 8px; border: 1px solid #d7dde2; background: #fbfcfd; font-size: 13px; }
.best-paper-option input { width: 18px; height: 18px; flex: 0 0 auto; }
.best-paper-option span { overflow-wrap: anywhere; }
.dialog-tools, .dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 12px; }
.dialog-actions { justify-content: flex-end; padding-top: 4px; }

.preview-panel { display: grid; grid-template-rows: 34px auto auto; align-content: start; overflow: hidden; }
.preview-title { display: flex; align-items: center; padding: 0 12px; font-weight: 700; border-bottom: 1px solid #d2d8de; }
#previewCanvas { width: 100%; height: 380px; display: block; background: #f8fafb; }
.preview-meta { padding: 8px 12px 12px; border-top: 1px solid #d2d8de; background: #fff; text-align: center; font-size: 12px; font-weight: 700; line-height: 1.7; }
.preview-meta[hidden] { display: none; }
.preview-meta-margin { color: #6d28d9; }
.preview-meta-gutter { color: #9a6700; }

.usage-guide { grid-column: 1 / -1; padding: 14px 18px 16px; background: #fff; border: 1px solid #cbd2d9; }
.usage-guide h2 { margin: 0 0 10px; font-size: 16px; color: #1f2933; }
.usage-guide h3 { margin: 14px 0 8px; font-size: 14px; color: #34404b; }
.usage-guide p { margin: 0; font-size: 13px; line-height: 1.8; }
.usage-guide ol { margin: 0; padding-left: 22px; display: grid; gap: 6px; font-size: 13px; line-height: 1.7; }
.usage-guide li::marker { font-weight: 700; color: #2f6f9f; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .preview-panel { min-height: 0; }
}

@media (max-width: 560px) {
  .app-header { padding: 0 10px; }
  .save-state { display: none; }
  .workspace { padding: 5px; }
  .controls { padding: 8px; }
  .field-grid { grid-template-columns: 92px 1fr; }
  .field-grid > :nth-child(4n + 3) { margin-top: 3px; }
  .check-label { grid-column: 1 / 3; }
  .preset-row { grid-template-columns: 70px 1fr 52px 52px; }
  .orientation-row { grid-template-columns: 70px 1fr; }
  .actions { grid-template-columns: 1fr 1fr; }
  .settings-tools { grid-template-columns: 1fr; }
  .best-paper-list { grid-template-columns: 1fr; }
  .margin-grid { grid-template-columns: 1fr 1fr; }
  .axis-fields { grid-template-columns: repeat(2, minmax(62px, 1fr)); }
  #previewCanvas { height: 340px; }
}
