*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, sans-serif;
  font-size: 14px;
  color: #111;
  background: #fff;
  padding: 1rem 1.5rem;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  gap: 1.5rem;
}

#controls {
  width: 380px;
  flex-shrink: 0;
  overflow-y: auto;
}

h1 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}

h2 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

label {
  display: block;
  margin-bottom: 0.9rem;
}

label span {
  display: block;
  font-size: 0.78rem;
  color: #555;
  margin-bottom: 3px;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 0.35rem 0.45rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 0.85rem;
  font-family: inherit;
  background: #fff;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: #0070f3;
  box-shadow: 0 0 0 2px #0070f3;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.field-note {
  font-size: 0.72rem;
  color: #888;
  margin-top: 2px;
  margin-bottom: 0.9rem;
}

/* Regions */
#regions-enable-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  margin-bottom: 0.3rem;
  cursor: pointer;
}

#regions-note {
  font-size: 0.75rem;
  color: #888;
  margin-bottom: 0.5rem;
}

#region-section {
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 0.75rem;
  margin-bottom: 0.9rem;
}

#region-section legend {
  font-size: 0.78rem;
  color: #555;
  padding: 0 4px;
}

#region-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
  font-size: 0.82rem;
}

#region-table th {
  text-align: left;
  font-weight: 500;
  color: #555;
  padding: 0 2px 4px;
  font-size: 0.75rem;
}

#region-table td {
  padding: 2px;
}

#region-table td:last-child {
  width: 24px;
}

#region-table select,
#region-table input {
  font-size: 0.82rem;
  padding: 0.2rem 0.3rem;
}

.btn-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: #999;
  font-size: 1rem;
  line-height: 1;
  padding: 2px 4px;
}

.btn-remove:hover { color: #c00; }

#region-actions {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  margin-top: 2px;
}

#add-region-btn {
  font-size: 0.78rem;
  color: #0070f3;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

#add-region-btn:hover { text-decoration: underline; }

#reset-regions-btn {
  font-size: 0.78rem;
  color: #999;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

#reset-regions-btn:hover { color: #c00; text-decoration: underline; }

/* Patches */
#patch-section {
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 0.75rem;
  margin-bottom: 0.9rem;
}

#patch-section legend {
  font-size: 0.78rem;
  color: #555;
  padding: 0 4px;
}

/* Suggested PRs — checkbox rows */
.pr-suggested {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
  cursor: pointer;
  overflow: hidden;
}

.pr-suggested input[type="checkbox"] {
  flex-shrink: 0;
  margin: 0;
  cursor: pointer;
}

.pr-suggested-title {
  flex: 1;
  min-width: 0;
}

.pr-ext-link {
  flex-shrink: 0;
  color: #bbb;
  font-size: 0.72rem;
  text-decoration: none;
  padding: 0 2px;
}

.pr-ext-link:hover { color: #0070f3; }

/* Custom PR list */
#pr-list {
  list-style: none;
  padding: 0;
  margin: 0.3rem 0 0.4rem;
}

#pr-list li {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 2px 0;
  font-size: 0.82rem;
}

.pr-label { flex: 1; color: #444; }

.pr-move {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #ccc;
  font-size: 0.6rem;
  padding: 2px 2px;
  line-height: 1;
}

.pr-move:hover { color: #333; }

.pr-add-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.pr-add-row input { flex: 1; width: auto; }

#add-pr-btn {
  font-size: 0.78rem;
  color: #0070f3;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
}

#add-pr-btn:hover { text-decoration: underline; }

/* Build button */
#build-btn {
  width: 100%;
  padding: 0.55rem;
  background: #111;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 0.5rem;
}

#build-btn:hover:not(:disabled) { background: #333; }
#build-btn:disabled { background: #aaa; cursor: default; }

#cancel-btn {
  width: 100%;
  padding: 0.55rem;
  background: none;
  color: #c00;
  border: 1px solid #c00;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 0.5rem;
}

#cancel-btn:hover { background: #fff0f0; }

/* Log */
#log-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#log-output {
  flex: 1;
  min-height: 0;
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 0.75rem;
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-y: auto;
}

#download-link {
  display: block;
  margin-top: 0.5rem;
  padding: 0.55rem;
  background: #0070f3;
  color: #fff;
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.9rem;
  text-align: center;
}

#download-link:hover { background: #005ac5; }

[hidden] { display: none !important; }

@media (max-width: 768px) {
  body {
    height: auto;
    overflow: auto;
  }
  main {
    flex-direction: column;
  }
  #controls {
    width: 100%;
    overflow-y: visible;
  }
  #log-section {
    min-height: 400px;
  }
}
