:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-muted: #edf1ed;
  --ink: #17221c;
  --muted: #68736c;
  --line: #dce3dd;
  --green: #247a52;
  --green-dark: #185c3d;
  --coral: #e96b5a;
  --yellow: #f4c95d;
  --blue: #2f72b7;
  --danger: #b33a3a;
  --shadow: 0 12px 35px rgba(26, 49, 36, .08);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); }
button, input, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; }
.topbar {
  position: fixed; inset: 0 0 auto 0; height: 70px; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; background: rgba(246, 247, 244, .96);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(12px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-size: 20px; font-weight: 800; }
.brand img { border-radius: 50%; box-shadow: 0 4px 14px rgba(36, 122, 82, .15); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.profile-button { width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--ink); color: white; font-weight: 800; }

.sidebar {
  position: fixed; left: 0; top: 70px; bottom: 0; width: 230px;
  padding: 28px 18px; border-right: 1px solid var(--line);
  background: #f1f4f0; z-index: 20;
  display: flex; flex-direction: column; justify-content: space-between;
}
.side-nav { display: grid; gap: 6px; }
.side-nav button {
  min-height: 46px; display: flex; align-items: center; gap: 12px;
  border: 0; border-radius: 6px; padding: 0 14px; color: var(--muted);
  background: transparent; text-align: left; font-weight: 650;
}
.side-nav button span:first-child { width: 22px; font-size: 22px; text-align: center; }
.side-nav button:hover, .side-nav button.active { color: var(--green-dark); background: #dfeae2; }
.nav-count { margin-left: auto; min-width: 22px; padding: 2px 7px; border-radius: 10px; background: var(--coral); color: white; text-align: center; font-size: 12px; }
.privacy-link { color: var(--muted); padding: 12px 14px; font-size: 13px; }

.main-content { min-height: 100vh; padding: 110px 36px 60px; }
.sidebar:not(.hidden) + .main-content { margin-left: 230px; }
.screen, .login-view { width: min(1040px, 100%); margin: 0 auto; }
.center-state { min-height: 60vh; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--green); animation: spin .75s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.screen-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.screen-heading.compact { align-items: center; }
.kicker { margin: 0 0 7px; color: var(--green); font-size: 13px; font-weight: 800; text-transform: uppercase; }
h1 { margin: 0; font-size: 42px; line-height: 1.08; letter-spacing: 0; }
h2 { letter-spacing: 0; }
.screen-meta { margin: 10px 0 0; color: var(--muted); }

.primary-command, .secondary-command, .danger-command, .icon-command, .file-button, .primary-link {
  min-height: 42px; border-radius: 6px; padding: 10px 16px; border: 1px solid transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; font-weight: 750;
}
.primary-command, .primary-link { color: white; background: var(--green); }
.primary-command:hover, .primary-link:hover { background: var(--green-dark); }
.secondary-command, .icon-command, .file-button { color: var(--ink); background: var(--surface); border-color: var(--line); }
.danger-command { color: var(--danger); background: #fff5f3; border-color: #f0cbc5; }
.wide { width: 100%; }
button:disabled { cursor: default; opacity: .55; }

.wish-composer { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; margin-bottom: 26px; box-shadow: var(--shadow); }
.wish-composer > label { display: block; margin-bottom: 8px; font-weight: 750; }
textarea, input { width: 100%; border: 1px solid #cbd5cc; border-radius: 6px; padding: 12px 13px; color: var(--ink); background: white; outline: 0; }
textarea { resize: vertical; min-height: 58px; }
textarea:focus, input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(36, 122, 82, .12); }
.composer-actions { min-height: 48px; display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.composer-actions .primary-command { margin-left: auto; }
.file-name { min-width: 0; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.wish-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.wish-card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; }
.wish-media { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: var(--surface-muted); }
.wish-media.video { object-fit: contain; background: #101410; }
.wish-body { padding: 16px; display: flex; flex-direction: column; gap: 13px; min-height: 170px; flex: 1; }
.wish-text { margin: 0; line-height: 1.48; overflow-wrap: anywhere; white-space: pre-wrap; }
.wish-text a { color: var(--blue); }
.status { align-self: flex-start; border-radius: 12px; padding: 4px 9px; font-size: 12px; font-weight: 800; background: var(--surface-muted); color: var(--muted); }
.status.free { background: #dff1e5; color: #17653f; }
.status.mine { background: #e2eef9; color: #235f96; }
.status.reserved { background: #f3eee0; color: #745d22; }
.status.gifted { background: #ece8f5; color: #5f4d83; }
.card-actions { margin-top: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.card-actions button { min-height: 38px; padding: 8px 12px; border-radius: 6px; border: 1px solid var(--line); background: white; font-weight: 720; }
.card-actions .gift-action { background: var(--green); border-color: var(--green); color: white; }
.card-actions .delete-action { color: var(--danger); }

.empty-state { min-height: 320px; padding: 50px 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; border: 1px dashed #cbd5cc; border-radius: 8px; color: var(--muted); }
.empty-state h2 { color: var(--ink); margin: 14px 0 6px; font-size: 21px; }
.empty-state p { margin: 0; }

.friend-list { display: grid; gap: 10px; }
.friend-row { min-height: 76px; display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 14px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.friend-row button.open-friend { border: 0; background: transparent; text-align: left; padding: 0; color: var(--ink); }
.friend-row strong { display: block; font-size: 16px; }
.friend-row small { display: block; margin-top: 4px; color: var(--muted); }
.new-label { color: var(--coral); font-size: 12px; font-weight: 850; }
.remove-friend { width: 38px; height: 38px; border-radius: 6px; border: 1px solid var(--line); background: white; color: var(--muted); }

.settings-section { width: min(700px, 100%); padding: 22px 0; border-top: 1px solid var(--line); }
.settings-section h2 { margin: 0 0 14px; font-size: 18px; }
.settings-section p { color: var(--muted); }
.inline-form { display: flex; gap: 10px; }
.inline-form input { width: 150px; }
.toggle-list { display: grid; gap: 1px; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.toggle-row { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 10px 14px; background: white; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: absolute; inset: 0; background: #bec8c0; border-radius: 14px; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 20px; height: 20px; top: 3px; left: 3px; border-radius: 50%; background: white; transition: .2s; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(18px); }
.account-section { margin-top: 20px; }

.login-view { min-height: calc(100vh - 170px); display: grid; place-items: center; }
.login-panel { width: min(430px, 100%); text-align: center; padding: 32px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.login-panel h1 { margin-top: 16px; font-size: 30px; }
.login-panel p { color: var(--muted); }
.login-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.messenger-button { min-height: 48px; border: 0; border-radius: 6px; color: white; font-weight: 800; }
.messenger-button.telegram { background: #229ed9; }
.messenger-button.max { background: #6b59d3; }
.fine-print { font-size: 12px; }

.modal { width: min(480px, calc(100% - 28px)); border: 0; border-radius: 8px; padding: 26px; color: var(--ink); box-shadow: 0 30px 90px rgba(15, 30, 21, .25); }
.modal::backdrop { background: rgba(18, 30, 22, .5); backdrop-filter: blur(3px); }
.modal-close { position: absolute; right: 12px; top: 10px; width: 36px; height: 36px; border: 0; background: transparent; font-size: 26px; color: var(--muted); }
.modal h2 { margin: 5px 35px 8px 0; }
.modal p { color: var(--muted); }
.modal textarea { margin: 12px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.auth-wait { text-align: center; padding: 12px 0; }
.auth-wait .spinner { margin-bottom: 20px; }
.share-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin: 16px 0 10px; }

.legal-view { width: min(780px, 100%); }
.legal-copy { background: white; border: 1px solid var(--line); border-radius: 8px; padding: 26px; line-height: 1.65; }
.legal-copy h2 { margin-top: 28px; font-size: 18px; }
.legal-copy a { color: var(--blue); }
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 100; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; max-width: min(420px, calc(100% - 30px)); padding: 12px 16px; border-radius: 6px; background: var(--ink); color: white; box-shadow: var(--shadow); transition: .2s; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

.mobile-nav { display: none; }
@media (max-width: 760px) {
  .topbar { height: 62px; padding: 0 14px; }
  .brand span { font-size: 18px; }
  .brand img { width: 38px; height: 38px; }
  .top-actions .icon-command span { display: none; }
  .top-actions .icon-command { width: 40px; padding: 8px; }
  .sidebar { display: none !important; }
  .sidebar:not(.hidden) + .main-content { margin-left: 0; }
  .main-content { padding: 88px 14px 100px; }
  .screen-heading { align-items: flex-start; margin-bottom: 20px; }
  .screen-heading h1 { font-size: 31px; }
  .screen-heading > .primary-command { display: none; }
  .wish-grid { grid-template-columns: 1fr; gap: 12px; }
  .wish-composer { padding: 14px; }
  .composer-actions { flex-wrap: wrap; }
  .composer-actions .primary-command { margin-left: 0; width: 100%; }
  .file-button { flex: none; }
  .wish-body { min-height: 0; }
  .friend-row { grid-template-columns: 1fr auto; }
  .friend-row .new-label { grid-column: 2; grid-row: 1; }
  .friend-row .remove-friend { grid-column: 2; grid-row: 2; }
  .mobile-nav { position: fixed; z-index: 40; inset: auto 0 0 0; height: calc(68px + env(safe-area-inset-bottom)); padding: 7px 10px env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(3, 1fr); background: rgba(255,255,255,.97); border-top: 1px solid var(--line); }
  .mobile-nav button { position: relative; border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .mobile-nav button > span { font-size: 22px; line-height: 24px; }
  .mobile-nav button small { font-size: 11px; }
  .mobile-nav button.active { color: var(--green); }
  .mobile-badge { position: absolute; top: 1px; left: calc(50% + 9px); width: 8px; height: 8px; border-radius: 50%; background: var(--coral); }
  .login-view { min-height: calc(100vh - 150px); }
  .login-panel { padding: 26px 18px; border: 0; box-shadow: none; background: transparent; }
  .login-buttons { grid-template-columns: 1fr; }
  .inline-form { align-items: stretch; }
  .inline-form input { width: 130px; }
  .share-row { grid-template-columns: 1fr; }
  .modal { padding: 22px 18px; }
  .legal-copy { padding: 18px; }
  .toast { bottom: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
