:root {
  --bg: #0B0E14;
  --panel: #121823;
  --panel2: #18202D;
  --line: #2A3445;
  --gold: #F5C451;
  --gold-dim: #B8923A;
  --cyan: #00CBCE;
  --text: #E2E8F0;
  --muted: #94A3B8;
  --ok: #4ADE80;
  --err: #F87171;
  --guild: #40FF40;
  --officer: #40C040;
  --whisper: #FF80FF;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}

button, input, select { font: inherit; color: inherit; }
a { color: var(--cyan); }
[hidden] { display: none !important; }
#app { height: 100%; }

/* ------------------------------------------------------------ bottoni */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid var(--gold-dim); border-radius: 6px;
  background: linear-gradient(#2A3242, #1A202B);
  color: var(--gold); font-weight: 600; letter-spacing: .02em;
  cursor: pointer;
}
.btn:active { filter: brightness(1.25); }
.btn:disabled { opacity: .45; }
.btn.primary {
  border-color: #E2B04A;
  background: linear-gradient(#9B1C1C, #5E0E0E);
  color: #FFE08A; text-shadow: 0 1px 1px #000;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.15), 0 0 0 1px #000;
}
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.danger { border-color: #7F1D1D; color: var(--err); background: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.input, select.input {
  width: 100%; min-height: 46px; padding: 0 14px;
  background: #0E131B; border: 1px solid var(--line); border-radius: 6px;
  outline: none;
}
.input:focus { border-color: var(--gold-dim); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--err); }
.ok { color: var(--ok); }
.gold { color: var(--gold); }
.center { text-align: center; }

/* ------------------------------------------------- schermate intere */
.screen {
  min-height: 100%;
  padding: calc(var(--top) + 24px) 20px calc(var(--bottom) + 24px);
  display: flex; flex-direction: column;
  background: radial-gradient(ellipse at 50% 0%, #142038 0%, var(--bg) 60%);
}
.screen .logo { width: 220px; max-width: 70%; margin: 12px auto 4px; display: block; }
.screen h1 { text-align: center; color: var(--gold); font-size: 20px; letter-spacing: .08em; text-transform: uppercase; margin: 8px 0 24px; }
.screen .box { width: 100%; max-width: 420px; margin: 0 auto; }
.screen .foot { margin-top: auto; padding-top: 24px; text-align: center; }

/* --------------------------------------------------- l'app vera */
.shell { height: 100%; display: flex; flex-direction: column; }

.top {
  padding: calc(var(--top) + 10px) 16px 10px;
  background: linear-gradient(#151C29, #0F141D);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.top .who { flex: 1; min-width: 0; }
.top .name { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; box-shadow: 0 0 6px var(--ok); }
.dot.afk { background: #FBBF24; box-shadow: none; }
.dot.busy { background: var(--err); box-shadow: none; }
.dot.offline { background: #475569; box-shadow: none; }
.crest {
  width: 40px; height: 40px; border-radius: 50%;
  border: 2px solid var(--gold-dim); background: #0E131B center/cover no-repeat;
  flex: none;
}

.main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.main.chatmode { display: flex; flex-direction: column; overflow: hidden; }

.tabs {
  display: flex;
  background: #0F141D;
  border-top: 1px solid var(--line);
  padding-bottom: var(--bottom);
}
.tabs button {
  flex: 1; border: 0; background: none; padding: 8px 0 6px;
  color: var(--muted); font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  position: relative; cursor: pointer;
}
.tabs button svg { width: 24px; height: 24px; }
.tabs button.on { color: var(--gold); }
.badge {
  position: absolute; top: 4px; left: 50%; margin-left: 6px;
  min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
  background: #DC2626; color: #fff; font-size: 11px; line-height: 17px; text-align: center; font-weight: 700;
}

.seg {
  display: flex; gap: 6px; padding: 10px 12px; overflow-x: auto;
  border-bottom: 1px solid var(--line); background: #0F141D; flex: none;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 16px; padding: 6px 14px; white-space: nowrap; font-size: 13px; cursor: pointer; position: relative;
}
.seg button.on { border-color: var(--gold-dim); color: var(--gold); background: #1C1A12; }
.seg button .pip { position: absolute; top: 3px; right: 4px; width: 7px; height: 7px; border-radius: 50%; background: #DC2626; }

.pad { padding: 14px 12px 24px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 14px; margin-bottom: 12px;
}
.card h2 {
  margin: 0 0 10px; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--gold);
}
.card h2 .right { float: right; text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; }

.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid #1E2735; }
.row:first-of-type { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .desc { color: var(--muted); font-size: 12px; }
.row.tap { cursor: pointer; }
.chev { color: var(--muted); font-size: 20px; }

.icon {
  width: 38px; height: 38px; border-radius: 5px; flex: none;
  border: 1px solid #000; outline: 1px solid #3B4352;
  background: #1F2633 center/cover no-repeat;
}
.icon.q0 { outline-color: #9D9D9D; } .icon.q1 { outline-color: #CFCFCF; } .icon.q2 { outline-color: #1EFF00; }
.icon.q3 { outline-color: #0070DD; } .icon.q4 { outline-color: #A335EE; } .icon.q5 { outline-color: #FF8000; }
.icon.q6 { outline-color: #E6CC80; } .icon.q7 { outline-color: #00CCFF; }
.q0 { color: #9D9D9D; } .q1 { color: #FFFFFF; } .q2 { color: #1EFF00; } .q3 { color: #0070DD; }
.q4 { color: #A335EE; } .q5 { color: #FF8000; } .q6 { color: #E6CC80; } .q7 { color: #00CCFF; }

.bar { height: 14px; border-radius: 3px; background: #0B0F16; border: 1px solid #000; position: relative; overflow: hidden; margin-top: 5px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; }
.bar.xp { height: 18px; }
.bar.xp b { line-height: 17px; font-size: 11px; }
.bar b { position: absolute; inset: 0; font-size: 10px; line-height: 13px; text-align: center; font-weight: 600; text-shadow: 0 1px 1px #000; }

.group-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 2px 6px; color: var(--gold); font-weight: 600; font-size: 14px; cursor: pointer;
}

.money { white-space: nowrap; }
.money span { margin-right: 6px; font-weight: 600; }
.money .g::after { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #E6B422; margin-left: 3px; }
.money .s::after { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #C0C0C0; margin-left: 3px; }
.money .c::after { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #B87333; margin-left: 3px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--panel2); border-radius: 6px; padding: 10px; }
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-weight: 700; font-size: 16px; margin-top: 2px; }

.grid-icons { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; }
.grid-icons div { text-align: center; font-size: 11px; color: var(--muted); }
.grid-icons .icon { margin: 0 auto 4px; width: 44px; height: 44px; }

/* --------------------------------------------------------------- chat */
.chatlog {
  flex: 1; overflow-y: auto; padding: 10px 12px; -webkit-overflow-scrolling: touch;
  background: #07090D; font-size: 15px;
}
.line { padding: 3px 0; word-wrap: break-word; }
.line .t { color: #556070; font-size: 11px; margin-right: 6px; }
.line .n { font-weight: 600; cursor: pointer; }
.line.guild { color: var(--guild); } .line.officer { color: var(--officer); } .line.whisper { color: var(--whisper); }
.line.sys { color: #FFFF00; }
.day { text-align: center; color: #556070; font-size: 11px; margin: 10px 0 4px; }
.older { display: block; margin: 0 auto 8px; }

.composer {
  display: flex; gap: 8px; padding: 8px 10px;
  border-top: 1px solid var(--line); background: #0F141D; flex: none;
}
.composer .input { min-height: 42px; }
.composer .btn { min-height: 42px; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

.back { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #0F141D; flex: none; }
.back button { border: 0; background: none; color: var(--gold); font-size: 15px; padding: 4px 6px 4px 0; cursor: pointer; }
.back .title { font-weight: 700; }

/* ---------------------------------------------------- guida */
.entry { border-top: 1px solid #1E2735; padding: 12px 0; }
.entry:first-of-type { border-top: 0; }
.entry .et { font-weight: 600; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.entry .es { color: var(--muted); font-size: 13px; margin-top: 3px; }
.entry .eb { margin-top: 10px; font-size: 14px; }
.entry .eb p { margin: 0 0 8px; }
.entry .eb ul { margin: 0 0 8px; padding-left: 20px; }
.tag-new { font-size: 10px; font-weight: 700; color: #000; background: var(--gold); border-radius: 3px; padding: 1px 5px; }
.tip { border-left: 3px solid var(--cyan); }

/* -------------------------------------------------------- avvisi */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--bottom) + 76px);
  background: #1E293B; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.5);
}
.toast.bad { border-color: #7F1D1D; }
.modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.65);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 520px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px 14px 0 0; padding: 20px 18px calc(var(--bottom) + 18px);
  max-height: 88%; overflow-y: auto;
}
.sheet h3 { margin: 0 0 10px; color: var(--gold); }
.sheet .actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet .actions .btn { flex: 1; }

.banner {
  margin: 10px 12px 0; padding: 10px 12px; border-radius: 8px;
  background: #13202B; border: 1px solid #1F4555; font-size: 13px;
}
.spin {
  width: 22px; height: 22px; border: 3px solid #334155; border-top-color: var(--gold);
  border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
