:root {
  color-scheme: dark;
  --bg: #06130f;
  --bg-elevated: rgba(8, 27, 21, .76);
  --bg-soft: rgba(12, 45, 34, .68);
  --surface: rgba(245, 250, 247, .08);
  --surface-strong: rgba(245, 250, 247, .13);
  --line: rgba(227, 240, 233, .18);
  --line-strong: rgba(227, 240, 233, .30);
  --text: #f5faf7;
  --muted: #bacbc3;
  --accent: #0d5d43;
  --accent-bright: #1aa36f;
  --accent-soft: rgba(26, 163, 111, .18);
  --button-text: #f5faf7;
  --shadow: 0 22px 70px rgba(0, 0, 0, .34);
  --blur: blur(20px);
  --toolbar-height: 60px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5faf7;
  --bg-elevated: rgba(255, 255, 255, .80);
  --bg-soft: rgba(245, 250, 247, .76);
  --surface: rgba(255, 255, 255, .72);
  --surface-strong: rgba(255, 255, 255, .90);
  --line: rgba(13, 93, 67, .18);
  --line-strong: rgba(13, 93, 67, .28);
  --text: #10231d;
  --muted: #52635c;
  --accent: #0d5d43;
  --accent-bright: #107a55;
  --accent-soft: rgba(13, 93, 67, .10);
  --button-text: #ffffff;
  --shadow: 0 20px 62px rgba(20, 46, 35, .18);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

body.portal-page {
  background:
    linear-gradient(135deg, rgba(3, 26, 19, .90), rgba(4, 47, 36, .68)),
    url("portal-bg.jpg") center / cover fixed,
    var(--bg);
}

:root[data-theme="light"] body.portal-page {
  background:
    linear-gradient(135deg, rgba(245, 250, 247, .90), rgba(220, 237, 228, .74)),
    url("portal-bg.jpg") center / cover fixed,
    var(--bg);
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0 44px;
}

.topbar,
.app-toolbar {
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  backdrop-filter: var(--blur);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 10px 12px;
  border-radius: 8px;
}

.brand,
.userbar,
.app-card,
.back-link,
.app-toolbar-actions {
  display: flex;
  align-items: center;
}

.brand {
  min-width: 0;
  gap: 12px;
  text-decoration: none;
}

.brand strong {
  display: block;
  font-size: 1rem;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: .82rem;
}

.mark {
  width: 38px;
  height: 38px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  color: var(--button-text);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-bright));
  font-weight: 900;
}

.userbar,
.app-toolbar-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: .92rem;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.portal-head {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 82px 0 26px;
  text-align: center;
}

.centered-head h1 {
  font-size: clamp(2rem, 4.5vw, 3.45rem);
}

.portal-note {
  margin-top: 12px;
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent-bright);
  font-size: .76rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(2.25rem, 6vw, 4.4rem);
  line-height: 1;
}

h2 {
  margin: 0;
  font-size: clamp(1.02rem, 1.5vw, 1.25rem);
  line-height: 1.16;
}

p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 16px;
  align-items: stretch;
  width: min(1040px, 100%);
  margin: 0 auto;
}

.app-card {
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  min-height: 240px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  text-align: center;
  text-decoration: none;
  backdrop-filter: var(--blur);
}

.app-card:hover,
.app-card:focus-within {
  border-color: var(--line-strong);
  background: var(--surface-strong);
}

.app-image {
  width: min(96px, 52%);
  aspect-ratio: 1;
  object-fit: contain;
  filter: drop-shadow(0 12px 22px rgba(0, 0, 0, .20));
}

.app-title-wrap {
  min-height: 3.2rem;
  display: grid;
  place-items: center;
}

.app-card .primary-button {
  width: 100%;
}

.login-panel {
  display: grid;
  grid-template-columns: minmax(300px, 400px);
  justify-content: center;
  gap: 24px;
  align-items: center;
  min-height: calc(100vh - 112px);
}

.login-copy h1,
.login-copy .eyebrow {
  text-align: center;
}

.login-card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  backdrop-filter: var(--blur);
}

.form-stack {
  display: grid;
  gap: 12px;
}

.inline-form {
  margin-top: 14px;
}

label {
  color: var(--text);
  font-size: .92rem;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 48px;
  padding: 11px 13px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  background: var(--surface);
}

input::placeholder {
  color: color-mix(in srgb, var(--muted) 76%, transparent);
}

input:focus {
  border-color: var(--accent-bright);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.primary-button,
.ghost-button,
.link-button,
.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 800;
}

.primary-button {
  padding: 0 18px;
  color: var(--button-text);
  border: 1px solid rgba(255, 255, 255, .12);
  background: linear-gradient(135deg, var(--accent), var(--accent-bright));
}

.ghost-button,
.back-link {
  padding: 0 14px;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--surface);
}

.ghost-button.compact {
  min-height: 40px;
}

.link-button {
  min-height: auto;
  padding: 0;
  color: var(--accent-bright);
  border: 0;
  background: transparent;
}

.alert,
.notice {
  margin-bottom: 14px;
  padding: 12px 13px;
  border-radius: 8px;
  line-height: 1.4;
}

.alert {
  color: #ffe1e1;
  border: 1px solid rgba(255, 141, 141, .42);
  background: rgba(255, 141, 141, .13);
}

.notice {
  color: var(--text);
  border: 1px solid var(--line-strong);
  background: var(--accent-soft);
}

.app-shell-page {
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

.app-toolbar {
  height: var(--toolbar-height);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 8px 10px;
  border-width: 0 0 1px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
}

.back-link {
  gap: 8px;
}

.app-toolbar-title {
  min-width: 0;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.app-frame {
  width: 100%;
  height: calc(100vh - var(--toolbar-height));
  display: block;
  border: 0;
  background: #ffffff;
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 24px, 1120px);
    padding-top: 12px;
  }

  .topbar,
  .portal-head,
  .app-card {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    align-items: flex-start;
  }

  .userbar {
    width: 100%;
    justify-content: space-between;
  }

  .login-panel,
  .app-grid {
    grid-template-columns: 1fr;
  }

  .login-panel {
    gap: 22px;
    min-height: auto;
    padding-top: 72px;
  }

  .portal-head {
    margin-top: 46px;
  }

  h1 {
    font-size: clamp(2rem, 13vw, 3.15rem);
  }

  .app-card {
    min-height: 184px;
  }

  .app-image {
    width: 82px;
  }

  .primary-button {
    width: 100%;
  }

  .app-toolbar {
    grid-template-columns: auto 1fr;
    height: auto;
    min-height: var(--toolbar-height);
  }

  .app-toolbar-title {
    display: none;
  }
}

@media (min-width: 761px) and (max-width: 1020px) {
  .app-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
