/* ==========================================
   Мастерская разработки игр — стили
   Основано на дизайне tlumac.me
   ========================================== */

:root {
  --brown: #39261f;
  --orange: #ff8633;
  --orange2: #ff6700;
  --light-orange: #fff4ef;
  --light-orange-2: #ffdbc2;
  --white: #ffffff;
  --light-yellow: #fff8e5;
  --light-grey: #f6f6f6;
  --yellow: #ffc219;
  --grey: #7a6f6c;
  --black: #1a1a1a;

  --font-main: 'Onest', 'Manrope', sans-serif;
  --font-ui: 'Manrope', sans-serif;

  --header-height: 60px;
  --sidebar-width: 260px;
  --border-radius: 12px;
  --border-radius-sm: 8px;
  --transition: 0.2s ease;

  --shadow-sm: 0 1px 4px rgba(57, 38, 31, 0.08);
  --shadow-md: 0 4px 16px rgba(57, 38, 31, 0.12);
  --shadow-lg: 0 8px 32px rgba(57, 38, 31, 0.16);
}

/* ==========================================
   Reset & Base
   ========================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-main);
  background-color: var(--light-grey);
  color: var(--brown);
  display: flex;
  flex-direction: column;
  font-size: 15px;
  line-height: 1.5;
}

/* ==========================================
   Header
   ========================================== */
.header {
  height: var(--header-height);
  background: var(--brown);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
  z-index: 100;
}

.header__logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--white);
}

.header__logo-icon {
  font-size: 22px;
  line-height: 1;
}

.header__logo-text {
  font-family: var(--font-main);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--white);
}

.header__subtitle {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 400;
  color: var(--light-orange-2);
  opacity: 0.85;
}

/* ==========================================
   Layout
   ========================================== */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ==========================================
   Sidebar
   ========================================== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--white);
  border-right: 1px solid var(--light-orange-2);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar__header {
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--light-orange-2);
  background: var(--light-yellow);
}

.sidebar__title {
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--grey);
}

.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}

.sidebar__nav::-webkit-scrollbar {
  width: 4px;
}
.sidebar__nav::-webkit-scrollbar-thumb {
  background: var(--light-orange-2);
  border-radius: 2px;
}

.sidebar__loading {
  padding: 20px;
  font-size: 13px;
  color: var(--grey);
  text-align: center;
}

/* Category headers */
.sidebar__category {
  padding: 14px 20px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--light-orange-2);
}

/* Game item */
.sidebar__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  text-decoration: none;
  color: var(--brown);
  font-size: 14px;
  font-weight: 500;
  user-select: none;
}

.sidebar__item:hover {
  background: var(--light-yellow);
  border-left-color: var(--light-orange-2);
}

.sidebar__item.is-active {
  background: var(--light-orange);
  border-left-color: var(--orange);
  color: var(--orange2);
  font-weight: 600;
}

.sidebar__item-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.sidebar__item-text {
  flex: 1;
  min-width: 0;
}

.sidebar__item-name {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__item-desc {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--grey);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

/* ==========================================
   Workspace
   ========================================== */
.workspace {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* panels fill workspace so welcome overlay sits on top */
.panels {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ==========================================
   Welcome screen
   ========================================== */
.welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  position: absolute;
  inset: 0;
  background: var(--light-grey);
  z-index: 20;
  transform: translateY(0);
  opacity: 1;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease;
  pointer-events: auto;
}

.welcome.is-hiding {
  transform: translateY(-40px);
  opacity: 0;
  pointer-events: none;
}

.welcome.is-hidden {
  display: none;
}

.welcome__content {
  max-width: 480px;
  text-align: center;
}

.welcome__icon {
  font-size: 64px;
  margin-bottom: 20px;
  filter: drop-shadow(0 4px 12px rgba(255, 134, 51, 0.3));
}

.welcome__title {
  font-family: var(--font-main);
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--brown);
  letter-spacing: -0.5px;
}

.welcome__desc {
  font-size: 15px;
  color: var(--grey);
  line-height: 1.7;
  margin-bottom: 24px;
}

.welcome__hint {
  display: inline-block;
  background: var(--light-yellow);
  border: 1px dashed var(--light-orange-2);
  border-radius: var(--border-radius-sm);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--orange2);
}

/* ==========================================
   Panels (editor + preview)
   ========================================== */

.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--white);
}

.panel--editor {
  flex: 1;
  min-width: 300px;
}

.panel--preview {
  flex: 1;
  min-width: 300px;
  border-left: 1px solid var(--light-orange-2);
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--light-yellow);
  border-bottom: 1px solid var(--light-orange-2);
  flex-shrink: 0;
  height: 46px;
}

.panel__title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--grey);
}

.panel__actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel__body {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.panel__body--editor {
  background: #282a36;
  display: flex;
  flex-direction: column;
}

.panel__body--preview {
  background: var(--white);
}

/* ==========================================
   Divider (resize handle)
   ========================================== */
.panel-divider {
  width: 5px;
  cursor: col-resize;
  background: var(--light-orange-2);
  flex-shrink: 0;
  transition: background var(--transition);
  position: relative;
  z-index: 10;
}

.panel-divider:hover,
.panel-divider.is-dragging {
  background: var(--orange);
}

/* ==========================================
   Buttons
   ========================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  line-height: 1;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.96);
}

.btn--primary {
  background: var(--orange);
  color: var(--white);
  padding: 6px 16px;
  box-shadow: 0 2px 8px rgba(255, 134, 51, 0.3);
}

.btn--primary:hover {
  background: var(--orange2);
  box-shadow: 0 4px 12px rgba(255, 103, 0, 0.35);
}

.btn--icon {
  background: var(--white);
  color: var(--grey);
  border: 1px solid var(--light-orange-2);
  padding: 5px 10px;
  font-size: 14px;
  border-radius: var(--border-radius-sm);
}

.btn--icon:hover {
  background: var(--light-orange);
  color: var(--orange2);
  border-color: var(--orange);
}

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

/* Панель поиска/замены */
.search-bar {
  background: #2b2b2b;
  border-bottom: 2px solid var(--orange);
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
}

.search-bar[hidden] {
  display: none;
}

.search-bar__row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.search-bar__input {
  flex: 1;
  background: #1e1e1e;
  border: 1px solid #555;
  border-radius: 4px;
  color: #fff;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 4px 8px;
  outline: none;
  min-width: 0;
}

.search-bar__input:focus {
  border-color: var(--orange);
}

.search-bar__input.search-bar__input--nomatch {
  border-color: #c0392b;
  background: #2d1a1a;
}

.search-bar__btn {
  background: #3a3a3a;
  border: 1px solid #555;
  border-radius: 4px;
  color: #ccc;
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.search-bar__btn:hover {
  background: var(--orange);
  color: #fff;
  border-color: var(--orange);
}

.search-bar__btn--text {
  font-family: 'Manrope', sans-serif;
  font-size: 12px;
}

.search-bar__count {
  font-family: 'Manrope', sans-serif;
  font-size: 11px;
  color: #888;
  white-space: nowrap;
  min-width: 50px;
}

.search-bar__close {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  flex-shrink: 0;
}

.search-bar__close:hover { color: #fff; }

/* ==========================================
   CodeMirror editor overrides
   ========================================== */
.CodeMirror {
  height: 100% !important;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 14px;
  line-height: 1.65;
  border-radius: 0;
}

.CodeMirror-scroll {
  height: 100%;
}

/* Диалог поиска/замены */
.CodeMirror-dialog {
  background: #2b2b2b;
  border-bottom: 2px solid var(--orange);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Manrope', sans-serif;
  font-size: 13px;
  color: #ccc;
}

.CodeMirror-dialog input {
  background: #1e1e1e;
  border: 1px solid #555;
  border-radius: 4px;
  color: #fff;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 3px 8px;
  outline: none;
  min-width: 180px;
}

.CodeMirror-dialog input:focus {
  border-color: var(--orange);
}

.CodeMirror-search-hint {
  color: #888;
  font-size: 11px;
}

/* Подсветка совпадений поиска */
.cm-search-match {
  background: rgba(255, 134, 51, 0.25);
  border-radius: 2px;
}

.cm-search-active {
  background: rgba(255, 194, 25, 0.55);
  border-radius: 2px;
  outline: 1px solid var(--orange);
}

/* Подсветка найденных совпадений */
.cm-matchhighlight {
  background: rgba(255, 134, 51, 0.25);
  border-radius: 2px;
}

.CodeMirror-focused .cm-matchhighlight {
  background: rgba(255, 194, 25, 0.3);
}

/* ==========================================
   Preview iframe
   ========================================== */
#previewFrame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: var(--white);
}

.preview__error {
  position: absolute;
  inset: 0;
  background: #fff5f5;
  padding: 24px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: #c0392b;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ==========================================
   Auto-run indicator
   ========================================== */
.autorun-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--grey);
  padding: 3px 8px;
  background: var(--light-grey);
  border-radius: 20px;
  border: 1px solid var(--light-orange-2);
}

.autorun-badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #aaa;
  flex-shrink: 0;
}

.autorun-badge__dot.is-running {
  background: var(--orange);
  animation: pulse 1s ease infinite;
}

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

/* ==========================================
   Toast notifications
   ========================================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  background: var(--brown);
  color: var(--white);
  padding: 10px 18px;
  border-radius: var(--border-radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease forwards;
  pointer-events: auto;
}

.toast--success {
  background: #2e7d32;
}

.toast--error {
  background: #c62828;
}

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

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

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 220px;
  }
  .header__subtitle {
    display: none;
  }
  .panels {
    flex-direction: column;
  }
  .panel--preview {
    border-left: none;
    border-top: 1px solid var(--light-orange-2);
  }
  .panel-divider {
    width: 100%;
    height: 5px;
    cursor: row-resize;
  }
}

@media (max-width: 520px) {
  .sidebar {
    position: fixed;
    left: -100%;
    top: var(--header-height);
    height: calc(100% - var(--header-height));
    z-index: 50;
    box-shadow: var(--shadow-lg);
    transition: left var(--transition);
  }
  .sidebar.is-open {
    left: 0;
  }
}
