/* Stars to TON - Modern iOS Style */

:root {
    --bg: #fff;
    --bg2: #f2f2f7;
    --text: #000;
    --hint: #8e8e93;
    --accent: #007aff;
    --accent-soft: #007aff15;
    --accent-light: #e5f1ff;
    --border: rgba(0,0,0,0.12);
    --sep: rgba(0,0,0,0.08);
    --success: #34c759;
    --danger: #ff3b30;
    --warning: #ff9500;
    --nav-glass: rgba(242,242,247,.92);
    --nav-border: rgba(0,0,0,0.15);
    --nav-inner: rgba(0,0,0,.06);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
*:focus, *:focus-visible { outline: none !important; box-shadow: none !important; -webkit-box-shadow: none !important; }
input:focus, button:focus { outline: none !important; }

body {
    font-family: -apple-system, 'SF Pro Display', BlinkMacSystemFont, sans-serif;
    background: var(--bg2);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    opacity: 0;
    transition: opacity .15s;
}

body.loaded { opacity: 1; }

/* Header */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    padding-top: calc(var(--safe-t) + 10px);
    background: var(--bg2);
}

.user-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg);
    padding: 6px 12px 6px 6px;
    border-radius: 24px;
}

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #5856d6);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.avatar span { color: #fff; font-weight: 600; font-size: 12px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: none; }
.avatar img.show { display: block; }
.avatar img.show + span { display: none; }

.username { font-size: 14px; font-weight: 600; }

/* Wallet Box */
.wallet-container { position: relative; }

.wallet-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg);
    color: var(--accent);
    border: none;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .1s;
}

.wallet-box:active { transform: scale(.95); }
.wallet-box i { font-size: 14px; }

.wallet-popup {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg);
    border-radius: 14px;
    padding: 6px;
    min-width: 150px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(.95);
    transition: all .2s;
    z-index: 200;
}

.wallet-popup.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.popup-addr {
    padding: 10px 12px;
    font-size: 12px;
    font-family: monospace;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

.popup-disconnect {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: none;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    color: var(--danger);
    cursor: pointer;
}

.popup-disconnect:active { background: rgba(255,59,48,.1); }

/* Main */
.app-main {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.view {
    position: absolute;
    inset: 0;
    opacity: 0;
    visibility: hidden;
    transform: translateX(12px);
    transition: all .25s cubic-bezier(.4, 0, .2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.view.active {
    position: relative;
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

.view-content {
    padding: 16px;
    padding-bottom: calc(90px + var(--safe-b));
    max-width: 420px;
    margin: 0 auto;
}

.page-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
    text-align: center;
    margin-bottom: 20px;
}

/* Swap Card */
.swap-card {
    background: var(--bg);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 20px;
}

.swap-field { margin-bottom: 4px; }

.field-header { margin-bottom: 10px; }

.field-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--hint);
}

.field-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.field-row.no-border { border-bottom: none; padding-bottom: 0; }

.field-currency {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 16px;
    font-weight: 600;
}

.currency-icon { width: 48px; height: 48px; object-fit: contain; }

.field-row input {
    width: 50%;
    border: none;
    background: transparent;
    font-size: 32px;
    font-weight: 700;
    color: var(--text);
    text-align: right;
}

.field-row input::placeholder { color: var(--hint); opacity: .4; }

.field-output {
    font-size: 32px;
    font-weight: 700;
    text-align: right;
}

/* Swap Divider with icon in center */
.swap-divider {
    display: flex;
    align-items: center;
    padding: 12px 0;
}

.divider-line {
    flex: 1;
    height: 1px;
    background: var(--border);
}

.divider-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 13px;
    margin: 0 12px;
}

.rate-line {
    text-align: center;
    font-size: 13px;
    color: var(--hint);
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* Swap Button */
.swap-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 18px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: transform .1s;
}

.swap-btn:active:not(:disabled) { transform: scale(.97); }
.swap-btn:disabled { background: var(--hint); opacity: .35; cursor: not-allowed; }
.swap-btn i { font-size: 15px; }

/* Shine - left to right only, faster */
.shine {
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.25), transparent);
    animation: shineMove 2.5s ease-in-out infinite;
}

.swap-btn:disabled .shine { display: none; }

@keyframes shineMove {
    0% { left: -50%; }
    40%, 100% { left: 150%; }
}

/* Loading spinner */
.swap-btn .spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
    text-align: center;
    font-size: 13px;
    color: var(--danger);
    margin-top: 12px;
    min-height: 18px;
}

/* Keyboard - button higher with smooth animation */
body.keyboard-open .swap-btn {
    position: fixed;
    bottom: 20px;
    left: 16px;
    right: 16px;
    width: auto;
    border-radius: 14px;
    z-index: 99;
}

.swap-btn {
    transition: all .3s cubic-bezier(.4, 0, .2, 1);
}

body.keyboard-open .nav-bar { 
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}

.nav-bar {
    transition: opacity .3s;
}

/* Assets Card */
.asset-card {
    background: var(--bg);
    border-radius: 20px;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.asset-left { display: flex; align-items: center; gap: 14px; }
.asset-icon { width: 48px; height: 48px; }
.asset-info { display: flex; flex-direction: column; gap: 2px; }
.asset-label { font-size: 13px; color: var(--hint); }

.asset-value {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.asset-value span:first-child { font-size: 28px; font-weight: 700; }
.asset-unit { font-size: 15px; font-weight: 600; color: var(--hint); }

.lock-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: var(--accent-soft);
    color: var(--accent);
    border: none;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    opacity: .5;
    cursor: not-allowed;
}

/* Connect Prompt */
.connect-prompt {
    background: var(--bg);
    border-radius: 20px;
    padding: 32px 20px;
    text-align: center;
    margin-top: 16px;
}

.prompt-icon {
    width: 52px;
    height: 52px;
    background: var(--accent-soft);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
    font-size: 22px;
    color: var(--accent);
}

.connect-prompt p { font-size: 14px; color: var(--hint); margin-bottom: 18px; }

.prompt-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 14px 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.prompt-btn:active { transform: scale(.97); }

/* Navigation - iOS Style with glass */
.nav-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 20px;
    padding-bottom: calc(var(--safe-b) + 8px);
    background: var(--nav-glass);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-top: 0.5px solid var(--nav-border);
    z-index: 100;
}

.nav-inner {
    display: flex;
    justify-content: center;
    gap: 8px;
    max-width: 280px;
    margin: 0 auto;
    background: var(--nav-inner);
    border-radius: 30px;
    padding: 4px;
}

.nav-tab {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 16px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--hint);
    font-size: 11px;
    font-weight: 500;
    transition: color .2s;
    border-radius: 26px;
    z-index: 1;
}

.tab-bg {
    position: absolute;
    inset: 0;
    background: var(--bg);
    border-radius: 26px;
    opacity: 0;
    transition: opacity .2s;
    z-index: -1;
}

.nav-tab.active .tab-bg { opacity: 1; }
.nav-tab.active { color: var(--accent); }
.nav-tab i { font-size: 18px; margin-bottom: 2px; }
.nav-tab:active { transform: scale(.95); }

/* Success Page */
.success-page {
    position: fixed;
    inset: 0;
    background: var(--bg2);
    z-index: 1000;
    transform: translateX(100%);
    transition: transform .3s cubic-bezier(.4, 0, .2, 1);
    overflow-y: auto;
}

.success-page.show { transform: translateX(0); }

.close-x {
    position: absolute;
    top: calc(var(--safe-t) + 14px);
    right: 14px;
    width: 32px;
    height: 32px;
    background: var(--bg);
    border: none;
    border-radius: 50%;
    color: var(--hint);
    font-size: 14px;
    cursor: pointer;
}

.close-x:active { transform: scale(.9); }

.success-body {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    padding-top: calc(var(--safe-t) + 60px);
    padding-bottom: calc(var(--safe-b) + 24px);
}

.success-check {
    width: 76px;
    height: 76px;
    background: var(--accent-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    font-size: 34px;
    color: var(--accent);
    animation: popIn .4s cubic-bezier(.175,.885,.32,1.275);
}

@keyframes popIn {
    from { transform: scale(0); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.success-body h1 { font-size: 24px; font-weight: 700; margin-bottom: 28px; }

.tx-rows {
    width: 100%;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}

.tx-row {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg);
    padding: 12px 14px;
    border-radius: 12px;
}

.tx-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.tx-icon.red { background: #ffcdd2; color: #c62828; }
.tx-icon.green { background: #c8e6c9; color: #2e7d32; }
.tx-icon.orange { background: #ffe0b2; color: #ef6c00; }

.tx-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.tx-label { font-size: 12px; color: var(--hint); }

.tx-value {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 18px;
    font-weight: 700;
}

.tx-value img { width: 26px; height: 26px; }

/* Notice */
.notice-box {
    width: 100%;
    max-width: 300px;
    text-align: center;
    margin-bottom: 28px;
}

.notice-box p {
    font-size: 13px;
    color: var(--accent);
    line-height: 1.6;
    margin-bottom: 10px;
}

.notice-link {
    font-size: 13px;
    color: var(--hint);
    text-decoration: underline;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 32px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
}

.action-btn:active { transform: scale(.97); }

/* Remove number spinners & focus rings */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] { -moz-appearance: textfield; }
::-webkit-scrollbar { width: 0; }
