/* Buttons */
.btn-primary {
  background: var(--gradient-primary);
  color: white;
  border: none;
  padding: 14px 40px;
  border-radius: var(--radius-button);
  font-family: var(--font-main);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 15px rgba(168, 85, 247, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(168, 85, 247, 0.4);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Input fields */
.input-field {
  width: 100%;
  padding: 12px 16px;
  border: 3px solid #E5E7EB;
  border-radius: var(--radius-button);
  font-family: var(--font-main);
  font-size: 1rem;
  direction: rtl;
  transition: border-color 0.2s;
}

.input-field:focus {
  outline: none;
  border-color: var(--color-purple);
}

/* Panels / Modals */
.panel {
  background: white;
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-panel);
  padding: 30px;
}

/* Notice box */
.notice-box {
  background: var(--notice-bg);
  border-radius: 12px;
  padding: 16px;
  font-size: 0.9rem;
  line-height: 1.6;
}

.error-msg {
  color: var(--color-red);
  font-size: 0.9rem;
  min-height: 1.2em;
}

.form-group {
  width: 100%;
}

.password-field {
  position: relative;
}

.btn-eye {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--color-purple);
  cursor: pointer;
  font-family: var(--font-main);
  font-weight: 700;
}

/* Panel overlay */
.panel-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.panel-close {
  position: absolute;
  top: 12px;
  left: 12px;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  font-family: var(--font-emoji);
}

.blockly-editor-panel {
  width: 90vw;
  height: 85vh;
  max-width: none;
  display: flex;
  flex-direction: column;
}

.blockly-container {
  flex: 1;
  position: relative;
  border: 2px solid #E5E7EB;
  border-radius: 12px;
  overflow: hidden;
}

.blockly-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 12px 0 0;
}

.map-panel {
  position: relative;
  width: 80%;
  max-width: 700px;
  max-height: 80vh;
  overflow-y: auto;
  text-align: center;
}

.zone-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin: 20px 0;
}

.zone-card {
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: white;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  transition: transform 0.2s;
}

.zone-card:hover {
  transform: translateY(-4px);
}

.zone-card img {
  width: 100%;
  height: 140px;
  object-fit: cover;
}

.zone-name {
  display: block;
  padding: 10px;
  font-weight: 700;
}

.btn-edit-zone {
  display: block;
  width: 100%;
  padding: 8px;
  background: #F3F4F6;
  border: none;
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 0.85rem;
  transition: background 0.15s;
}

.btn-edit-zone:hover {
  background: #E5E7EB;
}

.zone-creator-panel {
  max-width: 600px;
  text-align: center;
}

.zone-creator-panel.wide {
  max-width: 90vw;
}

.paint-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin: 12px 0;
}

.btn-tool {
  background: #E5E7EB;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-main);
  font-weight: 700;
}

.btn-tool.active {
  background: var(--color-purple);
  color: white;
}

#mask-canvas, #edit-mask-canvas {
  border: 2px solid #E5E7EB;
  border-radius: 12px;
  cursor: crosshair;
  max-width: 100%;
}

.status-options {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin: 16px 0;
}

.status-option {
  font-size: 1.1rem;
  cursor: pointer;
}

.edit-section {
  margin: 20px 0;
  padding: 16px 0;
  border-bottom: 1px solid #E5E7EB;
}

/* Potion panel */
.potion-panel {
  text-align: center;
  background: linear-gradient(135deg, #1a0533, #2d1b69);
  color: white;
  border: 2px solid #A855F7;
}

.potion-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  padding: 20px;
}

.potion-btn {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 2px solid #A855F7;
  background: rgba(168, 85, 247, 0.2);
  cursor: pointer;
  font-size: 2rem;
  transition: transform 0.2s, box-shadow 0.2s;
}

.potion-btn:hover {
  transform: scale(1.15);
  box-shadow: 0 0 20px rgba(168, 85, 247, 0.5);
}

.potion-overlay.dissolving {
  opacity: 0;
  transition: opacity 0.3s ease-out;
}

.potion-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  margin: 4px 0;
  background: #F3F4F6;
  border-radius: 8px;
}

/* Game modal */
.game-container {
  width: 90vw;
  height: 90vh;
  position: relative;
  background: white;
  border-radius: 16px;
  overflow: hidden;
}

.game-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.game-close-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 100;
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid #E5E7EB;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
  cursor: pointer;
  font-family: var(--font-emoji);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: transform 0.15s;
}

.game-close-btn:hover {
  transform: scale(1.1);
}

/* Item creator */
.drop-zone {
  border: 3px dashed #D1D5DB;
  border-radius: 16px;
  padding: 40px;
  cursor: pointer;
  margin: 16px 0;
  transition: border-color 0.2s;
}

.drop-zone.dragover {
  border-color: var(--color-purple);
  background: rgba(168, 85, 247, 0.05);
}

.item-editor-toolbar {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 12px 0;
}

/* Chat bar */
.chat-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  padding: 10px 20px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(255,255,255,0.95);
  padding: 8px 12px;
  border-radius: 16px;
  box-shadow: 0 -2px 20px rgba(0,0,0,0.1);
}

.chat-input {
  flex: 1;
  border: none !important;
  padding: 8px !important;
}

.chat-send {
  padding: 8px 20px !important;
  background: var(--color-green) !important;
}

.emoji-toggle {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
}

.emoji-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  background: white;
  padding: 10px;
  border-radius: 12px;
  box-shadow: var(--shadow-panel);
  margin-bottom: 8px;
  justify-content: center;
}

.emoji-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  font-size: 1.5rem;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
}

.emoji-btn:hover {
  background: #F3F4F6;
}

/* User card */
.user-card-panel {
  max-width: 350px;
  text-align: center;
}

.user-card-name {
  font-size: 1.5rem;
  margin-bottom: 12px;
}

.user-card-character canvas {
  background: rgba(168, 85, 247, 0.1);
  border-radius: 16px;
  margin-bottom: 16px;
}

/* Admin context menu */
.admin-context-menu {
  position: absolute;
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow-panel);
  padding: 12px;
  z-index: 200;
  min-width: 250px;
}

.context-menu-header {
  font-weight: 700;
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.context-option {
  display: block;
  width: 100%;
  text-align: right;
  background: #F3F4F6;
  border: none;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-main);
  margin: 4px 0;
  transition: background 0.15s;
}

.context-option:hover {
  background: #E5E7EB;
}

.context-option.permanent {
  color: var(--color-red);
  font-weight: 700;
}

.btn-set-default {
  display: block;
  width: 100%;
  padding: 8px;
  background: #FEF9C3;
  border: none;
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 0.85rem;
  transition: background 0.15s;
}

.btn-set-default:hover {
  background: #FDE047;
}

/* ========================================
   Inventory V2 — Full-Screen Panel
   ======================================== */

.inventory-v2-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  transform: translateY(100%);
  transition: transform 0.3s ease-out;
}

.inventory-v2-overlay.open {
  transform: translateY(0);
}


.inventory-v2 {
  width: 100%;
  height: 100%;
  display: flex;
  background: #fafafa;
  position: relative;
}

.inventory-v2-close {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  font-family: var(--font-main);
}

.inventory-v2-close:hover {
  background: #f3f4f6;
}

.preview-coins {
  font-size: 1.2rem;
  font-weight: 700;
  color: #EAB308;
  text-align: center;
}

/* Preview panel (right, 1/4 of remaining 7/8) */
.inventory-v2-preview {
  flex: 1;
  background: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 16px;
  border-right: 1px solid #e5e7eb;
  order: 3;
}

#preview-canvas {
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 16px;
  background: #f0f4ff;
}

.preview-controls {
  width: 100%;
  display: flex;
  justify-content: center;
}

.preview-rotate {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.preview-direction {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 0.8rem;
  transition: all 0.15s;
}

.preview-direction.active {
  background: var(--color-purple);
  color: white;
  border-color: var(--color-purple);
}

.preview-direction:hover:not(.active) {
  background: #e5e7eb;
}

.preview-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 240px;
}

.preview-confirm {
  flex: 1;
  padding: 10px;
  background: var(--color-green);
  color: white;
  border: none;
  border-radius: var(--radius-button);
  font-family: var(--font-main);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}

.preview-confirm:hover:not(:disabled) {
  transform: translateY(-1px);
}

.preview-confirm:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.preview-reset {
  flex: 1;
  padding: 10px;
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #e5e7eb;
  border-radius: var(--radius-button);
  font-family: var(--font-main);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: opacity 0.15s;
}

.preview-reset:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.preview-reset:hover:not(:disabled) {
  background: #e5e7eb;
}

/* Finder panel (center, flex) */
.inventory-v2-finder {
  flex: 3;
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow-y: auto;
  order: 2;
}

.finder-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 16px;
}

.finder-title {
  font-family: var(--font-main);
  font-size: 1.3rem;
  font-weight: 700;
}

.finder-count {
  font-family: var(--font-main);
  font-size: 0.85rem;
  color: #9ca3af;
}

.finder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
}

.finder-item {
  aspect-ratio: 1;
  background: white;
  border: 2px solid #d1d5db;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.finder-item:hover {
  border-color: #9ca3af;
  transform: translateY(-2px);
}

.finder-item.equipped {
  border-color: var(--color-green);
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.3);
}

.finder-item.trying {
  border-color: var(--color-green);
  background: #f0fdf4;
}

.finder-item img {
  width: 60%;
  height: 60%;
  object-fit: contain;
}

.finder-item-name {
  font-family: var(--font-main);
  font-size: 0.7rem;
  text-align: center;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* Empty state */
.finder-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 12px;
  padding: 40px 20px;
  text-align: center;
  color: #9ca3af;
  font-family: var(--font-main);
}

.finder-empty-icon {
  width: 80px;
  height: 80px;
  opacity: 0.3;
  object-fit: contain;
}

.finder-empty-create {
  margin-top: 8px;
  padding: 10px 24px;
  background: var(--color-orange);
  color: white;
  border: none;
  border-radius: var(--radius-button);
  font-family: var(--font-main);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.15s;
}

.finder-empty-create:hover {
  transform: translateY(-2px);
}

/* Sidebar (left, 1/8 of total) */
.inventory-v2-sidebar {
  width: 12.5%;
  min-width: 68px;
  background: white;
  border-left: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 4px;
  overflow-y: auto;
  order: 1;
}

.sidebar-cat {
  width: calc(100% - 12px);
  aspect-ratio: 1 / 1;
  border: none;
  background: transparent;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  transition: all 0.15s;
}

.sidebar-cat img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sidebar-cat:hover {
  background: #f3f4f6;
}

.sidebar-cat.active {
  background: #1f2937;
}

.sidebar-cat.active img {
  filter: brightness(10);
}

.sidebar-admin-create {
  width: calc(100% - 12px);
  aspect-ratio: 1 / 1;
  margin-top: auto;
  border: 2px dashed var(--color-orange);
  background: transparent;
  border-radius: 12px;
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-orange);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.sidebar-admin-create:hover {
  background: rgba(249, 115, 22, 0.1);
}

/* Mobile responsive */
@media (max-width: 768px) {
  .inventory-v2 {
    flex-direction: column;
  }

  /* Sidebar becomes horizontal strip at top */
  .inventory-v2-sidebar {
    order: 1;
    width: 100%;
    height: auto;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid #e5e7eb;
    padding: 8px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
  }

  .sidebar-cat {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
  }

  .sidebar-admin-create {
    width: 40px;
    height: 40px;
    margin-top: 0;
    margin-left: auto;
    flex-shrink: 0;
  }

  /* Finder takes full width */
  .inventory-v2-finder {
    order: 2;
    flex: 1;
    overflow-y: auto;
  }

  /* Preview becomes compact strip at bottom */
  .inventory-v2-preview {
    order: 3;
    width: 100%;
    flex-direction: row;
    padding: 10px 16px;
    gap: 12px;
    border-left: none;
    border-top: 1px solid #e5e7eb;
  }

  #preview-canvas {
    width: 80px;
    max-width: 80px;
    aspect-ratio: 1 / 1;
  }

  .preview-controls {
    width: auto;
  }

  .preview-rotate {
    flex-direction: column;
    gap: 4px;
  }

  .preview-direction {
    padding: 4px 8px;
    font-size: 0.7rem;
  }

  .preview-actions {
    max-width: none;
    width: auto;
    flex-direction: column;
    gap: 6px;
  }

  .preview-confirm,
  .preview-reset {
    padding: 8px 16px;
    font-size: 0.8rem;
  }
}

/* ========================================
   MegaTolk Sidebar
   ======================================== */

.megatolk-sidebar {
  position: absolute;
  top: 0;
  right: 0;
  width: calc(100% / 6);
  min-width: 280px;
  height: 100%;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  z-index: 50;
  font-family: var(--font-main);
  direction: rtl;
  transform: translateX(-100%);
  transition: transform 0.3s ease-out;
}

.megatolk-sidebar.open {
  transform: translateX(0);
}

.megatolk-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--gradient-primary);
  color: white;
}

.megatolk-close {
  background: none;
  border: none;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  font-family: var(--font-main);
}

.megatolk-title {
  flex: 1;
  margin: 0;
  font-size: 1.1rem;
}

.megatolk-new-group {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  font-family: var(--font-main);
}

.megatolk-tabs {
  display: flex;
  border-bottom: 2px solid #E5E7EB;
}

.megatolk-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  font-family: var(--font-main);
  font-size: 0.9rem;
  cursor: pointer;
  color: #6B7280;
  position: relative;
}

.megatolk-tab.active {
  color: var(--color-purple);
  font-weight: 700;
  border-bottom: 2px solid var(--color-purple);
  margin-bottom: -2px;
}

.megatolk-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #EF4444;
  color: white;
  font-size: 0.7rem;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 4px;
  margin-right: 4px;
}

.megatolk-content {
  flex: 1;
  overflow-y: auto;
}

.megatolk-conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #F3F4F6;
  transition: background 0.15s;
}

.megatolk-conv-item:hover {
  background: #F9FAFB;
}

.megatolk-conv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.megatolk-conv-info {
  flex: 1;
  min-width: 0;
}

.megatolk-conv-name {
  font-weight: 700;
  font-size: 0.9rem;
}

.megatolk-conv-preview {
  font-size: 0.8rem;
  color: #9CA3AF;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.megatolk-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid #E5E7EB;
  background: white;
}

.megatolk-back {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
}

.megatolk-chat-name {
  font-weight: 700;
  font-size: 1rem;
}

.megatolk-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.megatolk-msg {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 0.9rem;
  word-wrap: break-word;
}

.megatolk-msg.own {
  align-self: flex-start;
  background: var(--color-purple);
  color: white;
  border-bottom-right-radius: 4px;
}

.megatolk-msg.other {
  align-self: flex-end;
  background: #F3F4F6;
  border-bottom-left-radius: 4px;
}

.megatolk-msg-name {
  font-size: 0.75rem;
  font-weight: 700;
  color: #6B7280;
  margin-bottom: 2px;
}

.megatolk-msg.other .megatolk-msg-name {
  color: #374151;
}

.megatolk-typing-indicator {
  padding: 4px 16px;
  font-size: 0.8rem;
  color: #9CA3AF;
  font-style: italic;
}

.megatolk-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #E5E7EB;
  background: white;
}

.megatolk-input {
  flex: 1;
}

.megatolk-send {
  padding: 8px 16px;
}

.megatolk-request-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #F3F4F6;
}

.megatolk-request-name {
  font-weight: 700;
}

.megatolk-request-actions {
  display: flex;
  gap: 6px;
}

.megatolk-request-actions .btn-primary {
  padding: 4px 12px;
  font-size: 0.85rem;
}

.megatolk-hud-btn {
  position: relative;
}

.megatolk-hud-badge {
  position: absolute;
  top: -4px;
  left: -4px;
  background: #EF4444;
  color: white;
  font-size: 0.65rem;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  font-family: var(--font-main);
  font-weight: 700;
}

@media (max-width: 768px) {
  .megatolk-sidebar {
    width: 100%;
    min-width: auto;
  }
}
