:root {
    --bg: #0B1327;
    --bg-2: #0B1327;
    --card: #182443;
    --card-2: #253356;
    --border: #2E3C60;
    --border-2: #3B4A6F;
    --text: #F3F9FF;
    --muted: #A5B8E3;
    --dim: #54648B;
    --accent: #F76B15;
    --accent-2: #FF9457;
    --green: #30A46C;
    --red: #E5484D;
    --neutral-chip: #A5B8E3;
  }
  * { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body { height: 100%; }
  html { background: var(--bg); }
  body {
    background: var(--bg);
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
  }
  button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
  button:active { opacity: .92; }
  #app {
    position: fixed; inset: 0;
    margin: 0 auto;
    max-width: 520px;
    background: var(--bg);
    display: flex; flex-direction: column;
    overflow: hidden;
  }

  /* ============ HEADER ============ */
  #appHeader {
    display: flex; align-items: flex-start; justify-content: space-between;
    padding: max(4px, env(safe-area-inset-top, 0px)) 16px 4px;
    flex: 0 0 auto;
  }
  .avatar-wrap { position: relative; }
  .avatar-btn {
    width: 48px; height: 48px; border-radius: 12px;
    background: var(--card);
    display: flex; align-items: center; justify-content: center;
    transition: transform .12s;
  }
  .avatar-btn:active { transform: scale(.95); }
  .avatar-btn svg { stroke: var(--muted); }
  .vip-badge {
    position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
    background: linear-gradient(90deg, #E7CFA4, #C9A96A);
    color: #4A3413;
    font-size: 9.5px; font-weight: 800; letter-spacing: .25px;
    padding: 1.5px 7px 2px; border-radius: 8px;
    display: flex; align-items: center; gap: 3px;
    white-space: nowrap;
  }
  .balance-block { text-align: center; padding-top: 1px; }
  .balance {
    color: var(--accent-2);
    font-size: 24px; line-height: 27px; font-weight: 700; letter-spacing: -.38px;
    font-variant-numeric: tabular-nums;
  }
  .balance .cents { font-size: 16px; }
  .acct-row {
    color: var(--muted); font-size: 12px; line-height: 17px; font-weight: 400;
    display: flex; align-items: center; justify-content: center; gap: 5px;
    margin-top: 1px;
  }
  .acct-row svg { transition: transform .18s ease; }
  .acct-row svg { stroke: var(--muted); }
  .balance-block.account-open .acct-row svg { transform: rotate(180deg); }
  .wallet-btn {
    width: 48px; height: 48px; border-radius: 12px;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    box-shadow: none;
    position: relative;
    transition: transform .12s, box-shadow .2s, filter .2s;
  }
  .wallet-btn:active { transform: scale(.95); }
  .wallet-btn svg { width: 24px; height: 24px; }
  #sceneTouch {
    position: absolute; z-index: 160; left: 0; top: 0;
    width: 28px; height: 28px; margin: -14px 0 0 -14px;
    border: 2px solid rgba(255,255,255,.92); border-radius: 50%;
    background: rgba(255,217,138,.18);
    box-shadow: 0 0 0 8px rgba(255,217,138,.09);
    pointer-events: none; opacity: 0; transform: scale(.7);
    transition: opacity .14s, transform .18s;
  }
  #sceneTouch.on { opacity: 1; transform: scale(1); }

  /* ============ SCREENS ============ */
  #screens { flex: 1 1 auto; min-height: 0; position: relative; }
  .screen {
    position: absolute; inset: 0;
    display: none;
    animation: screenIn .22s cubic-bezier(.22,.9,.34,1);
  }
  .screen.on { display: flex; flex-direction: column; }
  @keyframes screenIn { from { opacity: .3; transform: translateY(9px); } to { opacity: 1; transform: none; } }
  .scrolly { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px 24px; }
  .screen h1 { font-size: 32px; font-weight: 800; letter-spacing: -.4px; margin: 10px 0 14px; }
  .sec-title { font-size: 25px; font-weight: 800; letter-spacing: -.3px; margin: 22px 0 12px; }

  /* ============ VIDEO TUTORIALS ============ */
  #app.tutorials-mode #appHeader { display: none; }
  #screen-tutorials {
    --tutorial-header: #171E31;
    --tutorial-section: #1D2538;
    --tutorial-gap: #11182C;
    background: var(--tutorial-header);
  }
  .tutorials-shell {
    display: flex; flex-direction: column; min-height: 0; flex: 1;
    background: var(--tutorial-header);
  }
  .tutorials-main {
    display: flex; flex-direction: column; min-height: 0; flex: 1;
  }
  .tutorials-header {
    min-height: 112px; flex: 0 0 auto;
    display: grid; grid-template-columns: minmax(84px, 1fr) auto minmax(84px, 1fr);
    align-items: center; gap: 8px;
    padding: max(10px, env(safe-area-inset-top, 0px)) 14px 8px;
    background: var(--tutorial-header);
  }
  .tutorials-header-title {
    font-size: 22px; line-height: 1.12; font-weight: 800; text-align: center;
    letter-spacing: -.35px; color: #F6F8FD; white-space: nowrap;
  }
  .tutorials-back, .tutorials-search {
    min-height: 44px; display: flex; align-items: center; overflow: visible; color: #F6F8FD;
  }
  .tutorials-back { justify-content: flex-start; gap: 5px; font-size: 18px; font-weight: 700; }
  .tutorials-search { justify-content: flex-end; }
  .tutorials-back img {
    width: 31px; height: 38px; padding: 0;
    display: block; object-fit: contain; object-position: center;
    mix-blend-mode: lighten;
  }
  .tutorials-search img {
    width: 34px; height: 34px; padding: 2px;
    display: block; object-fit: contain; object-position: center;
    mix-blend-mode: lighten;
  }
  .tutorials-content {
    flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; background: var(--tutorial-gap); overscroll-behavior: contain;
  }
  .tutorials-content::-webkit-scrollbar, .tutorial-row::-webkit-scrollbar { display: none; }
  .tutorial-category {
    background: var(--tutorial-section); padding: 12px 0 20px; margin-bottom: 14px;
  }
  .tutorial-category-head {
    display: grid; grid-template-columns: 46px 1fr auto; align-items: center;
    gap: 10px; min-height: 58px; padding: 0 15px 11px;
  }
  .tutorial-category-icon {
    width: 44px; height: 44px; padding: 1px; border-radius: 50%;
    display: block; object-fit: contain; background: var(--tutorial-section);
  }
  .tutorial-category-copy { min-width: 0; }
  .tutorial-category-title {
    color: #F5F7FC; font-size: 20px; line-height: 1.1; font-weight: 800;
    letter-spacing: -.2px;
  }
  .tutorial-category-count {
    color: #7585A4; font-size: 15px; line-height: 1.2; font-weight: 600; margin-top: 5px;
  }
  .tutorial-see-all {
    color: #7B8CAA; font-size: 17px; line-height: 1; font-weight: 700;
    padding: 12px 0 12px 12px; white-space: nowrap;
  }
  .tutorial-row {
    display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none;
    padding: 0 15px; scroll-padding-inline: 15px;
    scroll-snap-type: x proximity; overscroll-behavior-inline: contain;
  }
  .tutorial-card {
    width: 166px; flex: 0 0 166px; color: #F5F7FC; text-align: left;
    scroll-snap-align: start; scroll-snap-stop: normal; align-self: flex-start;
  }
  .tutorial-thumb {
    width: 166px; aspect-ratio: 495 / 278; display: block; object-fit: cover;
    border-radius: 10px; background: #0B1223;
  }
  .tutorial-card-title {
    display: block; margin-top: 8px; min-height: 40px;
    font-size: 15.5px; line-height: 1.18; font-weight: 500; letter-spacing: -.12px;
    user-select: text; -webkit-user-select: text;
  }
  html[data-locale="ar"] .tutorial-card-title {
    direction: rtl; text-align: right;
  }
  .tutorials-detail { display: none; flex: 1; min-height: 0; flex-direction: column; background: var(--tutorial-header); }
  .tutorials-shell.detail-open .tutorials-main { display: none; }
  .tutorials-shell.detail-open .tutorials-detail { display: flex; }
  .tutorial-detail-tags {
    display: flex; gap: 9px; overflow-x: auto; scrollbar-width: none;
    padding: 0 15px 10px; flex: 0 0 auto; background: var(--tutorial-header);
  }
  .tutorial-tag {
    flex: 0 0 auto; border-radius: 18px; background: #28344E; color: #7D8EAD;
    padding: 7px 12px 8px; font-size: 15px; line-height: 1; font-weight: 700;
  }
  .tutorial-detail-grid, .tutorial-search-grid {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 22px 12px; padding: 8px 15px 28px;
  }
  .tutorial-detail-grid .tutorial-card, .tutorial-search-grid .tutorial-card { width: 100%; }
  .tutorial-detail-grid .tutorial-thumb, .tutorial-search-grid .tutorial-thumb { width: 100%; }
  .tutorial-search-panel { display: none; padding: 10px 15px 6px; background: var(--tutorial-header); }
  .tutorials-shell.search-open .tutorial-search-panel { display: block; }
  .tutorial-search-field {
    width: 100%; height: 42px; border: 1px solid #4A5D83; border-radius: 13px;
    background: #121B30; color: #F5F7FC; padding: 0 13px; outline: none;
    font: 500 16px/1.2 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
    user-select: text; -webkit-user-select: text;
  }
  .tutorial-search-field::placeholder { color: #7181A0; }
  .tutorial-search-results { display: none; background: var(--tutorial-header); }
  .tutorials-shell.search-open .tutorial-category-list { display: none; }
  .tutorials-shell.search-open .tutorial-search-results { display: block; }
  .tutorial-empty {
    grid-column: 1 / -1; color: #7B8CAA; text-align: center; padding: 54px 20px;
    font-size: 16px;
  }
  @media (max-width: 360px) {
    .tutorials-header { grid-template-columns: minmax(72px, 1fr) auto minmax(72px, 1fr); padding-inline: 11px; }
    .tutorials-header-title { font-size: 20px; }
    .tutorials-back { font-size: 16px; }
    .tutorial-card { width: 154px; flex-basis: 154px; }
    .tutorial-thumb { width: 154px; }
    .tutorial-category-title { font-size: 19px; }
  }

  /* ============ TRADE ============ */
  #screen-trade { padding-top: 0; }
  .risk-warning {
    flex: 0 0 auto;
    margin: 0 16px 7px;
    color: var(--muted);
    font-size: 10px;
    line-height: 13px;
    text-align: center;
  }
  .risk-warning[hidden] { display: none; }
  .asset-tabs {
    display: flex; gap: 4px; padding: 4px 16px;
    overflow-x: auto; scrollbar-width: none;
    flex: 0 0 auto;
  }
  .asset-tabs::-webkit-scrollbar { display: none; }
  .a-tab {
    flex: 0 0 auto;
    height: 48px; min-width: 48px;
    background: var(--card);
    border: 1px solid transparent;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    transition: transform .12s;
  }
  .a-tab:active { transform: scale(.95); }
  .a-tab.wide {
    padding: 0 7px 0 6px;
    gap: 6px;
    background: var(--card-2);
    border: 1.2px solid var(--border-2);
    animation: tabExpand .28s cubic-bezier(.22,.9,.34,1);
  }
  @keyframes tabExpand { from { transform: scale(.9); opacity: .5; } to { transform: scale(1); opacity: 1; } }
  .a-tab .ico { position: relative; width: 32px; height: 32px; flex: 0 0 auto; }
  .a-tab .ico svg { width: 32px; height: 32px; display: block; }
  .ico img { width: 100%; height: 100%; display: block; object-fit: contain; }
  .ico img.sq { border-radius: 32%; }
  .a-tab .meta { text-align: left; min-width: 0; }
  .a-tab .meta .nm {
    display: block;
    font-size: 14px; line-height: 20px; font-weight: 600; letter-spacing: -.154px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 78px;
  }
  .a-tab .meta .tp {
    display: block;
    font-size: 11px; line-height: 15px; color: var(--muted); font-weight: 400; margin-top: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 78px;
  }
  .a-tab .x { padding: 6px 0 6px 2px; display: flex; }
  .a-tab.plus { background: var(--card); }

  .chart-wrap { flex: 1 1 auto; min-height: 170px; position: relative; margin: 0; touch-action: none; }
  .chart-map {
    position: absolute; left: 0; right: 0; top: 18.35%; bottom: 18.35%;
    background: url("../../assets/trade-room-world-map.svg") center / 100% 100% no-repeat;
    opacity: .10;
    pointer-events: none;
  }
  #chart { position: absolute; inset: 0; width: 100%; height: 100%; }
  .chart-tools {
    position: absolute; left: 8px; bottom: 14px;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    z-index: 3;
  }
  .tool-badge {
    background: var(--card); color: var(--muted);
    font-size: 12px; font-weight: 700;
    padding: 3px 9px; border-radius: 9px;
  }
  button.tool-badge { transition: background .15s, color .15s, transform .12s; }
  button.tool-badge:active { transform: scale(.94); }
  button.tool-badge.active { background: #36466E; color: #F6F8FC; box-shadow: inset 0 0 0 1px #6379A7; }
  button.tool-badge[hidden] { display: none; }
  .interval-badge {
    min-width: 44px; min-height: 24px; padding: 3px 8px;
    border-radius: 8px; background: var(--card-2); color: var(--text);
    box-shadow: inset 0 0 0 1.2px var(--border-2);
    font-size: 12px; line-height: 1; white-space: nowrap;
  }
  .tool-btn {
    position: relative;
    width: 32px; height: 32px; border-radius: 8px;
    background: rgba(24,36,67,.94);
    display: flex; align-items: center; justify-content: center;
    transition: transform .12s;
  }
  .tool-btn:active { transform: scale(.93); }
  .tool-btn svg { width: 18px; height: 18px; }
  .indicator-count {
    position: absolute; top: -5px; right: -5px;
    min-width: 20px; height: 20px; padding: 0 5px;
    border-radius: 10px;
    background: #6E7FA8; color: #F5F7FB;
    border: 2px solid var(--bg);
    display: none; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; line-height: 1;
  }
  .indicator-count.on { display: flex; }
