* { box-sizing: border-box; margin: 0; padding: 0; }
:root { --bg: #0a0a0a; --card: #161616; --border: #2a2a2a; --gold: #ffd267;
        --text: #fafafa; --muted: #888; --dim: #444; }
html, body { -webkit-tap-highlight-color: transparent; }
body { font-family: -apple-system, BlinkMacSystemFont, system-ui, "PingFang SC",
         "Microsoft YaHei", sans-serif;
       background: var(--bg); color: var(--text); min-height: 100vh; line-height: 1.55; }
a { color: var(--gold); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; }

header { position: sticky; top: 0; z-index: 10; backdrop-filter: blur(8px);
         background: rgba(10,10,10,0.85); border-bottom: 1px solid #222;
         display: flex; justify-content: space-between; align-items: center;
         padding: 14px 20px; flex-wrap: wrap; gap: 12px; }
.brand { font-size: 1.05em; letter-spacing: 0.02em; flex: 1; min-width: 0; }
.brand .logo { color: var(--gold); margin-right: 6px; }
.user-bar { display: flex; gap: 8px; align-items: center; flex-shrink: 0; flex-wrap: wrap; }
.user-bar button { background: var(--gold); color: #000; border: none;
                   padding: 6px 14px; border-radius: 4px; font-size: 0.9em; }
.user-bar button.ghost { background: transparent; color: var(--text); border: 1px solid var(--dim); }
.user-bar button.ghost:hover { border-color: var(--gold); color: var(--gold); }
.balance-pill { padding: 4px 10px; border: 1px solid var(--dim); border-radius: 999px;
                font-size: 0.85em; }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }
h2 { font-size: 1.15em; margin-bottom: 14px; font-weight: 600; }
h3 { font-size: 0.92em; color: #aaa; margin-bottom: 10px; font-weight: 500;
     text-transform: uppercase; letter-spacing: 0.05em; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
@media (max-width: 760px) { .grid { grid-template-columns: 1fr; gap: 12px; } }
.window { background: var(--card); border: 1px solid var(--border); border-radius: 8px;
          padding: 16px; min-height: 240px; display: flex; flex-direction: column; }
.window.full { grid-column: 1 / -1; }

.drop { border: 2px dashed #333; border-radius: 6px; padding: 28px 14px; text-align: center;
        color: var(--muted); cursor: pointer; transition: all 0.18s; flex: 1;
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        min-height: 130px; }
.drop:hover, .drop.drag { border-color: var(--gold); background: #1c1a14; color: var(--gold); }
.drop .icon { font-size: 1.8em; margin-bottom: 6px; }
.preview-row { display: flex; flex-direction: column; align-items: center; flex: 1; gap: 8px; }
.preview-row img { max-width: 100%; max-height: 240px; border-radius: 4px;
                   object-fit: contain; }
.preview-row .meta { font-size: 0.78em; color: var(--muted); }
.preview-row button { background: transparent; color: var(--gold); border: 1px solid var(--dim);
                      padding: 4px 12px; border-radius: 4px; font-size: 0.82em; }

.example { margin-top: 12px; border: 1px solid var(--border); border-radius: 4px;
           overflow: hidden; background: var(--bg); }
.example img { width: 100%; max-height: 130px; object-fit: contain; display: block; }
.example figcaption { background: #1a1a1a; color: var(--muted); font-size: 0.72em;
                      padding: 4px 8px; text-align: center; letter-spacing: 0.08em; }

textarea { width: 100%; min-height: 78px; background: var(--bg); border: 1px solid var(--border);
           border-radius: 4px; color: var(--text); padding: 10px; resize: vertical;
           font-size: 0.92em; }
textarea:focus { outline: none; border-color: var(--gold); }
.res-row { display: flex; gap: 10px; margin: 12px 0; }
.res-opt { flex: 1; padding: 10px; background: var(--bg); border: 1px solid var(--border);
           border-radius: 4px; cursor: pointer; text-align: center; font-size: 0.9em; }
.res-opt.active { border-color: var(--gold); color: var(--gold); background: #1c1a14; }
.res-opt small { display: block; color: var(--muted); margin-top: 2px; font-size: 0.78em; }
.res-opt.active small { color: var(--gold); }
.gen-btn { width: 100%; background: var(--gold); color: #000; border: none;
           padding: 13px; border-radius: 4px; font-size: 0.98em; font-weight: 600;
           margin-top: 6px; transition: opacity 0.18s; }
.gen-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.output-area { flex: 1; display: flex; align-items: center; justify-content: center;
               background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
               min-height: 220px; padding: 12px; color: var(--muted); font-size: 0.88em;
               position: relative; overflow: hidden; }
.output-area img { max-width: 100%; max-height: 320px; }
.spinner { width: 32px; height: 32px; border: 3px solid #333; border-top-color: var(--gold);
           border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.status-text { color: var(--gold); margin-top: 12px; font-size: 0.85em; text-align: center; }

.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.history-item { background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
                overflow: hidden; cursor: pointer; transition: transform 0.18s; }
.history-item:hover { transform: scale(1.03); border-color: var(--gold); }
.history-item img { width: 100%; aspect-ratio: 1 / 1.3; object-fit: cover; display: block; }
.history-item .info { padding: 6px 10px; font-size: 0.72em; color: var(--muted);
                      display: flex; justify-content: space-between; }
.history-empty { text-align: center; color: #555; padding: 30px; grid-column: 1 / -1; }

footer { text-align: center; color: #666; font-size: 0.82em; padding: 24px 16px;
         border-top: 1px solid #222; margin-top: 24px; }
footer .copyright { color: #444; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 100;
         display: none; align-items: center; justify-content: center; padding: 16px; }
.modal.show { display: flex; }
.modal-box { background: #1a1a1a; border: 1px solid var(--border); border-radius: 8px;
             padding: 22px; max-width: 440px; width: 100%; position: relative;
             max-height: 90vh; overflow-y: auto; }
.modal-box h2 { color: var(--gold); margin: 0 0 12px; }
.modal-box label { display: block; margin: 12px 0 6px; font-size: 0.9em; color: #aaa; }
.modal-box input { width: 100%; background: var(--bg); border: 1px solid var(--border);
                   border-radius: 4px; color: var(--text); padding: 10px; font-size: 0.95em; }
.modal-box input:focus { outline: none; border-color: var(--gold); }
.modal-box button.primary { width: 100%; background: var(--gold); color: #000; border: none;
                            padding: 12px; border-radius: 4px; font-weight: 600;
                            margin-top: 16px; font-size: 1em; }
.modal-box .alt-link { display: block; text-align: center; margin-top: 12px;
                        font-size: 0.85em; color: var(--muted); }
.modal-close { position: absolute; top: 10px; right: 14px; background: transparent;
               border: none; color: var(--muted); font-size: 1.4em; cursor: pointer; }
.muted { color: #aaa; font-size: 0.9em; margin-bottom: 6px; }
.code-input { font-size: 1.4em !important; letter-spacing: 0.3em !important; text-align: center !important; }
.err { color: #ff6b6b; font-size: 0.85em; margin-top: 8px; min-height: 1em; }

/* Output window 保存按钮 */
.output-actions { display: flex; justify-content: center; margin-top: 10px; }
.save-btn { display: inline-block; background: var(--gold); color: #000;
            padding: 10px 20px; border-radius: 4px; font-weight: 600;
            font-size: 0.95em; text-decoration: none; min-height: 44px;
            display: inline-flex; align-items: center; }
.save-btn:hover { text-decoration: none; opacity: 0.9; }

/* Lightbox · 图片点击放大 */
#image-modal { background: rgba(0,0,0,0.95); padding: 0; cursor: zoom-out; }
#image-modal.show { display: flex; }
#image-modal img { max-width: 95vw; max-height: 95vh; object-fit: contain;
                   cursor: default; box-shadow: 0 4px 40px rgba(0,0,0,0.6); }
.lightbox-close { position: fixed; top: 16px; right: 20px; background: rgba(0,0,0,0.6);
                  border: none; color: #fff; font-size: 2em; cursor: pointer;
                  width: 44px; height: 44px; border-radius: 50%; line-height: 1;
                  display: flex; align-items: center; justify-content: center;
                  z-index: 110; }
.lightbox-close:hover { background: rgba(255,210,103,0.9); color: #000; }
.zoomable { cursor: zoom-in; }

/* Crop modal — flex column 让确认按钮始终底部可见 */
.modal-box.crop-box { max-width: 720px; display: flex; flex-direction: column;
                       max-height: 92vh; padding: 18px; }
.crop-box h2 { flex-shrink: 0; }
.crop-stage { flex: 1 1 auto; min-height: 200px; max-height: 50vh;
              background: #0a0a0a; border: 1px solid var(--border); border-radius: 4px;
              overflow: hidden;
              display: flex; align-items: center; justify-content: center;
              margin-top: 10px; }
.crop-stage img { display: block; max-width: 100%; max-height: 100%; }
.ratio-row { display: flex; gap: 8px; margin: 12px 0 10px; justify-content: center;
             flex-shrink: 0; flex-wrap: wrap; }
.ratio-btn { background: var(--bg); border: 1px solid var(--border); color: var(--text);
             padding: 9px 16px; border-radius: 4px; font-size: 0.92em; cursor: pointer;
             min-width: 72px; }
.ratio-btn.active { border-color: var(--gold); color: var(--gold); background: #1c1a14; }
.crop-actions { display: flex; gap: 10px; flex-shrink: 0;
                position: sticky; bottom: 0; padding-top: 10px;
                background: #1a1a1a;   /* 与 modal-box 同色，sticky 时不透 */ }
.crop-actions button { flex: 1; padding: 13px; border-radius: 4px; font-size: 1em;
                       font-weight: 600; border: none; cursor: pointer;
                       min-height: 44px;   /* iOS 触摸目标最小尺寸 */ }
.crop-actions button.ghost { background: transparent; color: var(--text);
                              border: 1px solid var(--dim); }
.crop-actions button.primary { background: var(--gold); color: #000; }

.recharge-grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin-top: 12px; }
@media (min-width: 480px) { .recharge-grid { grid-template-columns: 1fr 1fr; } }
.recharge-cell { background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
                 padding: 14px; text-align: center; }
.recharge-cell .cell-label { font-size: 0.78em; color: var(--muted);
                              text-transform: uppercase; letter-spacing: 0.05em;
                              margin-bottom: 10px; }
.recharge-cell code { display: block; background: #0a0a0a; padding: 8px;
                      border-radius: 3px; color: var(--gold); font-size: 0.9em;
                      user-select: all; word-break: break-all; margin-bottom: 8px; }
.recharge-cell .copy-btn { background: transparent; color: var(--gold);
                           border: 1px solid var(--dim); padding: 4px 14px;
                           border-radius: 3px; font-size: 0.82em; }
.recharge-cell img { max-width: 200px; width: 100%; aspect-ratio: 1; object-fit: contain;
                     border-radius: 4px; }
.qr-fallback { color: #555; padding: 40px 10px; font-size: 0.85em; }

#toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
         background: #1a1a1a; border: 1px solid var(--gold); color: var(--gold);
         padding: 11px 18px; border-radius: 4px; font-size: 0.9em; z-index: 200;
         opacity: 0; transition: opacity 0.3s; pointer-events: none;
         max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
