:root {
  color-scheme: light;
  --ink: #1d242b;
  --muted: #65717b;
  --line: #d9e0e4;
  --paper: #f5f3ef;
  --panel: #ffffff;
  --field: #f9faf8;
  --accent: #246a73;
  --accent-dark: #164950;
  --danger: #a13f34;
  --shadow: 0 18px 48px rgba(23, 33, 41, .12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body:lang(ja) {
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  line-break: strict;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
  min-height: 100vh;
}

.panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.topbar,
.preview-toolbar,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.05rem;
  line-height: 1.2;
}

h2 {
  font-size: .82rem;
  text-transform: uppercase;
  color: var(--muted);
}

#statusText,
#previewMeta {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: .88rem;
}

.icon-button,
.viewport-switch button {
  min-width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

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

label {
  display: grid;
  gap: 7px;
}

label span {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--ink);
  outline: none;
}

textarea,
input {
  padding: 12px;
}

textarea {
  resize: vertical;
  min-height: 170px;
  line-height: 1.5;
}

select {
  height: 42px;
  padding: 0 10px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 106, 115, .12);
}

.clarification {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid #f0c36b;
  border-radius: 8px;
  background: #fff8e7;
}

.clarification.hidden {
  display: none;
}

.clarification h2 {
  color: var(--ink);
  font-size: .95rem;
  text-transform: none;
}

.clarification p {
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.45;
}

.clarification-actions {
  display: grid;
  gap: 8px;
}

.clarification-questions {
  display: grid;
  gap: 10px;
}

.clarification-questions textarea {
  min-height: 74px;
  background: #fff;
}

.checkbox-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: start;
  gap: 9px;
}

.checkbox-row input {
  width: 18px;
  margin: 2px 0 0;
}

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

.primary {
  height: 46px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

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

.primary:disabled {
  cursor: progress;
  opacity: .62;
}

.secondary {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: #fff;
  color: var(--accent-dark);
  font-weight: 800;
  cursor: pointer;
}

.secondary:hover {
  background: #edf7f5;
}

.history {
  min-height: 0;
  overflow: auto;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.section-title span {
  display: grid;
  place-items: center;
  min-width: 28px;
  height: 24px;
  border-radius: 999px;
  background: #edf4f2;
  color: var(--accent-dark);
  font-size: .78rem;
  font-weight: 800;
}

.project-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.project-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: stretch;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.project-item:hover,
.project-item.active {
  border-color: var(--accent);
}

.project-open {
  min-width: 0;
  display: grid;
  gap: 5px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.project-open strong {
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-open span {
  color: var(--muted);
  font-size: .82rem;
}

.project-delete {
  width: 34px;
  min-width: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: #fff4f1;
  color: var(--danger);
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
}

.project-delete:hover {
  border-color: #e5b3aa;
  background: #ffe8e2;
}

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

.preview-toolbar {
  min-height: 56px;
  padding: 0 4px 14px;
}

.preview-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.viewport-switch {
  display: inline-flex;
  gap: 6px;
}

.viewport-switch button {
  min-width: 82px;
  font-weight: 700;
}

.viewport-switch button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.preview-stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e7ecee;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .6);
}

.preview-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  background: #eef2f3;
}

.preview-empty strong {
  color: var(--ink);
  font-size: 1.2rem;
}

.preview-empty.hidden {
  display: none;
}

iframe {
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 110px);
  border: 0;
  background: #fff;
}

.preview-stage.mobile iframe {
  width: 390px;
  max-width: 100%;
  height: 812px;
  min-height: 812px;
  box-shadow: var(--shadow);
}

.error {
  color: var(--danger);
}

.modal {
  width: min(620px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(29, 36, 43, .44);
}

.modal-card {
  display: grid;
  gap: 18px;
  padding: 22px;
  background: #fff;
}

.modal-card header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
}

.modal-card h2 {
  color: var(--ink);
  font-size: 1rem;
  text-transform: none;
}

.modal-card p {
  margin-top: 5px;
  color: var(--muted);
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.modal-actions .primary,
.modal-actions .secondary {
  min-width: 140px;
  padding: 0 16px;
}

.modal-status {
  min-height: 22px;
  color: var(--muted);
  font-weight: 700;
}

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

  .panel {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    min-height: 82vh;
  }

  .preview-toolbar,
  .preview-actions {
    align-items: stretch;
    flex-direction: column;
  }
}
