:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --border: #e6e8ee;
    --border-strong: #d3d7e0;
    --text: #14161c;
    --muted: #7c8494;
    --brand: #6366f1;
    --brand-dark: #4f46e5;
    --brand-soft: rgba(99,102,241,.10);
    --radius: 12px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(20,24,40,.05), 0 6px 20px rgba(20,24,40,.07);
    --shadow-soft: 0 1px 2px rgba(20,24,40,.04), 0 2px 8px rgba(20,24,40,.05);
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; margin: 0; }
  body {
    display: flex; flex-direction: column;
    background: var(--bg); color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
  }
  button { font-family: inherit; }
  ::selection { background: var(--brand-soft); }

  /* ---------- top chrome ---------- */
  #chrome {
    flex: 0 0 auto;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 5;
    -webkit-user-select: none; user-select: none;
  }

  #row1 {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 8px 0;
  }
  #brand {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 6px;
    padding: 0 6px 8px;
    color: var(--text);
  }
  #brand img.omark { height: 18px; width: auto; display: block; border-radius: 5px; }
  #brand .word { font-weight: 700; letter-spacing: -.02em; font-size: 14px; color: #16233c; }

  #tabs { display: flex; align-items: flex-end; gap: 2px; overflow-x: auto; flex: 1 1 auto; min-width: 0; scrollbar-width: none; }
  .tab {
    position: relative;
    display: flex; align-items: center; gap: 6px;
    max-width: 220px; min-width: 0;
    padding: 8px 10px 10px;
    font-size: 13px; color: var(--muted);
    cursor: pointer; white-space: nowrap; overflow: hidden;
    border-radius: 9px 9px 0 0;
    transition: color .1s, background .1s;
  }
  .tab:hover { background: rgba(20,24,40,.05); color: var(--text); }
  .tab.active { color: var(--text); }
  .tab.active::after { content:""; position:absolute; left:8px; right:8px; bottom:0; height:2px; background: var(--brand); border-radius: 2px; }
  .tab .fav { flex: 0 0 auto; width: 16px; height: 16px; display: block; }
  .tab .fav img { width: 100%; height: 100%; display: block; border-radius: 4px; }
  .tab .lbl { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }
  .tab .close {
    flex: 0 0 auto; width: 16px; height: 16px; border: 0; border-radius: 5px;
    background: transparent; color: var(--muted); font-size: 13px; line-height: 1;
    cursor: pointer; display: none; align-items: center; justify-content: center;
  }
  .tab:hover .close { display: inline-flex; }
  .tab .close:hover { background: var(--brand-soft); color: var(--brand); }
  #newtab {
    flex: 0 0 auto; width: 26px; height: 26px; margin: 0 2px 6px 2px;
    border: 0; border-radius: 7px; background: transparent;
    color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; transition: background .1s, color .1s;
  }
  #newtab:hover { background: rgba(20,24,40,.06); color: var(--brand); }

  /* ---------- nav / omnibox ---------- */
  #nav {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 12px 10px;
  }
  .btn {
    flex: 0 0 auto; width: 30px; height: 30px;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 0; border-radius: 8px;
    color: var(--text); font-size: 16px; cursor: pointer; transition: background .1s, transform .05s;
  }
  .btn:hover:not(:disabled) { background: rgba(20,24,40,.06); }
  .btn:active:not(:disabled) { transform: scale(.92); }
  .btn:disabled { opacity: .3; cursor: default; }
  #url {
    flex: 1 1 auto; height: 34px; padding: 0 14px;
    background: #eceff4; border: 1px solid transparent; border-radius: 17px;
    color: var(--text); font-size: 13.5px; outline: none; min-width: 0; transition: background .12s, border-color .12s, box-shadow .12s;
  }
  #url:focus { background: var(--panel); border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
  #url::placeholder { color: var(--muted); }
  #go {
    flex: 0 0 auto; height: 34px; padding: 0 16px;
    border: none; border-radius: 17px; background: var(--brand); color: #fff;
    font-size: 13px; font-weight: 600; cursor: pointer; transition: background .12s;
  }
  #go:hover { background: var(--brand-dark); }
  #opennew {
    flex: 0 0 auto; height: 34px; padding: 0 14px;
    border: 1px solid var(--border); border-radius: 17px;
    background: var(--panel); color: var(--text); font-size: 12.5px; font-weight: 600;
    cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, color .12s;
  }
  #opennew:hover:not(:disabled) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
  #opennew:disabled { opacity: .35; cursor: default; }

  /* ---------- content ---------- */
  #content { flex: 1 1 auto; position: relative; min-height: 0; }
  .tabview { position: absolute; inset: 0; display: none; background: #fff; }
  .tabview.active { display: block; }
  iframe { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
  .spinner {
    position: absolute; top: 12px; right: 16px; width: 18px; height: 18px;
    border: 2px solid #d3d7e0; border-top-color: var(--brand); border-radius: 50%;
    animation: spin .7s linear infinite; opacity: 0; transition: opacity .1s; pointer-events: none;
  }
  .spinner.on { opacity: 1; }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ---------- start page ---------- */
  .startpage {
    position: absolute; inset: 0; overflow: auto;
    display: flex; flex-direction: column; align-items: center;
    background:
      radial-gradient(700px 520px at 18% 6%,  rgba(99,102,241,.10), transparent 60%),
      radial-gradient(720px 540px at 85% 18%, rgba(167,139,250,.10), transparent 55%),
      radial-gradient(600px 500px at 62% 96%, rgba(99,102,241,.05), transparent 60%),
      var(--bg);
    padding: 40px 20px 36px;
  }
  .sp-inner { width: min(760px, 100%); display: flex; flex-direction: column; align-items: center; }
  .sp-logo { height: 100px; width: auto; display: block; margin: 0 0 14px; user-select: none; }

  .sp-search {
    display: flex; align-items: center; gap: 8px;
    width: min(540px, 100%);
    background: var(--panel); border: 1px solid var(--border-strong);
    border-radius: 28px; padding: 6px 8px 6px 18px; box-shadow: var(--shadow);
  }
  .sp-search svg { flex: 0 0 auto; color: var(--muted); }
  .sp-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 16px; height: 36px; }
  .sp-search input::placeholder { color: var(--muted); }
  .sp-search button {
    flex: 0 0 auto; height: 36px; padding: 0 20px; border: 0; border-radius: 19px;
    background: var(--brand); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer; transition: background .12s;
  }
  .sp-search button:hover { background: var(--brand-dark); }


  .sp-foot {
    width: 100%; margin: 28px 0 2px; margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border);
    display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 20px; font-size: 13px;
  }
  .sp-foot a { color: var(--muted); text-decoration: none; padding: 4px 2px; border-radius: 8px; cursor: pointer; }
  .sp-foot a:hover { color: var(--brand-dark); text-decoration: underline; }

  .sp-title { margin: 24px 0 12px; font-size: 14px; font-weight: 600; color: var(--muted); letter-spacing: .3px; align-self: flex-start; }
  .sp-grid {
    width: 100%; display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px;
  }
  .tile {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
    aspect-ratio: 1 / 1; cursor: pointer; box-shadow: var(--shadow-soft);
    transition: transform .1s, box-shadow .15s, border-color .15s; text-align: center; padding: 10px; position: relative;
  }
  .tile:hover { transform: translateY(-3px); border-color: var(--brand); box-shadow: var(--shadow); }
  .tile .ic { position: relative; width: 50px; height: 50px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 23px; font-weight: 700; color: #fff; overflow: hidden; }
  .tile .ic-letter { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
  .tile .ic-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
  .tile .ic.has-img { color: transparent; }
  .tile .nm { font-size: 13px; color: var(--text); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tile .del {
    position: absolute; top: 6px; right: 6px; width: 20px; height: 20px; border: 0; border-radius: 6px;
    background: var(--brand-soft); color: var(--brand); font-size: 14px; cursor: pointer; display: none; line-height: 1;
  }
  .tile:hover .del { display: block; }
  .tile .del:hover { background: var(--brand); color: #fff; }
  .tile.add { border-style: dashed; background: transparent; color: var(--muted); box-shadow: none; }
  .tile.add .plus { font-size: 30px; }
  .tile.add .nm { color: var(--muted); }

  /* ---------- editor ---------- */
  #editor {
    position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center;
    background: rgba(20,24,40,.42); padding: 20px;
  }
  #editor.show { display: flex; }
  .ed-card { width: min(420px, 100%); background: var(--panel); border-radius: 16px; padding: 22px; box-shadow: 0 14px 44px rgba(0,0,0,.3); }
  .ed-card h3 { margin: 0 0 16px; font-size: 17px; }
  .ed-card label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
  .ed-card input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 14px; outline: none; }
  .ed-card input:focus { border-color: var(--brand); }
  .ed-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
  .ed-actions button { height: 38px; padding: 0 18px; border-radius: var(--radius-sm); font-size: 14px; cursor: pointer; border: 1px solid var(--border-strong); background: var(--panel); }
  .ed-actions button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
  .ed-actions button.primary:hover { background: var(--brand-dark); }

  /* redirect rules are managed server-side in the independent admin; see /admin */

  #openhint {
    position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
    display: none; align-items: center; gap: 10px;
    background: var(--panel); border: 1px solid var(--border-strong); border-radius: 14px;
    box-shadow: 0 10px 30px rgba(20,24,40,.18); padding: 10px 14px; z-index: 60; max-width: 92vw;
  }
  #openhint.show { display: flex; }
  #openhint span { font-size: 13px; color: var(--text); }
  #openhint a { color: var(--brand); font-weight: 600; font-size: 13px; text-decoration: none; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #openhint a:hover { text-decoration: underline; }
  #openhint button { flex: 0 0 auto; width: 24px; height: 24px; border: 0; border-radius: 7px; background: var(--brand-soft); color: var(--brand); cursor: pointer; font-size: 16px; line-height: 1; }
  #openhint button:hover { background: var(--brand); color: #fff; }

  @media (max-width: 640px) {
    #row1 { gap: 6px; padding: 8px 8px 0; }
    #brand { padding: 0 6px 8px; gap: 8px; }
    #brand img.omark { height: 24px; border-radius: 7px; }
    #brand .word { font-size: 16px; }
    .tab { min-width: 130px; max-width: 200px; padding: 10px 12px; font-size: 14px; }
    #newtab { width: 34px; height: 34px; margin: 0 2px 8px 2px; font-size: 22px; border-radius: 8px; }
    /* mobile: address bar on its own full-width row so long URLs are visible */
    #nav { flex-wrap: wrap; gap: 8px; padding: 6px 12px 12px; }
    #url { order: 0; flex: 1 1 100%; height: 46px; font-size: 16px; padding: 0 18px; border-radius: 23px; }
    .btn { order: 1; width: 42px; height: 42px; font-size: 20px; border-radius: 11px; }
    #fav { order: 1; }
    #opennew { order: 2; height: 42px; padding: 0 15px; font-size: 13px; border-radius: 21px; }
    #go { order: 3; height: 42px; padding: 0 20px; font-size: 15px; border-radius: 21px; }
    .startpage { padding: 22px 16px 28px; }
    .sp-logo { height: 74px; margin: 0 0 12px; }
    .sp-search { min-height: 44px; }
    .sp-search input { height: 42px; font-size: 16px; }
    .sp-search button { height: 42px; padding: 0 18px; }
    .sp-foot { gap: 2px 14px; font-size: 12.5px; }
    .sp-title { margin: 18px 0 10px; }
    .sp-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
    .tile { gap: 7px; padding: 9px; }
    .tile .ic { width: 46px; height: 46px; font-size: 22px; }
  }
