/* ============================================
   VisuAlg Blocky - Estilos
   Tema: Tokyo Night (Storm / Day)
   ============================================ */

/* === Theme Variables === */
:root,
[data-theme="dark"] {
  /* Tokyo Night Storm */
  --bg:            #24283b;
  --bg-dark:       #1f2335;
  --bg-darker:     #1b1e2d;
  --bg-highlight:  #292e42;
  --bg-visual:     #2e3c64;
  --fg:            #c0caf5;
  --fg-dark:       #a9b1d6;
  --fg-gutter:     #3b4261;
  --comment:       #6b7394;
  --dark3:         #545c7e;
  --dark5:         #8891b5;
  --border:        #292e42;
  --blue:          #7aa2f7;
  --cyan:          #7dcfff;
  --green:         #9ece6a;
  --green1:        #73daca;
  --yellow:        #e0af68;
  --orange:        #ff9e64;
  --red:           #f7768e;
  --magenta:       #bb9af7;
  --purple:        #9d7cd8;
  --teal:          #1abc9c;

  /* Maze */
  --maze-wall:        #1b1e2d;
  --maze-path:        #414868;
  --maze-start:       #2e4a3e;
  --maze-goal:        #4a3e28;
  --maze-goal-flag:   #e0af68;
  --maze-visited:     #364a6b;
  --maze-grid-bg:     #292e42;
  --maze-grid-border: #3b4261;
  --maze-reached:     #2e4a3e;

  /* Sonar */
  --sonar-open:    rgba(158, 206, 106, 0.6);
  --sonar-blocked: rgba(247, 118, 142, 0.5);

  /* Success glow */
  --success-glow:  rgba(158, 206, 106, 0.6);
}

[data-theme="light"] {
  /* Tokyo Night Day */
  --bg:            #e1e2e7;
  --bg-dark:       #ffffff;
  /*--bg-dark:       #d0d5e3;*/
  --bg-darker:     #c4c8da;
  --bg-highlight:  #d2d4dd;
  --bg-visual:     #b7c1e3;
  --fg:            #1e3a5f;
  --fg-dark:       #4e5f99;
  --fg-gutter:     #8890b5;
  --comment:       #6b739e;
  --dark3:         #7880a3;
  --dark5:         #505882;
  --border:        #c4c8da;
  --blue:          #1286e2;
  --cyan:          #007197;
  --green:         #71b530;
  --green1:        #64a723;
  --yellow:        #edba10;
  --orange:        #d97a00;
  --red:           #e02050;
  --magenta:       #8740e0;
  --purple:        #6a3aab;
  --teal:          #0e7a65;

  /* Maze */
  --maze-wall:        #37474f;
  --maze-path:        #e8f5e9;
  --maze-start:       #c8e6c9;
  --maze-goal:        #fff8e1;
  --maze-goal-flag:   #f57f17;
  --maze-visited:     #dcedc8;
  --maze-grid-bg:     #90a4ae;
  --maze-grid-border: #546e7a;
  --maze-reached:     #c8e6c9;

  /* Sonar */
  --sonar-open:    rgba(76, 175, 80, 0.6);
  --sonar-blocked: rgba(244, 67, 54, 0.5);

  /* Success glow */
  --success-glow:  rgba(76, 175, 80, 0.6);
}

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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-dark);
  color: var(--fg);
  height: calc(100vh - 30px);
  overflow: hidden;
}

.game-container {
  display: grid;
  grid-template-columns: minmax(280px, 2fr) 3fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header"
    "maze   editor";
  height: calc(100vh - 30px);
  gap: 0;
}

/* Header */
.header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-darker);
  color: var(--fg);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  z-index: 10;
  gap: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.title {
  font-size: 1.3rem;
  font-weight: 700;
  white-space: nowrap;
}

.btn-theme {
  background: none;
  border: 1px solid var(--border);
  color: var(--orange);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-theme:hover {
  background: var(--bg-highlight);
  border-color: var(--orange);
}

/* Level selector */
.level-selector {
  height: 60px;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.level-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--dark3);
  background: transparent;
  color: var(--fg);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.2s;
  flex-shrink: 0;
}

.level-btn:hover:not(.locked) {
  background: var(--bg-visual);
  transform: scale(1.1);
}

.level-btn.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.level-btn.completed {
  border-color: var(--yellow);
  background: rgba(224, 175, 104, 0.15);
}

.level-btn.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.level-stars {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.5rem;
  white-space: nowrap;
  line-height: 1;
}

/* Maze panel */
.maze-panel {
  grid-area: maze;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.maze-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.maze-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--fg-dark);
}

.speed-control input[type="range"] {
  width: 80px;
  accent-color: var(--blue);
}

.hint-text {
  font-size: 0.85rem;
  color: var(--fg-dark);
  font-style: italic;
  min-height: 1.2em;
  padding: 4px 0;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
}

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

.btn-run {
  background: var(--green);
  color: #fff;
}

.btn-run:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-stop {
  background: var(--red);
  color: #fff;
}

.btn-stop:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-reset {
  background: var(--bg-highlight);
  color: var(--fg);
  border: 1px solid var(--border);
}

.btn-reset:hover:not(:disabled) {
  background: var(--bg-visual);
}

/* Editor panel */
.editor-panel {
  grid-area: editor;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#blocklyDiv {
  flex: 1;
  min-height: 0;
}

/* Code panel */
.code-panel {
  border-top: 1px solid var(--border);
  background: var(--bg-darker);
  color: var(--fg);
  max-height: 160px;
  display: flex;
  flex-direction: column;
  transition: max-height 0.3s ease;
}

.code-panel.collapsed {
  max-height: 32px;
}

.code-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
  background: var(--bg-dark);
}

.code-panel-header:hover {
  background: var(--bg-highlight);
}

.toggle-icon {
  transition: transform 0.3s;
  font-size: 0.7rem;
}

.code-panel.collapsed .toggle-icon {
  transform: rotate(-90deg);
}

.code-display {
  flex: 1;
  padding: 8px 12px;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  overflow-y: auto;
  white-space: pre-wrap;
  min-height: 0;
}

/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.visible {
  display: flex;
}

.modal-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-content h2 {
  margin-bottom: 12px;
  color: var(--blue);
}

.modal-error h2 {
  color: var(--red);
}

.modal-content p {
  color: var(--fg-dark);
  margin-bottom: 20px;
  font-size: 0.95rem;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.stars {
  font-size: 2rem;
  margin: 8px 0 16px;
  letter-spacing: 4px;
}

.star-filled {
  color: var(--yellow);
}

.star-empty {
  color: var(--dark3);
}

/* Certificate button (header) */
.btn-certificate {
  background: var(--bg-dark);
  /*background: none;*/
  border: 1px solid var(--yellow);
  color: var(--yellow);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  white-space: nowrap;
}

.btn-certificate:hover {
  background: rgba(224, 175, 104, 0.15);
}

/* Name input (success modal level 10) */
.input-nome {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--bg-dark);
  color: var(--fg);
  font-size: 1rem;
  text-align: center;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s;
}

.input-nome:focus {
  border-color: var(--blue);
}

#nameInputSection {
  margin-bottom: 16px;
}

#nameInputSection .btn {
  margin: 0 auto;
}

/* Certificate modal */
.certificate {
  max-width: 600px;
  padding: 0;
  background: var(--bg-dark);
}

.certificate-border {
  border: 3px double var(--yellow);
  border-radius: 10px;
  padding: 36px 32px;
  margin: 12px;
}

.cert-title {
  color: var(--yellow) !important;
  font-size: 1.5rem;
  margin-bottom: 4px !important;
}

.cert-subtitle {
  color: var(--fg-dark) !important;
  font-size: 0.85rem;
  font-style: italic;
  margin-bottom: 24px !important;
}

.cert-text {
  color: var(--fg-dark) !important;
  font-size: 0.95rem;
  margin-bottom: 4px !important;
}

.cert-nome {
  color: var(--blue);
  font-size: 1.6rem;
  font-style: italic;
  font-family: 'Georgia', 'Times New Roman', serif;
  margin: 8px 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.cert-app-name {
  color: var(--green) !important;
  font-size: 1.3rem;
  margin-bottom: 16px !important;
}

.cert-stars {
  font-size: 1.1rem;
  color: var(--yellow) !important;
  margin-bottom: 8px !important;
}

.cert-date {
  font-size: 0.85rem;
  color: var(--comment) !important;
  margin-bottom: 20px !important;
}

.cert-professor {
  font-style: italic;
  color: var(--fg-dark) !important;
  font-size: 0.95rem;
  margin-bottom: 24px !important;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.certificate .btn {
  margin: 0 auto;
}

/* Footer / Status Bar */
.footer {
  height: 30px;
  background: var(--bg-dark);
  border-radius: 8px;
  margin: 2px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  gap: 16px;
}

.footer-item {
  font-size: 12px;
  color: var(--dark5);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.footer-status {
  color: var(--green);
  font-weight: 500;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-highlight);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--dark3);
}

/* Responsive */
@media (max-width: 768px) {
  .game-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto 40vh 1fr;
    grid-template-areas:
      "header"
      "maze"
      "editor";
    overflow: auto;
  }

  .maze-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .editor-panel {
    min-height: 300px;
  }

  .code-panel {
    display: none;
  }

  .title {
    font-size: 1rem;
  }

  .level-btn {
    width: 30px;
    height: 30px;
    font-size: 0.75rem;
  }

  .footer {
    height: auto;
    min-height: 30px;
    margin: 10px;
    flex-wrap: wrap;
    padding: 6px 12px;
    gap: 4px 16px;
  }
}
