:root {
  --bg: #0c0e14;
  --panel: #181b24;
  --raised: #262a36;
  --line: #262a36;
  --text: #f5f7fa;
  --muted: #969eac;
  --green: #16c784;
  --red: #ea3943;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100dvh; display: flex; flex-direction: column; }

.wrap { width: 100%; max-width: 980px; margin: 0 auto; padding: 0 16px; }

button { font: inherit; color: inherit; }

/* header */
.top {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; padding-top: 20px; padding-bottom: 14px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 900; font-size: 24px; letter-spacing: 0.02em;
}
.brand i {
  width: 10px; height: 10px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 4px rgba(22, 199, 132, 0.15);
}
.tagline {
  margin-top: 4px; color: var(--muted); font-weight: 700; font-size: 12px;
  letter-spacing: 0.14em; text-transform: uppercase;
}
.meta { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

.link {
  background: none; border: 0; padding: 4px 2px; cursor: pointer;
  color: var(--green); font-weight: 700; font-size: 13px;
}
.link:disabled { opacity: 0.4; cursor: default; }

/* layout: settings, then image, then actions on phones; image left, panel right on wide screens */
.layout {
  display: grid; gap: 14px; flex: 1; padding-bottom: 24px;
  grid-template-areas: "controls" "preview" "side";
}
.controls { grid-area: controls; }
.preview { grid-area: preview; }
.side { grid-area: side; display: flex; flex-direction: column; gap: 14px; }

@media (min-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-rows: auto 1fr;
    grid-template-areas: "preview controls" "preview side";
    align-items: start;
  }
}

.group { background: var(--panel); border-radius: 16px; padding: 14px; }
.group-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.label {
  margin: 0; color: var(--muted); font-size: 12px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
}

/* settings */
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.seg {
  flex: 1 1 220px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: var(--bg); border-radius: 12px; padding: 4px;
}
.seg button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 10px 8px; border-radius: 9px; font-weight: 700; font-size: 14px;
}
.seg button.on { background: var(--raised); color: var(--text); }
.coins { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 700; }
.coins select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 10px; font: inherit; font-weight: 700;
}

/* image */
.preview {
  position: relative; margin: 0; padding: 10px; background: var(--panel);
  border-radius: 16px; display: flex; justify-content: center;
}
.preview canvas {
  display: block; max-width: 100%; max-height: 82vh; width: auto; height: auto; border-radius: 8px;
}
.state {
  position: absolute; inset: 10px; display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center; color: var(--muted); font-weight: 700;
  background: rgba(12, 14, 20, 0.7); border-radius: 8px;
}
.state[hidden] { display: none; }
.state.error { color: #ffb4b9; }

/* actions */
.actions { display: flex; flex-direction: column; gap: 10px; }
.btn {
  width: 100%; border: 0; border-radius: 12px; padding: 14px 16px; cursor: pointer;
  background: var(--raised); color: var(--text); font-weight: 700; font-size: 15px;
}
.btn.primary { background: var(--green); color: #04160d; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn[hidden] { display: none; }

.caption {
  margin: 0; white-space: pre-wrap; word-break: break-word;
  font: inherit; font-size: 14px; line-height: 1.55; color: #d9dde5;
}
.tip { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.tip b { color: var(--text); }

footer { padding-top: 8px; padding-bottom: 24px; color: var(--muted); font-size: 12px; }
footer a { color: var(--muted); }

/* phones: keep Share / Download pinned to the bottom of the screen */
@media (max-width: 859px) {
  body { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .actions {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; flex-direction: row;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: rgba(12, 14, 20, 0.92); border-top: 1px solid var(--line);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  }
  .actions .btn { flex: 1; padding: 13px 10px; font-size: 14px; }
}
