/* Theme tokens */
:root {
  /* Backgrounds (espresso → latte) */
  --bg-body: #1a1209;           /* Espresso Bean */
  --bg-card: #2c2116;           /* Dark Roast */
  --bg-input: #362a1e;          /* Medium Roast */
  --bg-elevated: #3d2f20;       /* Mocha */

  /* Borders */
  --border-subtle: #4a3828;     /* Cinnamon Bark */
  --border-hover: #5c4a36;      /* Toasted Walnut */

  /* Text */
  --text-heading: #f5e6d0;
  --text-body: #e8dcc8;         /* Warm Cream */
  --text-secondary: #c4b69e;    /* Wheat */
  --text-tertiary: #a08e74;     /* Burlap */
  --text-muted: #8a7a62;        /* Dried Sage */
  --text-dim: #6b5d4a;          /* Driftwood */
  --text-faint: #7a6b55;        /* Weathered Oak */
  --text-status: #b5a48a;       /* Sandstone */

  /* Accents */
  --accent: #c4956a;            /* Caramel */
  --accent-hover: #d4a87a;

  /* Game pieces */
  --piece-white-fill: #f5e6d0;
  --piece-white-stroke: #c4b496;
  --piece-black-fill: #2a1f14;  /* Espresso Shot */
  --piece-black-stroke: #1a120a; /* Black Coffee */

  /* Semantic */
  --color-success: #6b8f4a;     /* Sage Green */
  --color-error: #c45a4a;       /* Brick Red */
  --color-gold: #d4a020;        /* Honey Gold */
  --color-warning: #d4883a;     /* Burnt Orange */
  --color-draw: #c49830;        /* Mustard */

  /* Flash */
  --flash-notice-bg: #2a3620;
  --flash-notice-text: #b5d4a0;
  --flash-notice-border: #3d5a2e;
  --flash-alert-bg: #3d1e18;
  --flash-alert-text: #e8a090;
  --flash-alert-border: #6b2e22;

  /* Shadows & alpha overlays */
  --shadow-black-40: rgba(0, 0, 0, 0.4);
  --shadow-black-30: rgba(0, 0, 0, 0.3);
  --accent-glow-20: rgba(196, 149, 106, 0.2);
  --accent-glow-30: rgba(196, 149, 106, 0.3);
  --gold-glow-50: rgba(212, 160, 32, 0.5);
  --gold-glow-80: rgba(212, 160, 32, 0.8);
  --success-glow-40: rgba(107, 143, 74, 0.4);
  --success-glow-80: rgba(107, 143, 74, 0.8);
  --success-bg-20: rgba(107, 143, 74, 0.2);
  --success-bg-30: rgba(107, 143, 74, 0.3);
  --error-bg-10: rgba(196, 90, 74, 0.1);
  --error-bg-20: rgba(196, 90, 74, 0.2);
  --draw-bg-20: rgba(196, 152, 48, 0.2);
}

/* Reset and base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.app-body {
  background: var(--bg-body);
  color: var(--text-body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

a:hover {
  color: var(--accent-hover);
}

/* App header */
.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
}

.app-nav__logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-heading) !important;
  white-space: nowrap;
}

.app-nav__icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.app-nav__toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
}

.app-nav__toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-body);
  border-radius: 1px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.app-nav__toggle--active span:nth-child(1) {
  transform: rotate(45deg) translate(4px, 4px);
}

.app-nav__toggle--active span:nth-child(2) {
  opacity: 0;
}

.app-nav__toggle--active span:nth-child(3) {
  transform: rotate(-45deg) translate(4px, -4px);
}

.app-nav__links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-nav__link {
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease;
}

.app-nav__link:hover {
  background: var(--border-subtle);
  color: var(--text-heading);
}

.app-nav__link--button {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
}

.app-nav__link--cta {
  background: var(--accent);
  color: var(--bg-input) !important;
  font-weight: 600;
}

.app-nav__link--cta:hover {
  background: var(--accent-hover);
}

/* Main content */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* Mobile navigation */
@media (max-width: 767px) {
  .app-nav__toggle {
    display: flex;
  }

  .app-nav__links {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-subtle);
    padding: 8px 16px;
    gap: 4px;
  }

  .app-nav__links--open {
    display: flex;
  }

  .app-nav__link {
    width: 100%;
    padding: 10px 12px;
  }
}

/* Form styles */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-body);
  font-size: 1rem;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow-20);
}

.btn-primary {
  display: inline-block;
  padding: 10px 24px;
  background: var(--accent);
  color: var(--bg-input);
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

/* Auth form styling */
.auth-container {
  max-width: 400px;
  margin: 40px auto;
  padding: 32px;
  background: var(--bg-card);
  border-radius: 8px;
}

.auth-container h1 {
  color: var(--text-heading);
  margin-bottom: 24px;
  text-align: center;
}

.auth-container .form-links {
  text-align: center;
  margin-top: 16px;
  font-size: 0.9rem;
}

/* Skip link for keyboard/screen reader users */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: var(--bg-input);
  padding: 8px 16px;
  z-index: 200;
  font-weight: 600;
}

.skip-link:focus {
  top: 0;
}

/* Focus styles for accessibility */
.app-nav__link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:focus-visible,
.btn-primary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Error messages */
.error-messages {
  background: var(--error-bg-10);
  border: 1px solid var(--color-error);
  border-radius: 4px;
  padding: 12px;
  margin-bottom: 16px;
}

.error-messages p {
  color: var(--color-error);
  font-size: 0.85rem;
  margin: 4px 0;
}
