@import url('https://fonts.googleapis.com/css2?family=Berkeley+Mono:wght@400;700&display=swap');

/* ========================================
   BASE STYLES
   ======================================== */

* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.7;
  background: black;
  color: white;
  margin: 0;
  padding: 0;
}

/* Full app mode body styles */
body.full-app {
  font-family: 'Berkeley Mono', monospace;
  width: 100%;
  min-height: 100vh;
  overflow-x: auto;
}

#cardsContainer::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

#cardsContainer::-webkit-scrollbar-track {
  background: white;
}

#cardsContainer::-webkit-scrollbar-thumb {
  background: black;
  border: 2px solid white;
}

#cardsContainer::-webkit-scrollbar-thumb:hover {
  background: #333;
}

.app-font {
  font-family: 'Berkeley Mono', monospace;
}

[contenteditable] {
  -webkit-user-select: text;
  user-select: text;
}

button {
  touch-action: manipulation;
}

/* ========================================
   TUTORIAL MODE STYLES
   ======================================== */

.tutorial-mode {
  max-width: 600px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
}

.app-mode {
  max-width: 978px;
  margin: 0 auto;
  padding: 0;
}

.tutorial-text {
  font-size: 1.125rem;
  margin-bottom: 1.5rem;
  color: #ffffff;
}

.tutorial-text h1 {
  font-size: 2.5rem;
  font-weight: bold;
  margin-bottom: 2rem;
  line-height: 1.2;
}

.tutorial-button {
  display: inline-block;
  background: white;
  color: black;
  padding: 0.75rem 1.5rem;
  margin: 2rem 0;
  border: 2px solid white;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  font-size: 1rem;
  text-decoration: none;
}

.tutorial-button:hover {
  background: black;
  color: white;
  transform: translateY(-2px);
}

.tutorial-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Step-based progressive disclosure */
.tutorial-step {
  margin-bottom: 3rem;
  display: none;
}

/* Step 1 always visible */
#tutorial-step-1 {
  display: block;
}

/* Progressive step reveals */
html.step1 #tutorial-step-2 { display: block; }
html.step2 #tutorial-step-3 { display: block; }
html.step3 #tutorial-step-4 { display: block; }
html.step4 #tutorial-step-5 { display: block; }
html.step5 #step-saving { display: block; }
html.step6 #step-final { display: block; }

.tutorial-step h2 {
  font-size: 1.5rem;
  font-weight: bold;
  margin-bottom: 1rem;
}

.card-container {
  position: relative;
  min-height: 180px;
  margin: 2rem 0;
}

/* ========================================
   ANIMATIONS
   ======================================== */

.fade-in {
  animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-out {
  animation: fadeOut 0.8s ease-out forwards;
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

.expand {
  animation: expand 1s ease-out forwards;
}

@keyframes expand {
  from {
    max-width: 600px;
  }
  to {
    max-width: 978px;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes slideDown {
  from {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
}

/* ========================================
   STATE MACHINE VISIBILITY RULES - CARD LEVEL
   ======================================== */

/* Menu Button: Hidden when NO menu actions available on THIS card */
.card-wrapper:not([data-clonable="true"]):not([data-deletable="true"]) .menu-btn {
  display: none !important;
}

/* Clone Button: Hidden when clonable is false on THIS card */
.card-wrapper:not([data-clonable="true"]) .clone-btn {
  display: none !important;
}

/* Delete Button: Hidden when deletable is false on THIS card */
.card-wrapper:not([data-deletable="true"]) .delete-btn {
  display: none !important;
}

/* Context Menu: Hidden when no actions available on THIS card */
.card-wrapper:not([data-clonable="true"]):not([data-deletable="true"]) .context-menu {
  display: none !important;
}

/* Drag Handle: Hidden when movable is false on THIS card */
.card-wrapper:not([data-movable="true"]) .drag-handle {
  display: none !important;
}

/* Drag Handle: Move cursor only when movable on THIS card */
.card-wrapper[data-movable="true"] .drag-handle {
  cursor: move;
  touch-action: none;
}

/* Card Wrapper: Prevent selection when draggable */
.card-wrapper[data-movable="true"] {
  -webkit-user-select: none;
  user-select: none;
}

.card-wrapper:not([data-movable="true"]) {
  -webkit-user-select: auto;
  user-select: auto;
}

/* Editable Content: Focus outline when THIS card is editable */
.card-wrapper[data-editable="true"] [contenteditable="true"]:focus {
  outline: 1px dashed rgba(255, 255, 255, 0.3);
  outline-offset: 2px;
}

/* ========================================
   CARDS
   ======================================== */

.card-wrapper {
  position: absolute;
}

.card-wrapper:focus {
  outline: 2px solid #60a5fa;
  outline-offset: 4px;
  border-radius: 4px;
}

.card {
  background: black;
  border: 1px solid white;
  width: 184.8px;
  min-height: 121.2px;
  display: flex;
  position: relative;
  touch-action: pan-y;
}

.card.dragging {
  opacity: 0.8;
  z-index: 1000;
  cursor: move !important;
  position: absolute !important;
}

.drag-handle {
  background: black;
  border-right: 1px solid white;
  width: 28.8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  user-select: none;
  -webkit-user-select: none;
}

.drag-handle .dot {
  background: white;
  width: 3px;
  height: 3px;
}

.card-content {
  flex: 1;
  padding: 12px;
  position: relative;
}

.card-text {
  font-size: 14.4px;
  line-height: 22.8px;
}

.card-text[contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
}

/* ========================================
   CONTEXT MENU
   ======================================== */

.context-menu {
  position: absolute;
  left: 183.8px;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: -1px;
  z-index: 1001;
}

.context-menu.hidden {
  display: none;
}

.card-wrapper:has(.context-menu:not(.hidden)) {
  z-index: 1000;
}

.context-menu button {
  background: black;
  border: 1px solid white;
  width: 88px;
  height: 31px;
  font-size: 16px;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Berkeley Mono', monospace;
}

.context-menu button:hover {
  background: white;
  color: black;
}

/* Menu Button */
.menu-btn {
  position: absolute;
  top: -1px;
  right: -1px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  background: black;
  border: 1px solid white;
  padding: 4px;
}

.menu-btn:hover {
  opacity: 0.7;
}

.menu-btn .dot {
  background: white;
  width: 2.25px;
  height: 2.25px;
}

/* ========================================
   PROPERTY APPLICATORS (FULL APP)
   ======================================== */

.property-applicator {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  cursor: grab;
  transition: all 0.2s;
  user-select: none;
  font-size: 14px;
  font-weight: 500;
}

.property-applicator:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateX(-2px);
}

.property-applicator:active {
  cursor: grabbing;
}

.property-applicator.dragging {
  opacity: 0.5;
  transform: scale(0.95);
}

.property-applicator.selected {
  background: #60a5fa;
  border-color: #60a5fa;
  color: white;
}

.property-applicator:focus {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

/* Property overlay - drop zone for property application */
.property-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  border-radius: 4px;
}

.property-overlay.active {
  pointer-events: auto;
  opacity: 1;
  background: rgba(96, 165, 250, 0.1);
  border: 2px solid #60a5fa;
}

/* Property hover on card */
.card-wrapper.property-hover {
  z-index: 100;
}

/* But open menu should be above property hover */
.card-wrapper:has(.context-menu:not(.hidden)) {
  z-index: 1000 !important;
}

.card-wrapper.property-hover .card {
  border-color: #60a5fa !important;
  color: #60a5fa !important;
  box-shadow: 0 0 0 2px #60a5fa;
  transform: scale(1.02);
  transition: all 0.2s;
}

.card-wrapper.property-hover .card-text {
  color: #60a5fa !important;
}

/* Mobile hint */
.mobile-hint {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #60a5fa;
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  z-index: 1000;
  pointer-events: none;
}

/* ========================================
   FULL APP STYLES
   ======================================== */

/* Header Buttons */
#newCardBtn:hover,
#searchInput:focus {
  background: #222;
}

/* Search fade */
.card-wrapper.faded {
  opacity: 0.2;
  pointer-events: none;
}

/* Sidebar collapse button */
#collapseSidebarBtn:hover {
  opacity: 0.7;
}

#expandSidebarBtn:hover {
  background: white;
  color: black;
}

/* ========================================
   MOBILE STYLES
   ======================================== */

@media (max-width: 768px) {
  #appHeader {
    padding: 8px 12px !important;
  }

  #appTitle {
    font-size: 18px !important;
  }

  #newCardBtn {
    font-size: 12px !important;
    padding: 6px 10px !important;
  }

  #searchInput {
    width: 150px !important;
    font-size: 12px !important;
  }

  /* Sidebar collapsed by default on mobile */
  #featureSidebar {
    transform: translateX(100%) !important;
  }

  #expandSidebarBtn {
    display: block !important;
  }
}

@media (max-width: 375px) {
  .card {
    width: 160px !important;
  }

  .context-menu {
    left: 159px !important;
  }
}

/* ========================================
   READ-ONLY MODE (NON-OWNERS)
   ======================================== */

/* Hide all edit controls for non-owners */
html[data-owner="false"] .new-card-btn,
html[data-owner="false"] .menu-btn,
html[data-owner="false"] .drag-handle,
html[data-owner="false"] .property-applicator,
html[data-owner="false"] #collapseSidebarBtn {
  display: none !important;
}

/* Disable contenteditable for non-owners */
html[data-owner="false"] [contenteditable="true"] {
  contenteditable: false;
  cursor: default;
  user-select: text;
}

/* Hide context menus for non-owners */
html[data-owner="false"] .context-menu {
  display: none !important;
}
