/* ═══════════════════════════════════════════════════════════════════════════
   The two views — the whole stylesheet half of the feature. See role.js.
   ═══════════════════════════════════════════════════════════════════════════

   Ported from Chess Bender, 2026-10-01. Language Bender shows a student's
   screens and a teacher's screens in the same place. The student's view is the
   DEFAULT for everyone, administrators included, so the app can be looked at
   the way students will actually see it.

   A page opts in with two tags:

     <link rel="stylesheet" href="/role.css">
     <script src="/role.js" defer></script>

   and then marks whatever is teacher-only with `data-admin-only`.

   Written as :not() rather than "hide, then un-hide for admins" on purpose. The
   un-hide version has to guess a `display` to restore, and gets it wrong for
   every flex row and grid panel. This way an administrator's markup matches no
   rule at all and styles exactly as it would without any of this.

   And because the attribute is ABSENT until role.js has an answer, the
   student's view is what renders first.

   This decides what is DRAWN. The server decides what is allowed, from the same
   session — ctx.isAdmin(event) and the /auth routes.
   ═══════════════════════════════════════════════════════════════════════════ */

html:not([data-viewing-as="admin"]) [data-admin-only] { display: none !important; }
html[data-viewing-as="admin"] [data-user-only] { display: none !important; }

/* ── the switch ────────────────────────────────────────────────────────────
   The --ui-* variables come from theme.css; the fallbacks are for a page that
   forgot to load it, where an unstyled button would be a bad surprise. */

.viewswitch {
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--ui-line, #2f3244);
  border-radius: var(--ui-radius, 0.5rem);
  background: var(--ui-btn, #262a3d);
  color: var(--ui-dim, #949ab0);
  cursor: pointer;
  white-space: nowrap;
}
@media (hover: hover) {
  .viewswitch:hover:not(:disabled) {
    background: var(--ui-btn-hover, #333750);
    color: var(--ui-text, #eef0f7);
  }
}
.viewswitch:disabled { opacity: .6; cursor: default; }

/* In the admin view the switch is the way back, so it reads as active rather
   than as one more grey link. */
.viewswitch[data-mode="admin"] {
  border-color: var(--ui-accent, #7c6cf2);
  color: var(--ui-text, #eef0f7);
}

/* An admin who forgets which view they are in turns every "this is broken for
   students" into a false alarm. This is the cheapest possible cure. */
.viewswitch-tag {
  font-size: max(0.75rem, var(--text-min, 0px)); /* 12px */
  font-weight: 800;
  letter-spacing: .06em;
  padding: 0.375rem 0.625rem;
  margin-right: 0.5rem;
  border-radius: 62.4375rem;
  background: var(--ui-accent, #7c6cf2);
  color: var(--ui-accent-text, #fff);
  white-space: nowrap;
}

[data-view-switch] { display: inline-flex; align-items: center; }
[data-view-switch][hidden] { display: none; }

/* ── who you are signed in as, and Sign out ─────────────────────────────────
   The picture and the username are there so switching accounts to test
   something can be verified at a glance rather than by remembering. The whole
   address is in the tooltip. */
[data-account-switch] { display: inline-flex; align-items: center; gap: 0.5rem; }
[data-account-switch][hidden] { display: none; }

.accountme {
  display: inline-flex;
  align-items: center;
  gap: 0.4375rem;
  min-width: 0;
  padding: 0.125rem 0.375rem 0.125rem 0.125rem;
  border: 1px solid transparent;
  border-radius: 62.4375rem;
  background: none;
  color: inherit;
  font: inherit;
}
button.accountme { cursor: pointer; }
@media (hover: hover) { button.accountme:hover { border-color: var(--ui-line, #2f3244); } }

/* The picture, over the first letter of the name: when there is no picture
   (a username account never has one) or it is blocked, the letter is left. */
.accountpic {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  overflow: hidden;
  background: var(--ui-accent-fill, var(--ui-accent, #7c6cf2));
  color: var(--ui-accent-text, #fff);
  font: 800 0.9375rem/1 var(--ui-font, system-ui, sans-serif);
}
.accountpic img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.accountwho {
  font-size: max(0.9375rem, var(--text-min, 0px)); /* 15px */
  font-weight: 600;
  color: var(--ui-dim, #949ab0);
  /* Enough to tell two accounts apart, not enough to push the shell bar past
     the window. */
  max-width: 17ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.accountout {
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--ui-line, #2f3244);
  border-radius: var(--ui-radius, 0.5rem);
  background: transparent;
  color: var(--ui-dim, #949ab0);
  cursor: pointer;
  white-space: nowrap;
}
@media (hover: hover) {
  .accountout:hover:not(:disabled) {
    background: var(--ui-btn-hover, #333750);
    color: var(--ui-text, #eef0f7);
  }
}
.accountout:disabled { opacity: .6; cursor: default; }

/* ═══════════════════════════════════════════════════════════════════════════
   Pro features, locked
   ═══════════════════════════════════════════════════════════════════════════

   Mark a control `data-pro` and role.js does the rest: for an account that is
   paying, nothing at all happens; for one that is not, this gold treatment and
   a click that goes to the Pro tab.

   Shown rather than hidden, deliberately, and that is José's instruction from
   Chess Bender: *"Free users should still see the options, but they should
   have a gold border with a Pro label."* A feature that is simply absent sells
   nothing and teaches nobody that it exists.

   NONE OF THIS IS THE PAYWALL. Every Pro feature is refused by the server too.

   `outline` and not `border`, so nothing here changes a layout: an outline is
   drawn outside the box and takes no space, which means a locked control is
   exactly the size of an unlocked one. */

.is-prolocked {
  position: relative;
  outline: 1px solid var(--pro-gold, #e3b341);
  outline-offset: 2px;
  border-radius: var(--ui-radius, 0.5rem);
  cursor: pointer;
}

/* Dimmed through the CHILDREN rather than the element, because opacity on the
   element would take the badge down with it — and the badge is the one part
   that has to stay legible. */
.is-prolocked > *:not(.probadge) { opacity: .55; }

/* A control with no element children of its own — a plain <button> whose whole
   content is a text node — cannot be dimmed that way, so it is dimmed here. */
.is-prolocked { color: var(--ui-dim, #949ab0); }

/* THE BADGE IS A PSEUDO-ELEMENT, and that is not a shortcut — it is the fix.
   Nothing a page does to its own content can remove an ::after. */
.is-prolocked::after {
  content: 'PRO';
  position: absolute;
  top: -0.5625rem;
  right: 0.5rem;
  z-index: 2;
  font: 700 max(0.5625rem, var(--text-min, 0px))/1 var(--ui-font, system-ui, sans-serif); /* 9px */
  letter-spacing: .1em;
  padding: 0.25rem 0.375rem;
  border-radius: 62.4375rem;
  background: var(--pro-gold, #e3b341);
  color: var(--pro-gold-text, #1b1405);
  pointer-events: none;
  white-space: nowrap;
  opacity: 1;
}

/* Somewhere too small or too tightly packed for a badge hanging off the top
   corner — a tab in a tab bar, a checkbox line. `data-pro="inline"` puts it
   after the text instead, where it reads as part of the label. */
[data-pro="inline"].is-prolocked::after {
  position: static;
  display: inline-block;
  margin-left: 0.4375rem;
  vertical-align: middle;
}
[data-pro="inline"].is-prolocked { outline-offset: 1px; }

/* A <summary> is a list-item by default, so ::after lands after the marker in
   a way that reads oddly. */
summary.is-prolocked { list-style-position: outside; }

@media (hover: hover) { .is-prolocked:hover { outline-width: 2px; } }
