/* =========================================================
   WHOI — Fantasy Verhalen Maker PRO
   Met animaties, verhaal & immersive mode
   ========================================================= */

/* Basis */
* { box-sizing: border-box; margin:0; padding:0; }

html, body {
  width:100%; 
  height:100%;
  overscroll-behavior:none;
  background:#e8f4f8; 
  color:#2c3e50;
  font-family:system-ui,-apple-system,"Segoe UI",Roboto,Ubuntu,"Helvetica Neue",Arial,sans-serif;
  overflow:hidden;
}

/* Topbar - Strand thema */
.topbar {
  --h:70px; 
  height:var(--h);
  background:linear-gradient(90deg,#4a90a4,#5ab1cc);
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:10px 20px; 
  color:#fff;
  box-shadow:0 4px 12px rgba(0,0,0,.3);
  z-index:100;
}

.topbar-left h1 {
  font-size:1.4rem;
  font-weight:800;
  background: linear-gradient(90deg, #fff, #c7e9f5);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0;
}

.topbar-left .slogan {
  font-size:.95rem;
  opacity:.95;
  margin: 3px 0 0 0;
}

.topbar-right {
  display:flex;
  gap:10px;
}

.header-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,0.2);
  color: white;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s;
  backdrop-filter: blur(10px);
}

.header-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.header-btn .btn-icon {
  font-size: 18px;
}

/* Layout */
.wrapper {
  display:grid;
  grid-template-columns:240px 1fr;
  height:calc(100vh - 70px - 64px);
}

/* Sidebar - Strand kleuren */
#sidebar {
  background:#f8fbfd;
  border-right:3px solid #7fb8cc;
  display:flex;
  flex-direction:column;
  min-height:0;
  overflow:hidden;
}

.sidebar-header {
  padding: 12px 16px;
  background: linear-gradient(135deg, #5ab1cc, #6ec9e0);
  border-bottom: 2px solid #4a90a4;
}

.sidebar-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
  color: white;
}

/* Tabs/Groups */
.tabs, #groupbar {
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(60px, 1fr));
  gap:8px;
  padding:8px;
}

.tab, #groupbar button {
  background: linear-gradient(135deg, #e8f5f8, #d4ebf2);
  border: 2px solid #7fb8cc;
  border-radius:10px;
  height:60px;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  transition: all 0.2s;
  position: relative;
}

.tab img, #groupbar button img {
  width:40px;
  height:40px;
  opacity:.95;
  object-fit:contain;
}

.tab.active, #groupbar button.active {
  background: linear-gradient(135deg, #5ab1cc, #6ec9e0);
  border-color: #4a90a4;
  box-shadow: 0 4px 12px rgba(74, 144, 164, 0.4);
}

.tab:hover, #groupbar button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Items tray */
#pieces {
  flex:1;
  overflow-y:auto;
  overflow-x:hidden;
  -webkit-overflow-scrolling:touch;
  padding:8px;
  display:grid;
  grid-template-columns:repeat(auto-fill,68px);
  gap:8px;
}

#pieces img {
  width:68px;
  height:68px;
  object-fit:contain;
  background:#f0f8fa;
  border:2px solid #b8dae5;
  border-radius:10px;
  cursor:pointer;
  padding:4px;
  transition: all 0.2s;
}

#pieces img:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(74, 144, 164, 0.3);
  border-color: #5ab1cc;
}

.sidebar-footer {
  padding: 12px;
  background: linear-gradient(135deg, #e8f5f8, #d4ebf2);
  border-top: 2px solid #7fb8cc;
}

.sidebar-footer .tip {
  font-size: 12px;
  opacity: 0.85;
  text-align: center;
  margin: 0;
  color: #2c3e50;
}

/* Canvas - Fantasy achtergrond */
#canvas {
  position:relative;
  overflow:hidden;
  background: url("achtergrond_01.png") center/cover no-repeat;
  height:100%;
  min-height:400px;
  z-index:1;
}

/* Grid overlay */
#canvas.grid {
  background-image: 
    linear-gradient(rgba(127, 184, 204, 0.2) 1px, transparent 1px),
    linear-gradient(90deg, rgba(127, 184, 204, 0.2) 1px, transparent 1px);
  background-size: 40px 40px;
}

/* Pieces op canvas */
.piece {
  position:absolute;
  cursor:move;
  user-select:none;
  transition: none;
}

.piece-img {
  max-width:128px;
  max-height:128px;
  object-fit:contain;
  user-select:none;
  pointer-events:none;
  display: block;
}

.piece:active {
  cursor:grabbing;
}

/* Piece controls */
.piece-btn {
  position:absolute;
  width:22px;
  height:22px;
  display:none;
  cursor:pointer;
  opacity: 0.9;
  transition: all 0.2s;
}

.piece-btn:hover {
  opacity: 1;
  transform: scale(1.1);
}

.piece-btn.rotate {
  bottom:0;
  left:0;
}

.piece-btn.delete {
  bottom:0;
  right:0;
}

.piece:hover .piece-btn {
  display: block;
}

/* Live overlay */
#liveOverlay {
  position:absolute;
  inset:0;
  background:rgba(74, 144, 164, 0.08);
  display:none;
  pointer-events:none;
  z-index:0;
}

/* Canvas Counter */
.canvas-counter {
  position: absolute;
  top: 15px;
  left: 15px;
  background: rgba(255, 255, 255, 0.9);
  color: #4a90a4;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  backdrop-filter: blur(5px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  z-index: 50;
  border: 2px solid #7fb8cc;
}

.canvas-counter span {
  color: #2c3e50;
  font-weight: 800;
  font-size: 16px;
}

/* Footer - Strand thema */
#footerBar {
  height:64px;
  background: linear-gradient(135deg, #4a90a4, #5ab1cc);
  display:flex;
  align-items:center;
  justify-content:center;
  gap:12px;
  border-top:3px solid #3a7a8a;
  position:fixed;
  bottom:0;
  left:0;
  width:100%;
  z-index:2000;
  padding: 0 20px;
}

#btnLive {
  background: linear-gradient(135deg, #ff8c42, #ffa75d);
  border:none;
  color:#fff;
  border-radius:12px;
  padding:10px 18px;
  font-weight:800;
  font-size: 14px;
  cursor:pointer;
  transition: all 0.2s;
  box-shadow: 0 3px 10px rgba(255, 140, 66, 0.4);
}

#btnLive:hover {
  background: linear-gradient(135deg, #ffa75d, #ffb875);
  transform: scale(1.05);
}

.footer-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
}

.footer-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: translateY(-2px);
}

.footer-divider {
  width: 2px;
  height: 35px;
  background: rgba(255,255,255,0.3);
  margin: 0 8px;
}

.bg-choice {
  display:flex;
  gap:8px;
}

.bg-choice img {
  width:52px;
  height:34px;
  border-radius:8px;
  opacity:.85;
  cursor:pointer;
  border:2px solid rgba(255,255,255,.3);
  background:#f0f8fa;
  transition: all 0.2s;
  object-fit: cover;
}

.bg-choice img.active {
  border-color: #ff8c42;
  opacity: 1;
  box-shadow: 0 0 12px rgba(255, 140, 66, 0.6);
}

.bg-choice img:hover {
  opacity: 1;
  transform: scale(1.1);
}

/* Story Modal - Texel thema */
.story-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(5px);
}

.story-overlay.hidden {
  display: none;
}

.story-box {
  background: linear-gradient(135deg, #e8f5f8, #d4ebf2);
  border-radius: 16px;
  width: 90%;
  max-width: 900px;
  max-height: 85vh;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  border: 3px solid #7fb8cc;
}

.story-header {
  background: linear-gradient(90deg, #4a90a4, #5ab1cc);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid #3a7a8a;
}

.story-header h2 {
  margin: 0;
  font-size: 1.5rem;
  color: white;
}

.close-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  font-size: 24px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: rotate(90deg);
}

.story-content {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.story-input-section,
.story-display-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.story-content label {
  font-weight: 600;
  color: #4a90a4;
  font-size: 14px;
}

.story-content input,
.story-content textarea {
  background: rgba(255,255,255,0.8);
  border: 2px solid #7fb8cc;
  border-radius: 8px;
  padding: 12px;
  color: #2c3e50;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}

.story-content input:focus,
.story-content textarea:focus {
  outline: none;
  border-color: #5ab1cc;
  background: rgba(255,255,255,0.95);
}

.story-preview {
  background: rgba(255,255,255,0.6);
  border-radius: 8px;
  padding: 16px;
  min-height: 200px;
  line-height: 1.6;
  border: 2px solid #b8dae5;
}

.story-preview h4 {
  color: #4a90a4;
  margin-bottom: 12px;
}

.placeholder-text {
  color: rgba(0,0,0,0.4);
  font-style: italic;
}

.story-footer {
  padding: 20px 24px;
  background: rgba(127, 184, 204, 0.2);
  border-top: 2px solid #7fb8cc;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.btn-primary {
  background: linear-gradient(135deg, #4a90a4, #5ab1cc);
  border: none;
  color: white;
  padding: 12px 24px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(74, 144, 164, 0.5);
}

.btn-secondary {
  background: rgba(255,255,255,0.6);
  border: 2px solid #7fb8cc;
  color: #2c3e50;
  padding: 12px 24px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.8);
}

/* Help Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(5px);
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: linear-gradient(135deg, #e8f5f8, #d4ebf2);
  border-radius: 16px;
  width: 90%;
  max-width: 700px;
  max-height: 85vh;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  border: 3px solid #7fb8cc;
}

.modal-header {
  background: linear-gradient(90deg, #4a90a4, #5ab1cc);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid #3a7a8a;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.4rem;
  color: white;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  max-height: calc(85vh - 100px);
}

.help-section {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(127, 184, 204, 0.3);
}

.help-section:last-child {
  border-bottom: none;
}

.help-section h3 {
  color: #4a90a4;
  margin-bottom: 8px;
  font-size: 1.1rem;
}

.help-section p {
  line-height: 1.6;
  opacity: 0.9;
  color: #2c3e50;
}

.help-section kbd {
  background: rgba(74, 144, 164, 0.2);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 13px;
  border: 1px solid #7fb8cc;
}

/* ========================================
   IMMERSIVE MODE 
   ======================================== */
body.immersive .topbar {
  display: none;
}

body.immersive #sidebar {
  display: none;
}

body.immersive #footerBar {
  display: none;
}

body.immersive .wrapper {
  height: 100vh;
  grid-template-columns: 1fr;
}

body.immersive #canvas {
  width: 100%;
  height: 100vh;
}

body.immersive .canvas-counter {
  display: none;
}

/* Immersive exit hint */
body.immersive::after {
  content: "Druk ESC om Immersive Mode te verlaten";
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 10000;
  opacity: 1;
  animation: fadeOut 4s forwards;
  pointer-events: none;
  border: 2px solid #5ab1cc;
}

@keyframes fadeOut {
  0%, 50% { opacity: 1; }
  100% { opacity: 0; }
}

/* Live mode */
body.live-mode #canvas {
  /* Marker voor live mode */
}

/* Responsive */
@media (max-width: 768px) {
  .topbar {
    flex-wrap: wrap;
    height: auto;
  }
  
  .topbar-left h1 {
    font-size: 1.1rem;
  }
  
  .header-btn .btn-text {
    display: none;
  }
  
  .story-content {
    grid-template-columns: 1fr;
  }
  
  #sidebar {
    width: 180px;
  }
  
  .wrapper {
    grid-template-columns: 180px 1fr;
  }
}

/* Viewport height variable */
canvas {
  display: block;
  width: 100%;
  height: calc(var(--vh, 1vh) * 100);
}
