@import url("https://fonts.googleapis.com/css2?family=Cinzel:wght@500;600&family=Crimson+Text:ital,wght@0,400;0,600;1,400&display=swap");

:root {
  --color-blue: #1f3659;
  --color-blue-dark: #142540;
  --color-blue-light: #2c4a73;
  --color-red: #a00000;
  --color-red-dark: #7a0000;
  --color-parchment: #d0a853;
  --color-parchment-dark: #b8a37c;
  --color-card-bg: #f7f2e7;
  --color-card-border: #d9cdb0;
  --color-text-dark: #2b2620;
  --color-text-muted: #6b6151;
  --color-text-on-dark: #f1ead9;
  --font-heading: "Cinzel", "Georgia", serif;
  --font-body: "Crimson Text", "Georgia", serif;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-card: 0 6px 18px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--color-text-dark);
  background-color: var(--color-parchment);
  background-image: url("../assets/textured-paper.png");
  background-repeat: repeat;
  background-size: auto;
  background-attachment: fixed;
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  font-weight: 600;
  margin: 0;
}

a {
  color: var(--color-red);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
}

/* Fixed top header with the brand logo, present on every page */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  padding: 10px 16px;
}

.app-logo {
  height: 42px;
  width: auto;
  display: block;
}

/* App shell: mobile-first, single column, comfortable max-width on larger screens */
.app-shell {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 78px 16px 32px;
}

.page-title {
  font-size: 1.6rem;
  color: var(--color-text-dark);
  text-align: center;
  margin-bottom: 4px;
}

.page-subtitle {
  text-align: center;
  color: var(--color-text-muted);
  font-style: italic;
  margin-bottom: 20px;
}

.dot-divider {
  display: block;
  height: auto;
  width: 55px;
  margin: 0 auto 18px;
}

/* Header row with a back arrow + centered title, e.g. Join/Group pages */
.page-header {
  position: relative;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.page-header .page-title {
  margin-bottom: 0;
}

.back-arrow {
  position: absolute;
  left: 0;
  top: 2px;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--color-text-dark);
}

.section-spacer {
  margin-top: 32px;
}

/* Plain text fields with no leading icon (Join/Create Group forms) */
.field.plain input {
  padding-left: 14px;
}

.role-row {
  display: flex;
  gap: 24px;
  align-items: center;
  margin: 4px 0 18px;
  font-size: 0.95rem;
}

.role-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.role-row input[type="radio"] {
  accent-color: var(--color-blue);
  width: 17px;
  height: 17px;
}

/* Card panel — the white rounded surfaces seen throughout the app */
.card {
  width: 100%;
  max-width: 380px;
  background: var(--color-card-bg);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 24px 20px;
}

.card + .card {
  margin-top: 16px;
}

/* Flex stack — used for the scrollable list of group cards. Mobile-first:
   a vertical column by default, switching to a centered horizontal row of
   fixed-width cards once there's enough room (laptop/desktop). */
.stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  max-width: 380px;
  gap: 12px;
}

/* .stack spaces its cards with gap, so the .card + .card margin above
   would otherwise double up spacing (and, in the row layout, throw off
   align-items: stretch — the first card has no top margin to eat into its
   stretched height, so it ends up taller than its siblings). */
.stack > .card + .card {
  margin-top: 0;
}

.group-card {
  position: relative;
  cursor: pointer;
  text-align: left;
  transition: box-shadow 0.15s ease;
}

.group-card:hover {
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3);
}

.group-card.active {
  box-shadow: 0 0 0 2px var(--color-blue), var(--shadow-card);
  text-align: center;
  cursor: default;
}

.group-card.active .card-actions {
  margin-top: 16px;
}

/* Stacked full-width buttons inside the active card (Battle / Group Settings) */
.card-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.group-card-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--color-blue);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
}

/* Form fields */
.field {
  position: relative;
  margin-bottom: 16px;
}

.field input {
  width: 100%;
  padding: 12px 14px 12px 38px;
  border: none;
  border-bottom: 1px solid var(--color-card-border);
  background: transparent;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--color-text-dark);
  outline: none;
}

.field input::placeholder {
  color: var(--color-text-muted);
}

.field input:focus {
  border-bottom-color: var(--color-blue);
}

.field .field-icon {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 20px;
  color: var(--color-text-muted);
  pointer-events: none;
}

.field .field-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 4px;
  color: var(--color-text-muted);
  font-size: 20px;
  display: flex;
}

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px 16px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
}

.btn-primary {
  background: var(--color-red);
}

.btn-primary:hover {
  background: var(--color-red-dark);
}

.btn-secondary {
  background: var(--color-blue);
}

.btn-secondary:hover {
  background: var(--color-blue-dark);
}

.btn-dark {
  background: #1a1a1a;
}

.btn-dark:hover {
  background: #000;
}

.btn-row {
  display: flex;
  gap: 10px;
}

.btn-row .btn {
  flex: 1;
}

/* Links and helper rows */
.field-row-end {
  display: flex;
  justify-content: flex-end;
  margin-top: -6px;
  margin-bottom: 16px;
}

.link-small {
  font-size: 0.9rem;
}

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--color-text-muted);
  margin: 18px 0;
  font-style: italic;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--color-card-border);
}

.divider::before {
  margin-right: 10px;
}

.divider::after {
  margin-left: 10px;
}

.below-card-link {
  text-align: center;
  margin-top: 18px;
}

/* Generic modal/popup used for the battle picker and group actions */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 10, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--color-card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 28px 20px 20px;
  text-align: left;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--color-red);
  font-size: 22px;
  line-height: 1;
  padding: 6px;
  cursor: pointer;
}

.modal-title {
  margin-bottom: 16px;
  text-align: left;
}

.battle-list {
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
}

.battle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 4px;
  cursor: pointer;
  border-bottom: 1px solid var(--color-card-border);
  color: var(--color-text-dark);
}

.battle-row:last-child {
  border-bottom: none;
}

.battle-row.active-battle {
  color: var(--color-red);
  font-weight: 600;
}

.battle-row .battle-edit {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 18px;
  padding: 4px;
  cursor: pointer;
  display: flex;
  flex-shrink: 0;
}

.modal-footer-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.form-status {
  min-height: 1.2em;
  text-align: center;
  font-size: 0.9rem;
  margin-top: 4px;
}

.form-status.error {
  color: var(--color-red);
}

.form-status.success {
  color: var(--color-blue);
}

.hidden {
  display: none !important;
}

/* 2x2 grid of primary action buttons, e.g. dashboard quick actions */
.nav-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 380px;
}

.summary-line {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-top: 6px;
}

/* Pages with a fixed bottom nav need extra bottom clearance */
.app-shell.with-bottom-nav {
  padding-bottom: 96px;
}

/* Bottom nav, shared by inner app pages */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--color-card-bg);
  border-top: 1px solid var(--color-card-border);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
}

/* Keeps the icons from spreading edge-to-edge on wide viewports */
.bottom-nav-inner {
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: 100%;
  max-width: 480px;
  padding: 0 16px;
}

.bottom-nav a {
  color: var(--color-text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.7rem;
  gap: 2px;
}

.bottom-nav a.active, .bottom-nav a:hover {
  color: var(--color-red);
}

.bottom-nav .material-icons,
.bottom-nav .material-symbols-outlined {
  font-size: 22px;
}

/* Tablet / laptop */
@media (min-width: 640px) {
  .app-shell {
    padding-top: 96px;
  }

  .app-header {
    padding: 16px 24px;
  }

  .card {
    max-width: 420px;
    padding: 32px 28px;
  }

  .page-title {
    font-size: 2rem;
  }
}

/* Desktop: lay the group-card stack out horizontally instead of stacked.
   align-items switches to flex-start because the active card is now taller
   (it carries its own action buttons) — the others should size to their
   own content rather than stretch to match it. */
@media (min-width: 900px) {
  .stack {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: center;
    max-width: 1040px;
  }

  .stack .group-card {
    flex: 0 1 220px;
    max-width: 220px;
  }

  .stack .group-card.active {
    flex: 0 1 320px;
    max-width: 320px;
  }
}
