:root {
  color-scheme: light;
  --bg: #f5f3ef;
  --panel: #ffffff;
  --ink: #1d2725;
  --muted: #68736f;
  --line: #d8d4cb;
  --soft: #ebe7df;
  --accent: #17453f;
  --focus: #2d7e73;
  --danger: #9e2f24;
  --shadow: 0 10px 26px rgba(31, 43, 39, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  letter-spacing: 0;
  background:
    linear-gradient(90deg, rgba(23, 69, 63, 0.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(23, 69, 63, 0.03) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
}

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

button {
  border: 0;
  cursor: pointer;
}

.app {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px 16px 92px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 38px);
  line-height: 1.12;
  font-weight: 800;
}

.status {
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 420px);
  gap: 16px;
  align-items: start;
}

.form-grid {
  display: grid;
  gap: 14px;
}

section,
.preview-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

section {
  padding: 16px;
  border-radius: 8px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--ink);
}

h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field.full {
  grid-column: 1 / -1;
}

label,
.group-label {
  font-size: 13px;
  font-weight: 700;
  color: #394541;
}

input,
textarea,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  outline: none;
  padding: 11px 12px;
  line-height: 1.35;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(45, 126, 115, 0.16);
}

.choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.choice {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
}

.choice input {
  width: 16px;
  height: 16px;
  padding: 0;
  accent-color: var(--accent);
}

.choice:has(input:checked) {
  border-color: var(--accent);
  background: rgba(23, 69, 63, 0.07);
}

.split-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.address-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.compact-btn {
  min-width: 64px;
  padding: 0 12px;
}

.account-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.account-list {
  display: grid;
  gap: 10px;
}

.account-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
  gap: 10px;
}

.preview-panel {
  position: sticky;
  top: 14px;
  overflow: hidden;
  border-radius: 8px;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #faf9f6;
}

.preview-head h2 {
  font-size: 17px;
}

.preview-actions {
  display: flex;
  gap: 8px;
}

.icon-btn,
.text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.icon-btn {
  width: 44px;
  flex: 0 0 44px;
}

.text-btn {
  min-width: 82px;
  padding: 0 14px;
}

.secondary {
  background: #45524e;
}

.ghost {
  background: var(--soft);
  color: var(--ink);
}

.danger {
  background: #f3ded9;
  color: var(--danger);
}

.icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  pointer-events: none;
}

#output {
  width: 100%;
  min-height: 560px;
  max-height: calc(100vh - 154px);
  border: 0;
  border-radius: 0;
  background: #fff;
  padding: 16px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}

#output:focus {
  box-shadow: inset 0 0 0 3px rgba(45, 126, 115, 0.16);
}

.bottom-actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: none;
  gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(250, 249, 246, 0.96);
  backdrop-filter: blur(12px);
}

.bottom-actions button {
  flex: 1;
}

.address-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(20, 29, 27, 0.56);
}

.address-modal[hidden] {
  display: none;
}

.address-dialog {
  display: grid;
  grid-template-rows: auto minmax(420px, 72vh);
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(11, 19, 17, 0.26);
}

.address-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #faf9f6;
}

#addressFrame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

@media (max-width: 880px) {
  .app {
    padding: 14px 12px 96px;
  }

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

  .status {
    text-align: left;
  }

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

  .preview-panel {
    position: static;
  }

  #output {
    min-height: 360px;
    max-height: none;
  }

  .bottom-actions {
    display: flex;
  }
}

@media (max-width: 620px) {
  .fields,
  .split-line,
  .account-row {
    grid-template-columns: 1fr;
  }

  .address-input-row {
    grid-template-columns: 1fr;
  }

  section {
    padding: 14px;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .choice {
    flex: 1 1 calc(50% - 8px);
    justify-content: center;
  }
}
