:root {
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --text: #17211d;
  --muted: #637069;
  --line: #dbe4dd;
  --teal: #1f7a73;
  --teal-dark: #145a55;
  --coral: #c75044;
  --amber: #d99722;
  --focus: #2e8fd6;
  --shadow: 0 16px 40px rgba(23, 33, 29, 0.08);
}

* {
  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;
  line-height: 1.5;
  letter-spacing: 0;
  background:
    linear-gradient(180deg, rgba(31, 122, 115, 0.08), rgba(31, 122, 115, 0) 260px),
    var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

:focus-visible {
  outline: 3px solid rgba(46, 143, 214, 0.55);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 72px;
  padding: 0 28px;
  border-bottom: 1px solid rgba(219, 228, 221, 0.9);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: max-content;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  border: 1px solid var(--line);
  overflow: hidden;
  background: #ffffff;
}

.brand-logo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.main-nav,
.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.main-nav {
  flex: 1;
}

.main-nav a,
.nav-actions a,
.link-button {
  min-height: 40px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.main-nav a.active,
.nav-actions a.active,
.main-nav a:hover,
.nav-actions a:hover,
.link-button:hover {
  color: var(--teal-dark);
  background: rgba(31, 122, 115, 0.1);
}

.inline-form {
  display: inline;
  margin: 0;
}

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 56px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.15;
}

h2 {
  margin: 0 0 18px;
  font-size: 22px;
  line-height: 1.25;
}

h3 {
  margin: 0 0 4px;
  font-size: 17px;
}

.auth-panel,
.account-grid,
.admin-grid {
  display: grid;
  grid-template-columns: minmax(240px, 0.8fr) minmax(320px, 1fr);
  gap: 28px;
  align-items: start;
}

.auth-panel.compact {
  grid-template-columns: minmax(240px, 0.75fr) minmax(320px, 460px);
}

.panel-copy,
.profile-card,
.form-card,
.board-panel,
.tray-panel,
.rank-table-wrap,
.image-row,
.empty-state,
.stat-grid > div,
.empty-inline {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-copy,
.profile-card,
.form-card,
.board-panel,
.tray-panel,
.empty-state,
.empty-inline {
  padding: 24px;
}

.form-card {
  display: grid;
  gap: 16px;
}

.form-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
}

.form-card input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: #fbfcfb;
}

.form-card small,
.form-error {
  color: var(--coral);
  font-weight: 700;
}

.form-error,
.form-success {
  margin: 0;
  padding: 11px 12px;
  border-radius: 8px;
}

.form-error {
  border: 1px solid rgba(199, 80, 68, 0.25);
  background: rgba(199, 80, 68, 0.08);
}

.form-success {
  border: 1px solid rgba(31, 122, 115, 0.25);
  color: var(--teal-dark);
  background: rgba(31, 122, 115, 0.09);
  font-weight: 800;
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 116px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 10px 16px;
  font-weight: 800;
}

.primary-button {
  color: #ffffff;
  background: var(--teal);
}

.primary-button:hover {
  background: var(--teal-dark);
}

.secondary-button {
  color: var(--teal-dark);
  border-color: rgba(31, 122, 115, 0.28);
  background: rgba(31, 122, 115, 0.09);
}

.danger-button {
  color: #ffffff;
  background: var(--coral);
}

.as-link {
  width: fit-content;
}

.game-header,
.section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.score-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.score-strip span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 800;
}

.score-strip strong {
  color: var(--teal-dark);
  font-size: 20px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(280px, 360px);
  gap: 22px;
  align-items: start;
}

.puzzle-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 2px solid #b9c8bd;
  border-radius: 8px;
  overflow: hidden;
  background: #edf2ed;
}

.slot {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  border-right: 1px solid #b9c8bd;
  border-bottom: 1px solid #b9c8bd;
  background: linear-gradient(135deg, rgba(31, 122, 115, 0.07), rgba(217, 151, 34, 0.08));
  overflow: hidden;
}

.slot:nth-child(4n) {
  border-right: 0;
}

.slot:nth-last-child(-n + 4) {
  border-bottom: 0;
}

.slot.filled {
  background: #ffffff;
}

.piece-tray {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.piece {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid rgba(23, 33, 29, 0.14);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(23, 33, 29, 0.08);
}

.piece img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.piece.selected {
  border-color: var(--amber);
  box-shadow: 0 0 0 4px rgba(217, 151, 34, 0.25);
}

.slot .piece {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.game-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.game-message {
  min-height: 28px;
  margin: 14px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.game-message[data-type="success"] {
  color: var(--teal-dark);
}

.game-message[data-type="error"] {
  color: var(--coral);
}

.next-game-link {
  margin-top: 12px;
}

.rank-table-wrap {
  overflow-x: auto;
}

.rank-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
}

.rank-table th,
.rank-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.rank-table th {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  background: var(--surface-2);
}

.rank-table tbody tr:last-child td {
  border-bottom: 0;
}

.muted-cell {
  color: var(--muted);
  text-align: center;
}

.empty-state {
  max-width: 720px;
  margin: 38px auto;
  text-align: center;
}

.empty-state p {
  color: var(--muted);
}

.empty-state .primary-button {
  margin: 10px auto 0;
}

.profile-card dl {
  display: grid;
  gap: 12px;
  margin: 22px 0 0;
}

.profile-card div {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 12px;
}

.profile-card dt {
  color: var(--muted);
  font-weight: 800;
}

.profile-card dd {
  margin: 0;
  font-weight: 700;
}

.admin-page {
  display: grid;
  gap: 20px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.stat-grid > div {
  padding: 18px;
}

.stat-grid span {
  display: block;
  color: var(--muted);
  font-weight: 800;
}

.stat-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 30px;
  line-height: 1.1;
}

.admin-grid {
  grid-template-columns: minmax(300px, 380px) 1fr;
}

.image-list {
  display: grid;
  gap: 12px;
}

.image-row {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 12px;
}

.image-row img {
  display: block;
  width: 150px;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-2);
}

.image-row p {
  margin: 2px 0;
  color: var(--muted);
}

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
  }

  .main-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
  }

  .nav-actions {
    margin-left: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .auth-panel,
  .auth-panel.compact,
  .account-grid,
  .admin-grid,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .game-header,
  .section-title {
    align-items: start;
    flex-direction: column;
  }

  .piece-tray {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .image-row {
    grid-template-columns: 110px 1fr;
  }

  .image-row form {
    grid-column: 1 / -1;
  }

  .danger-button {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .page-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 22px;
  }

  h1 {
    font-size: 28px;
  }

  .panel-copy,
  .profile-card,
  .form-card,
  .board-panel,
  .tray-panel,
  .empty-state,
  .empty-inline {
    padding: 18px;
  }

  .piece-tray {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .game-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .profile-card div {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}
