:root {
  --page: #f5f8fc;
  --surface: #ffffff;
  --surface-soft: #f9fbfe;
  --text: #17223b;
  --muted: #67748e;
  --border: #dde6f2;
  --border-strong: #cbd7e8;
  --primary: #2478ed;
  --primary-hover: #1967d2;
  --success: #11a66a;
  --success-hover: #0b915b;
  --danger: #c63838;
  --shadow: 0 8px 28px rgba(29, 51, 84, 0.07);
  --radius: 14px;
}

* {
  box-sizing: border-box;
  min-width: 0;
}

[hidden] {
  display: none !important;
}

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--page);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--page);
  color: var(--text);
  font-family: "Segoe UI", Inter, Arial, sans-serif;
  line-height: 1.45;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(100%, 1600px);
  margin: 0 auto;
  padding: 22px clamp(14px, 2.2vw, 34px) 18px;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  display: grid;
  place-items: center;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border-radius: 13px;
  color: #fff;
  font-size: 23px;
  font-weight: 800;
  background: linear-gradient(145deg, #5aa2ff, #176ad8);
  box-shadow: 0 8px 18px rgba(36, 120, 237, 0.2);
}

.brand-copy h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 1.7rem);
  line-height: 1.2;
  color: #10182d;
}

.brand-copy p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.version-badge {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid #cfe0ff;
  border-radius: 9px;
  background: #eaf2ff;
  color: #1769d1;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

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

.controls-column,
.preview-column {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.compact-card {
  padding: 16px;
}

.card-heading {
  margin-bottom: 15px;
}

.card-heading h2 {
  margin: 0;
  font-size: 1rem;
  color: #1d2944;
}

.card-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.compact-heading {
  margin-bottom: 12px;
}

.fields-grid {
  display: grid;
  gap: 10px;
}

.field-row {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.field-label {
  color: #273652;
  font-size: 0.84rem;
  white-space: nowrap;
}

.text-input,
.hex-input {
  width: 100%;
  max-width: 100%;
  min-height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.text-input:focus,
.hex-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 120, 237, 0.1);
}

.color-controls {
  display: grid;
  grid-template-columns: 48px minmax(100px, 130px) minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.color-picker {
  width: 48px;
  height: 42px;
  padding: 3px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
}

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

.button {
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 9px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s, background 0.18s, opacity 0.18s;
}

.button:active {
  transform: translateY(1px);
}

.button:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

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

.button.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.button.success {
  background: var(--success);
  color: #fff;
}

.button.success:hover:not(:disabled) {
  background: var(--success-hover);
}

.button.secondary {
  border: 1px solid var(--border-strong);
  background: #fff;
  color: #24334e;
}

.button.secondary:hover:not(:disabled) {
  background: #f2f6fb;
}

.preview-card {
  padding: 12px;
}

.preview-header {
  padding: 4px 6px 0;
}

.preview-stage {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: clamp(300px, 52vh, 590px);
  overflow: hidden;
  border: 1px solid #d5dfec;
  border-radius: 10px;
  background: #fff;
  padding: clamp(8px, 1.2vw, 14px);
}

.preview-empty {
  display: grid;
  place-items: center;
  gap: 6px;
  text-align: center;
  color: #7b879c;
  padding: 20px;
}

.preview-empty strong {
  color: #52627a;
}

.preview-image {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: calc(62vh - 30px);
  object-fit: contain;
  border-radius: 4px;
}

.info-card {
  padding: 16px;
}

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

.info-item {
  min-width: 0;
  border-radius: 9px;
  background: var(--surface-soft);
  padding: 10px 12px;
}

.info-item.span-2 {
  grid-column: span 2;
}

.info-item dt {
  margin-bottom: 4px;
  color: #6b7890;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.info-item dd {
  margin: 0;
  color: #23314f;
  font-size: 0.88rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-width: 0;
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 10px 12px;
  color: #52627a;
  font-size: 0.84rem;
  box-shadow: 0 5px 18px rgba(29, 51, 84, 0.04);
}

.status-bar span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.status-dot {
  flex: 0 0 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #13aa6c;
}

.status-bar.error .status-dot {
  background: var(--danger);
}

.toast {
  position: fixed;
  z-index: 50;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(360px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  border-radius: 11px;
  background: #17223b;
  color: #fff;
  padding: 12px 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

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

  .controls-column {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }

  .controls-column > .card:first-child {
    grid-column: 1 / -1;
  }

  .preview-stage {
    min-height: 420px;
  }
}

@media (max-width: 700px) {
  .app-shell {
    padding: 14px 12px 16px;
  }

  .app-header {
    align-items: center;
  }

  .brand-icon {
    flex-basis: 42px;
    width: 42px;
    height: 42px;
    border-radius: 11px;
  }

  .brand-copy p {
    font-size: 0.82rem;
  }

  .controls-column {
    grid-template-columns: 1fr;
  }

  .controls-column > .card:first-child {
    grid-column: auto;
  }

  .card,
  .compact-card,
  .info-card {
    padding: 14px;
  }

  .preview-card {
    padding: 8px;
  }

  .preview-stage {
    min-height: 330px;
  }

  .preview-image {
    max-height: 52vh;
  }
}

@media (max-width: 520px) {
  .app-header {
    gap: 10px;
  }

  .brand-block {
    gap: 10px;
  }

  .brand-icon {
    display: none;
  }

  .version-badge {
    padding: 6px 8px;
    font-size: 0.75rem;
  }

  .field-row {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .field-label {
    white-space: normal;
  }

  .text-input,
  .hex-input {
    min-height: 44px;
    font-size: 16px; /* mencegah auto-zoom Safari/iOS */
  }

  .color-controls {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .color-controls .button {
    grid-column: 1 / -1;
  }

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

  .action-grid .button:last-child {
    grid-column: auto;
  }

  .button {
    min-height: 48px;
  }

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

  .info-item.span-2 {
    grid-column: auto;
  }

  .preview-stage {
    min-height: 260px;
    padding: 6px;
  }

  .preview-image {
    width: 100%;
    max-height: none;
  }
}

@media (max-width: 360px) {
  .app-shell {
    padding-left: 9px;
    padding-right: 9px;
  }

  .card,
  .compact-card,
  .info-card {
    padding: 12px;
  }

  .brand-copy h1 {
    font-size: 1.24rem;
  }

  .brand-copy p {
    font-size: 0.78rem;
  }
}

/* PHP Native hardening / responsive safeguards */
html, body { max-width: 100%; overflow-x: hidden; }
.app-shell, .workspace, .controls-column, .preview-column, .card, .field-row, .info-grid { min-width: 0; max-width: 100%; }
input, button, img { max-width: 100%; }
.fatal-card { display:grid; gap:6px; margin-bottom:14px; padding:14px 16px; border:1px solid #f3b7bd; border-radius:12px; background:#fff2f3; color:#8d2330; overflow-wrap:anywhere; }

@media (max-width: 920px) {
  .app-shell { width: min(100% - 24px, 100%); margin: 0 auto; padding: 14px 0 18px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .controls-column, .preview-column { width: 100%; }
  .preview-column { grid-row: auto; }
  .preview-stage { min-height: 260px; }
}

@media (max-width: 560px) {
  .app-shell { width: min(100% - 16px, 100%); padding-top: 10px; }
  .app-header { align-items:flex-start; gap:10px; }
  .brand-block { min-width:0; }
  .brand-icon { width:42px; height:42px; flex-basis:42px; }
  .brand-copy h1 { font-size:1.25rem; }
  .version-badge { padding:5px 8px; font-size:.72rem; }
  .card { padding:14px; border-radius:11px; }
  .compact-card { padding:14px; }
  .field-row { grid-template-columns: 1fr; gap:6px; }
  .field-label { white-space:normal; }
  .text-input, .hex-input { min-height:44px; font-size:16px; }
  .color-controls { grid-template-columns: 48px minmax(0,1fr); }
  .color-controls .button { grid-column:1 / -1; }
  .action-grid { grid-template-columns: 1fr; }
  .action-grid .button:last-child { grid-column:auto; }
  .info-grid { grid-template-columns: 1fr; }
  .info-item.span-2 { grid-column:auto; }
  .preview-stage { min-height:220px; padding:8px; }
  .preview-image { width:100%; height:auto; max-height:none; object-fit:contain; }
  .status-bar { align-items:flex-start; font-size:.82rem; overflow-wrap:anywhere; }
}

@media (max-width: 360px) {
  .app-header { flex-direction:column; }
  .version-badge { align-self:flex-start; }
}


/* Patch v1.0.1: global font-size control */
.font-size-controls {
  display: grid;
  grid-template-columns: 46px minmax(96px, 128px) 46px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
}
.step-button {
  width: 46px;
  height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #fff;
  color: #24334e;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.step-button:hover { background: #f2f6fb; }
.font-size-input-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 44px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #fff;
}
.font-size-input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 8px 4px 8px 11px;
  font-weight: 700;
}
.font-size-input-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36,120,237,.1);
}
.font-size-input-wrap > span {
  padding: 0 10px 0 4px;
  color: var(--muted);
  font-size: .84rem;
}
.font-default-button { min-height: 44px; }
.font-size-range-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  margin-top: 11px;
  color: var(--muted);
  font-size: .76rem;
}
.font-size-range {
  width: 100%;
  min-width: 0;
  accent-color: var(--primary);
}
@media (max-width: 520px) {
  .font-size-controls {
    grid-template-columns: 46px minmax(0, 1fr) 46px;
  }
  .font-default-button {
    grid-column: 1 / -1;
  }
  .font-size-input {
    font-size: 16px;
  }
}


/* Patch v1.0.4: download locked until manual preview */
.button.is-locked {
  opacity: 0.62;
  cursor: not-allowed;
}
