:root {
  --bg: #f4f2ed;
  --panel: #ffffff;
  --ink: #20231f;
  --muted: #6d746d;
  --line: #d7d9d1;
  --accent: #2f7d57;
  --accent-strong: #1f6141;
  --danger: #b93838;
  --amber: #b77a24;
  --shadow: 0 16px 42px rgba(32, 35, 31, 0.18);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body,
#app,
#map {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  letter-spacing: 0;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

#map {
  background: #e7e4dc;
}

.leaflet-control-container .leaflet-top,
.leaflet-control-container .leaflet-bottom {
  z-index: 650;
}

.map-tools {
  position: fixed;
  left: 16px;
  top: 16px;
  z-index: 700;
  display: flex;
  gap: 8px;
}

.tool-button,
.people-button,
.profile-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(32, 35, 31, 0.12);
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(32, 35, 31, 0.12);
}

.tool-button {
  width: 44px;
  height: 44px;
  border-radius: 8px;
}

.people-button {
  min-height: 44px;
  max-width: 180px;
  border-radius: 8px;
  padding: 0 12px;
  font-weight: 700;
  white-space: nowrap;
}

.plus-icon {
  position: relative;
  top: -1px;
  font-size: 28px;
  line-height: 1;
}

.geo-icon {
  font-size: 25px;
  line-height: 1;
}

.tool-button.is-active {
  background: var(--accent);
  color: #fff;
}

.icon-button.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.profile-button {
  position: fixed;
  right: 16px;
  top: 16px;
  z-index: 720;
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  overflow: hidden;
}

.avatar,
.avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 50%;
  background: #d6d9d3;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-fallback svg {
  width: 58%;
  height: 58%;
  fill: #77806f;
}

.auth-panel,
.mark-panel,
.modal,
.editor {
  border: 1px solid rgba(32, 35, 31, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.auth-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 900;
  width: min(380px, calc(100vw - 32px));
  padding: 14px;
  transform: translate(-50%, -50%);
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef0ea;
}

.tab-button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.tab-button.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(32, 35, 31, 0.08);
}

.auth-form,
.settings-form {
  display: none;
  margin-top: 14px;
}

.auth-form.is-active,
.settings-form {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 125, 87, 0.16);
}

.primary-button,
.secondary-button,
.danger-button,
.text-button {
  min-height: 40px;
  border-radius: 7px;
  padding: 0 12px;
  border: 1px solid transparent;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

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

.secondary-button {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.danger-button {
  border-color: rgba(185, 56, 56, 0.24);
  background: #fff5f3;
  color: var(--danger);
}

.text-button {
  margin-top: 12px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.form-message {
  min-height: 20px;
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 13px;
}

.form-message.is-error,
.toast.is-error {
  color: var(--danger);
}

.mark-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 860;
  width: min(430px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 96px));
  padding: 14px;
  overflow: auto;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.panel-header h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.15;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

#markOwner {
  text-transform: none;
}

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.photo-stage {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  margin-top: 12px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 8px;
  background: #242720;
}

.photo-stage[hidden],
.empty-photos[hidden] {
  display: none;
}

.photo-stage img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.photo-date,
.photo-user {
  position: absolute;
  top: 8px;
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.54);
  color: #fff;
  font-size: 12px;
}

.photo-date {
  left: 8px;
  padding: 0 8px;
}

.photo-user {
  right: 8px;
  width: 32px;
  height: 32px;
  padding: 2px;
}

.photo-nav {
  position: absolute;
  top: 50%;
  width: 34px;
  height: 44px;
  transform: translateY(-50%);
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
}

.photo-prev {
  left: 8px;
}

.photo-next {
  right: 8px;
}

.empty-photos {
  display: grid;
  place-items: center;
  min-height: 160px;
  margin-top: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.mark-engagement,
.photo-engagement {
  display: flex;
  align-items: center;
  margin-top: 10px;
}

.thumb-strip {
  display: flex;
  gap: 7px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.thumb-button {
  flex: 0 0 58px;
  width: 58px;
  height: 58px;
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  background: #e8e9e3;
}

.thumb-button.is-active {
  flex-basis: 78px;
  width: 78px;
  border-color: var(--accent);
}

.thumb-button img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.mark-comments {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(32, 35, 31, 0.1);
}

.mark-comments h2 {
  margin: 0;
  font-size: 15px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 980;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(32, 35, 31, 0.22);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(520px, 100%);
  max-height: calc(100vh - 32px);
  padding: 16px;
  overflow: auto;
}

.compact-modal {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
}

.profile-grid {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  align-items: center;
  margin-top: 16px;
}

.profile-preview {
  width: 96px;
  height: 96px;
}

.profile-line {
  margin: 0 0 7px;
  color: var(--muted);
}

.rank-field {
  display: inline-grid;
  grid-template-columns: auto minmax(86px, 112px);
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.rank-select,
.role-select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
  background: #fff;
  color: var(--ink);
}

.rank-select,
.rank-badge {
  font-family: Georgia, Cambria, "Times New Roman", serif;
  font-weight: 800;
  font-style: italic;
}

.editor {
  width: min(920px, 100%);
  max-height: calc(100vh - 32px);
  overflow: hidden;
  background: #fbfbf8;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.icon-button.accept {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
}

.icon-button.cancel {
  color: var(--danger);
}

.palette {
  display: flex;
  gap: 6px;
}

.swatch {
  width: 26px;
  height: 26px;
  border: 2px solid transparent;
  border-radius: 50%;
  padding: 0;
}

.swatch.is-active {
  border-color: var(--ink);
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 190px;
}

.zoom-control input {
  min-height: 28px;
  padding: 0;
}

.canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  max-height: calc(100vh - 112px);
  padding: 12px;
  overflow: auto;
  touch-action: none;
}

#editCanvas {
  max-width: 100%;
  max-height: calc(100vh - 136px);
  border-radius: 8px;
  background: #e8e8e2;
  box-shadow: 0 8px 28px rgba(32, 35, 31, 0.16);
  touch-action: none;
}

.avatar-mask {
  pointer-events: none;
  position: absolute;
  width: min(70vw, 520px);
  max-width: calc(100% - 24px);
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: 0 0 0 999px rgba(32, 35, 31, 0.34);
  border: 2px solid rgba(255, 255, 255, 0.9);
}

.leaflet-marker-icon.mark-avatar {
  border-radius: 50%;
  border: 2px solid #fff;
  background: #d6d9d3;
  box-shadow: 0 5px 16px rgba(32, 35, 31, 0.28);
  overflow: hidden;
}

.mark-avatar .avatar,
.mark-avatar .avatar-fallback {
  width: 100%;
  height: 100%;
}

.leaflet-marker-icon.mark-marker {
  overflow: visible;
  border: 0;
  background: transparent;
}

.mark-pin {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #d6d9d3;
  box-shadow: 0 5px 16px rgba(32, 35, 31, 0.28);
}

.mark-pin .avatar,
.mark-pin .avatar-fallback {
  width: 100%;
  height: 100%;
}

.mark-label {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 5px);
  max-width: 150px;
  transform: translateX(-50%);
  border-radius: 7px;
  padding: 3px 7px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(32, 35, 31, 0.16);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mark-rank {
  position: absolute;
  left: 50%;
  top: calc(100% + 5px);
  transform: translateX(-50%);
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(32, 35, 31, 0.88);
  color: #fff;
  box-shadow: 0 4px 12px rgba(32, 35, 31, 0.16);
  font-family: Georgia, Cambria, "Times New Roman", serif;
  font-size: 12px;
  font-weight: 800;
  font-style: italic;
  line-height: 1.15;
  white-space: nowrap;
}

.rank-SSS {
  color: #f9d766;
}

.rank-A {
  color: #8fd3ff;
}

.rank-B {
  color: #b9eab9;
}

.rank-C {
  color: #f6f2e8;
}

.rank-D {
  color: #ffb1a3;
}

.location-dot {
  width: 18px;
  height: 18px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #2f80ed;
  box-shadow: 0 0 0 6px rgba(47, 128, 237, 0.2), 0 6px 18px rgba(32, 35, 31, 0.24);
}

.invite-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.invite-bar code {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 9px;
  background: #f7f8f4;
  color: var(--accent-strong);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invite-bar code:empty {
  display: none;
}

.users-list {
  display: grid;
  gap: 4px;
  margin-top: 14px;
}

.feed-modal {
  width: min(680px, 100%);
}

.map-is-locked .leaflet-control-zoom,
.map-is-locked .leaflet-control-scale {
  opacity: 0.45;
  pointer-events: none;
}

.feed-composer {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(32, 35, 31, 0.1);
}

.feed-composer textarea {
  width: 100%;
  min-height: 104px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  font: inherit;
  line-height: 1.4;
  outline: none;
}

.feed-composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 125, 87, 0.16);
}

.feed-composer-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.switch-row {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-ui {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #d8dbd3;
  transition: background 0.16s ease;
}

.switch-ui::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(32, 35, 31, 0.22);
  transition: transform 0.16s ease;
}

.switch-row input:checked + .switch-ui {
  background: var(--accent);
}

.switch-row input:checked + .switch-ui::after {
  transform: translateX(18px);
}

.feed-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.feed-card {
  border: 1px solid rgba(32, 35, 31, 0.1);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.feed-meta,
.comment-main {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
}

.feed-meta p,
.feed-action,
.comment-author,
.comment-text {
  margin: 0;
}

.feed-avatar,
.comment-avatar,
.feed-mark-avatar {
  display: inline-flex;
  width: 38px;
  height: 38px;
}

.feed-mark-avatar {
  width: 24px;
  height: 24px;
  vertical-align: middle;
}

.professor-fallback svg {
  width: 68%;
  height: 68%;
  fill: none;
  stroke: #66705e;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.feed-action,
.feed-post-text,
.feed-photo,
.feed-actions,
.comments {
  margin-top: 10px;
}

.feed-post-text,
.comment-text {
  line-height: 1.45;
  white-space: normal;
}

.feed-photo {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border-radius: 8px;
  background: #242720;
}

.feed-link {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.feed-muted {
  color: var(--muted);
}

.rank-change {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
  font-family: Georgia, Cambria, "Times New Roman", serif;
  font-weight: 800;
  font-style: italic;
}

.old-rank {
  color: var(--muted);
  text-decoration: line-through;
}

.rank-arrow {
  color: var(--muted);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-style: normal;
}

.feed-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.like-wrap {
  position: relative;
  display: inline-flex;
}

.like-button {
  min-height: 32px;
  border: 1px solid rgba(185, 56, 56, 0.22);
  border-radius: 999px;
  padding: 0 10px;
  background: #fff8f7;
  color: var(--danger);
  font-weight: 800;
}

.like-button.is-liked {
  background: var(--danger);
  color: #fff;
}

.likes-popover {
  pointer-events: none;
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 5;
  display: none;
  min-width: 210px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 10px 24px rgba(32, 35, 31, 0.16);
}

.like-wrap:hover .likes-popover,
.like-wrap:focus-within .likes-popover {
  display: grid;
  gap: 7px;
}

.liked-user {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  font-size: 13px;
}

.liked-user .avatar,
.liked-user .avatar-fallback {
  width: 24px;
  height: 24px;
}

.comments {
  display: grid;
  gap: 8px;
}

.comment {
  border-top: 1px solid rgba(32, 35, 31, 0.08);
  padding-top: 8px;
}

.comment-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
}

.comment-author {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.comment .like-button {
  min-height: 28px;
  padding: 0 8px;
  font-size: 12px;
}

.feed-delete-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(185, 56, 56, 0.22);
  border-radius: 50%;
  background: #fff;
  color: var(--danger);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.comment .feed-delete-button {
  width: 28px;
  height: 28px;
  font-size: 16px;
}

.comment-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 2px;
}

.user-row {
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 30px 34px 34px;
  align-items: center;
  gap: 8px;
  min-height: 54px;
  border-bottom: 1px solid rgba(32, 35, 31, 0.08);
}

.user-action-menu {
  position: absolute;
  right: 36px;
  top: 44px;
  z-index: 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(32, 35, 31, 0.14);
  overflow: hidden;
}

.user-action-menu button {
  display: block;
  width: 100%;
  min-height: 36px;
  border: 0;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  white-space: nowrap;
}

.user-action-menu button:hover {
  background: #eef0ea;
}

.user-row:last-child {
  border-bottom: 0;
}

.user-name {
  min-width: 0;
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #eef0ea;
  color: var(--accent-strong);
}

.role-icon svg,
.tiny-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tiny-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.tiny-icon.danger {
  border-color: rgba(185, 56, 56, 0.24);
  color: var(--danger);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 1200;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(32, 35, 31, 0.92);
  color: #fff;
  box-shadow: var(--shadow);
}

@media (min-width: 641px) {
  #feedModal {
    inset: 70px auto 16px 16px;
    z-index: 760;
    display: block;
    width: min(430px, calc(100vw - 32px));
    padding: 0;
    background: transparent;
    pointer-events: none;
  }

  #feedModal[hidden] {
    display: none;
  }

  #feedModal .feed-modal {
    width: 100%;
    height: 100%;
    max-height: none;
    pointer-events: auto;
  }
}

@media (max-width: 640px) {
  .map-tools {
    left: 10px;
    top: 10px;
    right: 68px;
    flex-wrap: wrap;
  }

  .people-button {
    min-height: 40px;
    max-width: 126px;
    padding: 0 9px;
    font-size: 13px;
  }

  #feedBtn {
    max-width: 82px;
  }

  .profile-button {
    right: 10px;
    top: 10px;
  }

  .mark-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 72vh;
    border-radius: 8px 8px 0 0;
  }

  .profile-grid {
    grid-template-columns: 76px 1fr;
  }

  .profile-preview {
    width: 76px;
    height: 76px;
  }

  .editor-toolbar {
    flex-wrap: wrap;
  }

  .user-row {
    grid-template-columns: 38px minmax(0, 1fr) 28px 32px 32px;
    gap: 6px;
  }

  .invite-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .feed-composer-actions,
  .comment-form {
    align-items: stretch;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .feed-modal {
    max-height: calc(100vh - 20px);
  }
}
