@import url('../theme.css');

:root {
  --accent:   var(--color-blue);
  --bg-hover: #1a2436;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, input, select, textarea { font-family: inherit; }
body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: .9rem;
}
.main {
  flex: 1;
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  align-items: start;
  gap: 1.5rem;
  padding: 1.2rem 1rem 1.2rem;
}
#left-col       { grid-column: 1; display: flex; flex-direction: column; gap: 1rem; }
#board-wrap     { grid-column: 2; justify-self: center; }
#ascii          { grid-column: 3; }
#right-col {
  grid-column: 3;
  display: flex;
  flex-direction: column;
  gap: .8rem;
  align-items: stretch;
}

/* Game list */
#game-list {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

/* Debug panel */
#debug-panel[hidden] { display: none; }
#debug-panel {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
#debug-content {
  font-family: var(--font-mono);
  font-size: .72rem;
  color: #666;
  display: flex;
  flex-direction: column;
  gap: .2rem;
}
.dbg-row { display: flex; gap: .4rem; }
.dbg-key { color: #444; flex-shrink: 0; }
.dbg-val { color: #888; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .2rem;
}
#game-list h2 {
  font-size: .7rem;
  color: #555;
  text-transform: uppercase;
  letter-spacing: .1em;
}
.list-header .new-btn {
  background: none; border: none; color: #555;
  font-size: 1.1rem; line-height: 1; cursor: pointer; padding: 0 .2rem;
}
.list-header .new-btn:hover { color: #bbb; }
#game-list .empty { font-size: .8rem; color: #444; font-style: italic; }
.game-entry {
  display: flex;
  align-items: center;
  gap: .4rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .4rem .6rem;
  cursor: pointer;
  transition: border-color .15s;
}
.game-entry:hover  { border-color: #444; }
.game-entry.dragging  { opacity: .4; }
.game-entry.drag-over { border-color: var(--accent); background: var(--bg-surface); }
.game-entry.active                    { border-color: var(--accent); background: #222; }
body.mode-edition .game-entry.active  { border-color: #5a9a7a; }
body:not(.mode-edition) .list-header .new-btn { visibility: hidden; }
.game-entry .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; }
.game-entry .label-edit {
  flex: 1; min-width: 0; background: none; color: #eee;
  border: none; border-bottom: 1px solid var(--accent); outline: none;
  font-size: .8rem; font-family: inherit; padding: 0;
}
.game-entry .meta  { font-size: .7rem; color: #555; flex-shrink: 0; }
.game-entry .dl    { background: none; border: none; color: #444; cursor: pointer; font-size: .85rem; padding: 0 .1rem; flex-shrink: 0; line-height: 1; }
.game-entry .dl:hover  { color: #6af; }
.game-entry .del   { background: none; border: none; color: #444; cursor: pointer; font-size: .85rem; padding: 0 .1rem; flex-shrink: 0; line-height: 1; }
.game-entry .del:hover { color: #c44; }


/* Board */
#board-wrap { display: flex; flex-direction: column; align-items: center; gap: .6rem; }
#game-title {
  font-size: .85rem;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  padding: 0 1rem;
}
#board { width: min(90vmin, 520px, calc(100dvh - 8rem)); height: min(90vmin, 520px, calc(100dvh - 8rem)); cursor: default; flex-shrink: 0; }

/* Nav */
#nav { display: none; align-items: center; gap: .4rem; }
#nav.on { display: flex; }
#nav-var { display: none; align-items: center; gap: .4rem; margin-top: .25rem; }
#nav-var.on { display: flex; }
#nav button, #nav-var button {
  background: var(--bg-surface);
  color: #bbb;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .25rem .55rem;
  cursor: pointer;
  font-size: .9rem;
  line-height: 1;
}
#nav button:hover, #nav-var button:hover { background: var(--bg-hover); }
#move-num { font-size: .8rem; color: #777; width: 5ch; text-align: center; }
#var-num  { font-size: .8rem; color: #777; width: 5ch; text-align: center; }

/* ASCII & SGF preview */
#right-col.search-open #sgf-preview { height: min(30vmin, 180px); }
#comment-preview {
  font-family: var(--font-mono);
  font-size: .65rem;
  line-height: 1.5;
  color: #8a9a7a;
  background: #161620;
  padding: .5rem .7rem;
  margin-bottom: .5rem;
  border-radius: 6px;
  border: 1px solid #223;
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  outline: none;
}
#comment-preview[hidden] { display: none; }
#meta-preview {
  font-family: var(--font-mono);
  font-size: .65rem;
  line-height: 1.5;
  color: #666;
  background: #161620;
  padding: .5rem .7rem;
  margin-bottom: .5rem;
  border-radius: 6px;
  border: 1px solid #223;
  width: 100%;
  box-sizing: border-box;
  resize: none;
  outline: none;
  white-space: pre;
  overflow-x: auto;
}
#sgf-preview {
  font-family: var(--font-mono);
  font-size: .65rem;
  line-height: 1.5;
  color: #8bc;
  background: #161620;
  padding: .6rem .7rem;
  border-radius: 6px;
  border: 1px solid #223;
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  height: min(67.5vmin, 390px);
  outline: none;
  transition: border-color .15s;
}
#sgf-preview:focus  { border-color: #46a; }
#sgf-preview.error  { border-color: #c44; }
.sgf-hint { font-size: .65rem; color: #555; text-align: right; }
#sgf-preview[hidden] ~ .sgf-hint { display: none; }
#ascii {
  font-family: var(--font-mono);
  font-size: .47rem;
  line-height: 1.45;
  color: #bbb;
  background: #161616;
  padding: .4rem .5rem;
  border-radius: 6px;
  border: 1px solid #222;
  user-select: all;
  width: 100%;
  box-sizing: border-box;
}

/* Sym boards */
#sym-boards[hidden] { display: none; }
#sym-boards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .25rem;
  width: min(90vmin, 520px, calc(100dvh - 8rem));
}
.mini-board {
  width: 100%;
  height: auto;
}

/* Mode toggle */
.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  align-self: flex-start;
}
.mode-toggle button {
  padding: .2rem .7rem;
  cursor: pointer;
  font-size: .8rem;
  color: #666;
  background: none;
  border: none;
  transition: background .15s, color .15s;
}
.mode-toggle button.active { background: var(--bg-hover); color: #ddd; }

#left-col h1 { font-size: 1rem; color: #eee; letter-spacing: .03em; }
#left-toolbar {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
#left-actions {
  display: flex;
  align-items: center;
  gap: .2rem;
  flex-wrap: wrap;
}

/* Settings */
.icon-btn {
  background: none; border: none; color: #666;
  font-size: 1.1rem; cursor: pointer; padding: .2rem .4rem;
}
.icon-btn:hover { color: #bbb; }
.icon-btn.active { color: var(--accent); }
#settings-panel {
  display: flex; flex-direction: column; gap: .5rem;
}
#settings-panel[hidden] { display: none; }
#sgf-panel[hidden] { display: none; }
#search-panel[hidden] { display: none; }
.cfg-row {
  display: flex; align-items: center; gap: .6rem;
  font-size: .8rem; color: #aaa;
}
.cfg-row[hidden] { display: none; }
#cfg-autoplay-opts[hidden] { display: none; }
#cfg-autoplay-opts { display: flex; flex-direction: column; gap: .5rem; }
.cfg-row label { flex: 1; }
.cfg-row small { color: #555; }
.cfg-row input[type=number] {
  width: 68px; background: var(--bg); color: #ccc;
  border: none; border-bottom: 1px solid #444;
  border-radius: 0; padding: .15rem .3rem;
  font-size: .8rem; text-align: right;
  outline: none; transition: border-color .15s;
}
.cfg-row input[type=number]:hover  { border-color: #666; }
.cfg-row input[type=number]:focus  { border-color: var(--accent); color: #eee; }
.cfg-row input[type=number]::-webkit-inner-spin-button,
.cfg-row input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.cfg-row input[type=number] { -moz-appearance: textfield; }
.cfg-row input[type=color] {
  width: 36px; height: 24px; padding: 0; border: 1px solid var(--border);
  border-radius: 4px; background: none; cursor: pointer;
}
.cfg-radio { display: flex; align-items: center; gap: .25rem; font-size: .8rem; color: #aaa; cursor: pointer; }
.cfg-radio input[type=radio] { accent-color: var(--accent); cursor: pointer; }
.cfg-sep { border: none; border-top: 1px solid var(--border); margin: .2rem 0; }
.cfg-details { border: none; }
.cfg-details > summary {
  list-style: none;
  display: flex; align-items: center; justify-content: space-between;
  font-size: .7rem; color: var(--text); text-transform: uppercase; letter-spacing: .08em;
  cursor: pointer; user-select: none; padding: .15rem 0;
}
.cfg-details > summary::-webkit-details-marker { display: none; }
.cfg-details > summary::after { content: '▾'; font-size: .8rem; color: var(--text); }
.cfg-details[open] > summary::after { content: '▴'; }
.cfg-section-body { display: flex; flex-direction: column; gap: .5rem; margin-top: .4rem; overflow: hidden; transition: height .22s ease; }
.mode-btn {
  background: var(--bg-surface); color: #bbb; border: 1px solid var(--border);
  border-radius: 4px; padding: .2rem .5rem; cursor: pointer; font-size: .75rem;
}
.mode-btn:hover { background: var(--bg-hover); }
.mode-btn.active { border-color: var(--accent); color: var(--accent); }

/* Search panel */
#search-panel {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 6px; padding: .7rem .9rem;
  display: flex; flex-direction: column; gap: .5rem;
}
#search-panel[hidden] { display: none; }
.search-row  { display: flex; align-items: center; justify-content: space-between; }
.search-title { font-size: .7rem; color: var(--text); text-transform: uppercase; letter-spacing: .08em; }
#search-seq {
  font-family: var(--font-mono); font-size: .7rem; line-height: 1.5;
  background: var(--bg); color: #8bc; border: 1px solid #223; border-radius: 4px;
  padding: .4rem .5rem; resize: vertical; min-height: 4.5rem; outline: none; width: 100%; box-sizing: border-box;
}
#search-seq:focus { border-color: #46a; }
#search-games { display: flex; flex-direction: column; gap: .2rem; max-height: 8rem; overflow-y: auto; }
.search-game-item {
  display: flex; align-items: center; gap: .4rem;
  font-size: .75rem; color: #aaa; cursor: pointer; min-width: 0;
}
.search-game-item input[type=checkbox] { accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.search-game-all { border-bottom: 1px solid var(--border); padding-bottom: .2rem; margin-bottom: .1rem; color: #777; }
.search-game-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#search-results { display: flex; flex-direction: column; gap: .2rem; }
.search-result {
  font-size: .75rem; color: #bbb; padding: .25rem .5rem;
  border-radius: 3px; cursor: pointer; border-left: 2px solid #333;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.search-result:hover { background: #222; border-left-color: var(--accent); color: #eee; }
.search-none  { font-size: .75rem; color: #555; font-style: italic; }

/* Validator */
#validator-panel {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 6px; padding: .7rem .9rem;
  display: flex; flex-direction: column; gap: .35rem;
}
#validator-panel[hidden] { display: none; }
.v-ok         { font-size: .8rem; color: #5a9a7a; }
.v-violation  { font-size: .75rem; color: #c66; padding: .1rem 0; border-bottom: 1px solid var(--border); }
.v-violation:last-child { border-bottom: none; }

/* Save dialog */
.save-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.save-dialog {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 1.2rem 1.4rem; display: flex; flex-direction: column; gap: .8rem;
  min-width: 280px;
}
.save-dialog label { font-size: .8rem; color: #888; }
.save-input {
  background: var(--bg); color: #eee; border: 1px solid #444; border-radius: 4px;
  padding: .35rem .55rem; font-size: .9rem; outline: none; width: 100%;
}
.save-input:focus { border-color: var(--accent); }
.save-actions { display: flex; justify-content: flex-end; gap: .6rem; }
.save-cancel {
  background: none; color: #666; border: 1px solid var(--border); border-radius: 4px;
  padding: .3rem .8rem; cursor: pointer; font-size: .8rem;
}
.save-cancel:hover { color: #aaa; border-color: #555; }
.save-ok {
  background: var(--accent); color: #111; border: none; border-radius: 4px;
  padding: .3rem .9rem; cursor: pointer; font-size: .8rem; font-weight: 600;
}
.save-ok:hover { background: #daa030; }

/* ---- Bottom sheets (portrait mobile) ---- */
#sheet-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 45;
}
#sheet-overlay.visible { display: block; }

#mobile-bar { display: none; }

@media (max-width: 640px) {
  .main {
    grid-template-columns: 1fr;
    padding: .5rem .5rem 4.5rem;
    gap: .5rem;
  }

  #board-wrap { grid-column: 1; width: 100%; }
  #board {
    width: min(96vw, calc(100dvh - 9rem));
    height: min(96vw, calc(100dvh - 9rem));
  }

  /* Left col → tiroir bas */
  #left-col {
    grid-column: 1;
    position: fixed;
    left: 0; right: 0; bottom: 3.5rem;
    max-height: 75dvh;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    padding: .6rem 1rem 1.2rem;
    z-index: 50;
    overflow-y: auto;
    transform: translateY(calc(100% + 3.5rem));
    transition: transform .3s ease;
  }
  #left-col.sheet-open { transform: translateY(0); }
  #left-col::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: #333;
    border-radius: 2px;
    margin: 0 auto .8rem;
  }

  /* Right col → tiroir bas */
  #right-col {
    grid-column: 1;
    position: fixed;
    left: 0; right: 0; bottom: 3.5rem;
    max-height: 75dvh;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    padding: .6rem 1rem 1.2rem;
    z-index: 50;
    overflow-y: auto;
    transform: translateY(calc(100% + 3.5rem));
    transition: transform .3s ease;
  }
  #right-col.sheet-open { transform: translateY(0); }
  #right-col::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: #333;
    border-radius: 2px;
    margin: 0 auto .8rem;
  }

  /* ASCII caché en portrait */
  #ascii { display: none !important; }

  /* SGF preview moins haute sur mobile */
  #sgf-preview { height: min(55vw, 220px); }

  /* Barre mobile */
  #mobile-bar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 3.5rem;
    background: var(--bg);
    border-top: 1px solid var(--border);
    z-index: 60;
    align-items: stretch;
  }
  .mob-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .1rem;
    background: none;
    border: none;
    border-right: 1px solid #1e1e1e;
    color: #555;
    cursor: pointer;
    padding: .3rem 0;
    transition: color .15s;
  }
  .mob-btn:last-child { border-right: none; }
  .mob-btn.active { color: var(--accent); }
  .mob-btn:active { color: #bbb; }
  .mob-icon { font-size: 1.2rem; line-height: 1; }
  .mob-label { font-size: .58rem; }

  #nav, #nav-var { gap: .6rem; }
  #nav button, #nav-var button {
    padding: .7rem 1.2rem;
    font-size: 1.4rem;
    border-radius: 6px;
  }
  #move-num, #var-num { font-size: 1.1rem; width: 6ch; }
}

