:root {
  --bg: #f3f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d7dee7;
  --line-strong: #b8c3cf;
  --text: #1f2933;
  --muted: #5b6775;
  --primary: #246bfe;
  --primary-dark: #174ea6;
  --terminal: #101828;
  --terminal-text: #e4e7ec;
  --success: #087443;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

.app {
  width: 100%;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.toolbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  min-width: 260px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

h1 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.brand a {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}

.brand a:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

button,
select,
input {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

button {
  padding: 0 13px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

button:hover,
select:hover,
.file-button:hover {
  border-color: #7a8a9a;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
.file-button:focus-within {
  outline: 2px solid rgba(36, 107, 254, 0.28);
  outline-offset: 1px;
}

.toolbar-link {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

select,
input {
  padding: 0 10px;
  font-size: 13px;
}

.button-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

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

.button-secondary,
.file-button {
  background: var(--panel-soft);
}

.file-button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  border-top: 1px solid rgba(255, 255, 255, 0.7);
}

.editor-pane,
.result-pane {
  min-width: 0;
  min-height: 0;
}

.editor-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--panel);
}

.result-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-left: 1px solid var(--line);
}

.pane-title {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
  font-size: 13px;
  font-weight: 800;
}

.local-badge {
  padding: 4px 8px;
  border: 1px solid #b7dec9;
  border-radius: 999px;
  background: #effaf3;
  color: var(--success);
  font-size: 11px;
  font-weight: 800;
}

#save-status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--success);
  font-weight: 700;
}

textarea,
pre {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.45;
  letter-spacing: 0;
}

textarea {
  resize: none;
  outline: none;
  color: var(--text);
  background: var(--panel);
}

textarea:focus {
  box-shadow: inset 0 0 0 2px rgba(36, 107, 254, 0.34);
}

pre {
  overflow: auto;
  white-space: pre-wrap;
  background: var(--terminal);
  color: var(--terminal-text);
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
  padding: 12px;
}

label {
  min-width: 0;
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
  color: #344054;
}

label input,
label select {
  width: 100%;
  min-width: 0;
}

[hidden] {
  display: none !important;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.46);
}

.modal-dialog {
  position: relative;
  width: min(680px, calc(100vw - 32px));
  max-height: min(540px, calc(100vh - 32px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 22px 70px rgba(15, 23, 42, 0.28);
}

.settings-dialog {
  width: min(900px, calc(100vw - 32px));
}

.modal-header {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.modal-header h2 {
  margin: 0;
  font-size: 17px;
}

.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
}

.modal-body {
  padding: 16px;
}

.settings-dialog .modal-body {
  max-height: min(560px, calc(100vh - 150px));
  overflow: auto;
  background: var(--panel-soft);
}

.modal-body p {
  margin: 0 0 12px;
  line-height: 1.6;
}

.modal-body a {
  color: var(--primary-dark);
  font-weight: 700;
}

.modal-footer {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

#settings-status {
  color: var(--success);
  font-size: 13px;
  font-weight: 800;
}

@media (max-width: 1000px) {
  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand {
    min-width: 0;
  }

  .controls {
    width: 100%;
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(260px, 0.8fr);
  }

  .result-pane {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .option-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
}
